From d7fd92937907b7664567e57f6a3d9a20ed7ae4ec Mon Sep 17 00:00:00 2001 From: William DURAND Date: Thu, 14 Nov 2013 10:28:42 +0100 Subject: [PATCH] Fix CS --- Annotation/ApiDoc.php | 1 + .../ExtractorHandlerCompilerPass.php | 11 ++-- Extractor/ApiDocExtractor.php | 55 ++++++++++--------- Extractor/Handler/FosRestHandler.php | 2 +- Formatter/MarkdownFormatter.php | 2 +- Parser/JmsMetadataParser.php | 2 +- Parser/ParserInterface.php | 2 +- Parser/ValidationParser.php | 38 ++++++------- .../Extractor/Handler/FosRestHandlerTest.php | 2 +- Tests/Fixtures/Controller/TestController.php | 4 +- Tests/Parser/FormTypeParserTest.php | 1 - Tests/Parser/ValidationParserTest.php | 4 +- Tests/WebTestCase.php | 1 - 13 files changed, 60 insertions(+), 65 deletions(-) diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index ab2a8f0..b2f527c 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -482,6 +482,7 @@ class ApiDoc public function setDeprecated($deprecated) { $this->deprecated = (bool) $deprecated; + return $this; } diff --git a/DependencyInjection/ExtractorHandlerCompilerPass.php b/DependencyInjection/ExtractorHandlerCompilerPass.php index 6e7a697..50c7143 100644 --- a/DependencyInjection/ExtractorHandlerCompilerPass.php +++ b/DependencyInjection/ExtractorHandlerCompilerPass.php @@ -15,7 +15,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Reference; - class ExtractorHandlerCompilerPass implements CompilerPassInterface { /** @@ -25,13 +24,11 @@ class ExtractorHandlerCompilerPass implements CompilerPassInterface { $handlers = array(); foreach ($container->findTaggedServiceIds('nelmio_api_doc.extractor.handler') as $id => $attributes) { - - // Adding handlers from tagged services $handlers[] = new Reference($id); } - $definition = $container->getDefinition( - 'nelmio_api_doc.extractor.api_doc_extractor' - ); - $definition->replaceArgument(4, $handlers); + + $container + ->getDefinition('nelmio_api_doc.extractor.api_doc_extractor') + ->replaceArgument(4, $handlers); } } diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 83bc59e..b50535f 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -23,7 +23,7 @@ use Nelmio\ApiDocBundle\Util\DocCommentExtractor; class ApiDocExtractor { - const ANNOTATION_CLASS = 'Nelmio\\ApiDocBundle\\Annotation\\ApiDoc'; + const ANNOTATION_CLASS = 'Nelmio\\ApiDocBundle\\Annotation\\ApiDoc'; /** * @var ContainerInterface @@ -46,22 +46,22 @@ class ApiDocExtractor private $commentExtractor; /** - * @var array ParserInterface + * @var ParserInterface[] */ protected $parsers = array(); /** - * @var array HandlerInterface + * @var HandlerInterface[] */ protected $handlers; public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, array $handlers) { - $this->container = $container; - $this->router = $router; - $this->reader = $reader; + $this->container = $container; + $this->router = $router; + $this->reader = $reader; $this->commentExtractor = $commentExtractor; - $this->handlers = $handlers; + $this->handlers = $handlers; } /** @@ -141,7 +141,7 @@ class ApiDocExtractor } $methodOrder = array('GET', 'POST', 'PUT', 'DELETE'); - usort($array, function($a, $b) use ($methodOrder) { + usort($array, function ($a, $b) use ($methodOrder) { if ($a['resource'] === $b['resource']) { if ($a['annotation']->getRoute()->getPattern() === $b['annotation']->getRoute()->getPattern()) { $methodA = array_search($a['annotation']->getRoute()->getRequirement('_method'), $methodOrder); @@ -282,8 +282,8 @@ class ApiDocExtractor } } - foreach($supportedParsers as $parser) { - if($parser instanceof PostParserInterface) { + foreach ($supportedParsers as $parser) { + if ($parser instanceof PostParserInterface) { $mp = $parser->postParse($normalizedInput, $parameters); $parameters = $this->mergeParameters($parameters, $mp); } @@ -293,7 +293,7 @@ class ApiDocExtractor if ('PUT' === $method) { // All parameters are optional with PUT (update) - array_walk($parameters, function($val, $key) use (&$data) { + array_walk($parameters, function ($val, $key) use (&$data) { $parameters[$key]['required'] = false; }); } @@ -401,32 +401,32 @@ class ApiDocExtractor * - Other string values are overridden by later parsers when present. * - Array parameters are recursively merged. * - * @param array $p1 The pre-existing parameters array. - * @param array $p2 The newly-returned parameters array. - * @return array The resulting, merged array. + * @param array $p1 The pre-existing parameters array. + * @param array $p2 The newly-returned parameters array. + * @return array The resulting, merged array. */ protected function mergeParameters($p1, $p2) { $params = $p1; - foreach($p2 as $propname => $propvalue) { - if(!isset($p1[$propname])) { + foreach ($p2 as $propname => $propvalue) { + if (!isset($p1[$propname])) { $params[$propname] = $propvalue; } else { $v1 = $p1[$propname]; - foreach($propvalue as $name => $value) { - if(is_array($value)) { - if(isset($v1[$name]) && is_array($v1[$name])) { + foreach ($propvalue as $name => $value) { + if (is_array($value)) { + if (isset($v1[$name]) && is_array($v1[$name])) { $v1[$name] = $this->mergeParameters($v1[$name], $value); } else { $v1[$name] = $value; } - } elseif(!is_null($value)) { - if(in_array($name, array('required', 'readonly'))) { + } elseif (!is_null($value)) { + if (in_array($name, array('required', 'readonly'))) { $v1[$name] = $v1[$name] || $value; - } elseif(in_array($name, array('requirement'))) { - if(isset($v1[$name])) { + } elseif (in_array($name, array('requirement'))) { + if (isset($v1[$name])) { $v1[$name] .= ', ' . $value; } else { $v1[$name] = $value; @@ -463,17 +463,18 @@ class ApiDocExtractor /** * Clears the temporary 'class' parameter from the parameters array before it is returned. * - * @param array $array The source array. - * @return array The cleared array. + * @param array $array The source array. + * @return array The cleared array. */ protected function clearClasses($array) { - if(is_array($array)) { + if (is_array($array)) { unset($array['class']); - foreach($array as $name => $item) { + foreach ($array as $name => $item) { $array[$name] = $this->clearClasses($item); } } + return $array; } } diff --git a/Extractor/Handler/FosRestHandler.php b/Extractor/Handler/FosRestHandler.php index f88316d..2a02fd0 100644 --- a/Extractor/Handler/FosRestHandler.php +++ b/Extractor/Handler/FosRestHandler.php @@ -36,7 +36,7 @@ class FosRestHandler implements HandlerInterface 'dataType' => '', 'description' => $annot->description, )); - } elseif($annot->default !== null) { + } elseif ($annot->default !== null) { $annotation->addFilter($annot->name, array( 'requirement' => $annot->requirements, 'description' => $annot->description, diff --git a/Formatter/MarkdownFormatter.php b/Formatter/MarkdownFormatter.php index 4bfe286..1700656 100644 --- a/Formatter/MarkdownFormatter.php +++ b/Formatter/MarkdownFormatter.php @@ -20,7 +20,7 @@ class MarkdownFormatter extends AbstractFormatter { $markdown = sprintf("### `%s` %s ###\n", $data['method'], $data['uri']); - if(isset($data['deprecated']) && false !== $data['deprecated']) { + if (isset($data['deprecated']) && false !== $data['deprecated']) { $markdown .= "### This method is deprecated ###"; $markdown .= "\n\n"; } diff --git a/Parser/JmsMetadataParser.php b/Parser/JmsMetadataParser.php index 1b3d149..df37980 100644 --- a/Parser/JmsMetadataParser.php +++ b/Parser/JmsMetadataParser.php @@ -126,7 +126,7 @@ class JmsMetadataParser implements ParserInterface 'untilVersion' => $item->untilVersion, ); - if(!is_null($dataType['class'])) { + if (!is_null($dataType['class'])) { $params[$name]['class'] = $dataType['class']; } diff --git a/Parser/ParserInterface.php b/Parser/ParserInterface.php index 3710bcf..3345550 100644 --- a/Parser/ParserInterface.php +++ b/Parser/ParserInterface.php @@ -19,7 +19,7 @@ interface ParserInterface /** * Return true/false whether this class supports parsing the given class. * - * @param array $item containing the following fields: class, groups. Of which groups is optional + * @param array $item containing the following fields: class, groups. Of which groups is optional * @return boolean */ public function supports(array $item); diff --git a/Parser/ValidationParser.php b/Parser/ValidationParser.php index c47f79f..1f26db4 100644 --- a/Parser/ValidationParser.php +++ b/Parser/ValidationParser.php @@ -56,23 +56,23 @@ class ValidationParser implements ParserInterface, PostParserInterface $classdata = $this->factory->getMetadataFor($className); $properties = $classdata->getConstrainedProperties(); - foreach($properties as $property) { + foreach ($properties as $property) { $vparams = array(); $pds = $classdata->getPropertyMetadata($property); - foreach($pds as $propdata) { + foreach ($pds as $propdata) { $constraints = $propdata->getConstraints(); - foreach($constraints as $constraint) { + foreach ($constraints as $constraint) { $vparams = $this->parseConstraint($constraint, $vparams, $className); } } - if(isset($vparams['format'])) { + if (isset($vparams['format'])) { $vparams['format'] = join(', ', $vparams['format']); } - foreach(array('dataType', 'readonly', 'required') as $reqprop) { - if(!isset($vparams[$reqprop])) { + foreach (array('dataType', 'readonly', 'required') as $reqprop) { + if (!isset($vparams[$reqprop])) { $vparams[$reqprop] = null; } } @@ -88,8 +88,8 @@ class ValidationParser implements ParserInterface, PostParserInterface */ public function postParse(array $input, array $parameters) { - foreach($parameters as $param => $data) { - if(isset($data['class']) && isset($data['children'])) { + foreach ($parameters as $param => $data) { + if (isset($data['class']) && isset($data['children'])) { $input = array('class' => $data['class']); $parameters[$param]['children'] = array_merge( $parameters[$param]['children'], $this->postParse($input, $parameters[$param]['children']) @@ -115,15 +115,15 @@ class ValidationParser implements ParserInterface, PostParserInterface * - Choice (single and multiple, min and max) * - Regex (match and non-match) * - * @param Constraint $constraint The constraint metadata object. - * @param array $vparams The existing validation parameters. - * @return mixed The parsed list of validation parameters. + * @param Constraint $constraint The constraint metadata object. + * @param array $vparams The existing validation parameters. + * @return mixed The parsed list of validation parameters. */ protected function parseConstraint(Constraint $constraint, $vparams, $className) { $class = substr(get_class($constraint), strlen('Symfony\\Component\\Validator\\Constraints\\')); - switch($class) { + switch ($class) { case 'NotBlank': case 'NotNull': $vparams['required'] = true; @@ -142,10 +142,10 @@ class ValidationParser implements ParserInterface, PostParserInterface break; case 'Length': $messages = array(); - if(isset($constraint->min)) { + if (isset($constraint->min)) { $messages[] = "min: {$constraint->min}"; } - if(isset($constraint->max)) { + if (isset($constraint->max)) { $messages[] = "max: {$constraint->max}"; } $vparams['format'][] = '{length: ' . join(', ', $messages) . '}'; @@ -153,12 +153,12 @@ class ValidationParser implements ParserInterface, PostParserInterface case 'Choice': $choices = $this->getChoices($constraint, $className); $format = '[' . join('|', $choices) . ']'; - if($constraint->multiple) { + if ($constraint->multiple) { $messages = array(); - if(isset($constraint->min)) { + if (isset($constraint->min)) { $messages[] = "min: {$constraint->min} "; } - if(isset($constraint->max)) { + if (isset($constraint->max)) { $messages[] = "max: {$constraint->max} "; } $vparams['format'][] = '{' . join ('', $messages) . 'choice of ' . $format . '}'; @@ -167,7 +167,7 @@ class ValidationParser implements ParserInterface, PostParserInterface } break; case 'Regex': - if($constraint->match) { + if ($constraint->match) { $vparams['format'][] = '{match: ' . $constraint->pattern . '}'; } else { $vparams['format'][] = '{not match: ' . $constraint->pattern . '}'; @@ -186,7 +186,7 @@ class ValidationParser implements ParserInterface, PostParserInterface * @return array * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ - protected function getChoices (Constraint $constraint, $className) + protected function getChoices(Constraint $constraint, $className) { if ($constraint->callback) { if (is_callable(array($className, $constraint->callback))) { diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 28cb2b6..145daca 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -87,4 +87,4 @@ class FosRestHandlerTest extends WebTestCase $this->assertArrayNotHasKey('default', $filter); } -} \ No newline at end of file +} diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index a235b1d..3b109b0 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -80,10 +80,10 @@ class TestController * * @ApiDoc() * - * @param int $id A nice comment + * @param int $id A nice comment * @param int $page * @param int $paramType The param type - * @param int $param The param id + * @param int $param The param id */ public function myCommentedAction() { diff --git a/Tests/Parser/FormTypeParserTest.php b/Tests/Parser/FormTypeParserTest.php index b2ee201..47e4be1 100644 --- a/Tests/Parser/FormTypeParserTest.php +++ b/Tests/Parser/FormTypeParserTest.php @@ -7,7 +7,6 @@ use Nelmio\ApiDocBundle\Tests\Fixtures; use Symfony\Component\Form\Extension\Core\CoreExtension; use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\FormFactoryBuilder; -use Symfony\Component\Form\FormRegistry; use Symfony\Component\Form\ResolvedFormTypeFactory; class FormTypeParserTest extends \PHPUnit_Framework_TestCase diff --git a/Tests/Parser/ValidationParserTest.php b/Tests/Parser/ValidationParserTest.php index 4e5c256..7e4d910 100644 --- a/Tests/Parser/ValidationParserTest.php +++ b/Tests/Parser/ValidationParserTest.php @@ -4,7 +4,6 @@ namespace NelmioApiDocBundle\Tests\Parser; use Nelmio\ApiDocBundle\Tests\WebTestCase; use Nelmio\ApiDocBundle\Parser\ValidationParser; - class ValidationParserTest extends WebTestCase { protected $handler; @@ -24,12 +23,11 @@ class ValidationParserTest extends WebTestCase { $result = $this->parser->parse(array('class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\ValidatorTest')); - foreach($expected as $name => $value) { + foreach ($expected as $name => $value) { $this->assertEquals($value, $expected[$name]); } } - public function dataTestParser() { return array( diff --git a/Tests/WebTestCase.php b/Tests/WebTestCase.php index 1d8d161..3586b8e 100644 --- a/Tests/WebTestCase.php +++ b/Tests/WebTestCase.php @@ -14,7 +14,6 @@ namespace Nelmio\ApiDocBundle\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Kernel; -use Symfony\Component\DependencyInjection\Scope; abstract class WebTestCase extends BaseWebTestCase {