Merge pull request #1159 from nelmio/analysis-zG01nA

Apply fixes from StyleCI
This commit is contained in:
David Buchmann 2017-12-22 18:44:38 +01:00 committed by GitHub
commit ccf7a75ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 41 additions and 8 deletions

View File

@ -23,7 +23,9 @@ final class Model extends AbstractAnnotation
'type' => 'string', 'type' => 'string',
'groups' => '[string]', 'groups' => '[string]',
]; ];
public static $_required = ['type']; public static $_required = ['type'];
public static $_parents = [ public static $_parents = [
'Swagger\Annotations\Parameter', 'Swagger\Annotations\Parameter',
'Swagger\Annotations\Response', 'Swagger\Annotations\Response',

View File

@ -21,8 +21,11 @@ use Psr\Cache\CacheItemPoolInterface;
final class ApiDocGenerator final class ApiDocGenerator
{ {
private $swagger; private $swagger;
private $describers; private $describers;
private $modelDescribers; private $modelDescribers;
private $cacheItemPool; private $cacheItemPool;
/** /**

View File

@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\Response;
final class SwaggerUiController final class SwaggerUiController
{ {
private $apiDocGenerator; private $apiDocGenerator;
private $twig; private $twig;
public function __construct(ApiDocGenerator $apiDocGenerator, \Twig_Environment $twig) public function __construct(ApiDocGenerator $apiDocGenerator, \Twig_Environment $twig)

View File

@ -40,7 +40,7 @@ trait PriorityTaggedServiceTrait
*/ */
private function findAndSortTaggedServices($tagName, ContainerBuilder $container) private function findAndSortTaggedServices($tagName, ContainerBuilder $container)
{ {
$services = array(); $services = [];
foreach ($container->findTaggedServiceIds($tagName) as $serviceId => $tags) { foreach ($container->findTaggedServiceIds($tagName) as $serviceId => $tags) {
foreach ($tags as $attributes) { foreach ($tags as $attributes) {
$priority = isset($attributes['priority']) ? $attributes['priority'] : 0; $priority = isset($attributes['priority']) ? $attributes['priority'] : 0;

View File

@ -23,6 +23,7 @@ final class ApiPlatformDescriber extends ExternalDocDescriber
parent::__construct(function () use ($documentation, $normalizer, $urlGenerator) { parent::__construct(function () use ($documentation, $normalizer, $urlGenerator) {
$baseContext = $urlGenerator->getContext(); $baseContext = $urlGenerator->getContext();
$urlGenerator->setContext(new RequestContext()); $urlGenerator->setContext(new RequestContext());
try { try {
$basePath = $urlGenerator->generate('api_entrypoint'); $basePath = $urlGenerator->generate('api_entrypoint');
} finally { } finally {

View File

@ -16,6 +16,7 @@ use EXSyst\Component\Swagger\Swagger;
class ExternalDocDescriber implements DescriberInterface class ExternalDocDescriber implements DescriberInterface
{ {
private $externalDoc; private $externalDoc;
private $overwrite; private $overwrite;
/** /**

View File

@ -22,7 +22,9 @@ final class RouteDescriber implements DescriberInterface, ModelRegistryAwareInte
use ModelRegistryAwareTrait; use ModelRegistryAwareTrait;
private $routeCollection; private $routeCollection;
private $controllerReflector; private $controllerReflector;
private $routeDescribers; private $routeDescribers;
/** /**

View File

@ -28,7 +28,9 @@ final class SwaggerPhpDescriber extends ExternalDocDescriber implements ModelReg
use ModelRegistryAwareTrait; use ModelRegistryAwareTrait;
private $routeCollection; private $routeCollection;
private $controllerReflector; private $controllerReflector;
private $annotationReader; private $annotationReader;
public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, Reader $annotationReader, bool $overwrite = false) public function __construct(RouteCollection $routeCollection, ControllerReflector $controllerReflector, Reader $annotationReader, bool $overwrite = false)

View File

@ -16,6 +16,7 @@ use Symfony\Component\PropertyInfo\Type;
final class Model final class Model
{ {
private $type; private $type;
private $groups; private $groups;
/** /**

View File

@ -20,9 +20,13 @@ use Symfony\Component\PropertyInfo\Type;
final class ModelRegistry final class ModelRegistry
{ {
private $unregistered = []; private $unregistered = [];
private $models = []; private $models = [];
private $names = []; private $names = [];
private $modelDescribers = []; private $modelDescribers = [];
private $api; private $api;
/** /**

View File

@ -70,28 +70,33 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
if ('text' === $blockPrefix) { if ('text' === $blockPrefix) {
$property->setType('string'); $property->setType('string');
break; break;
} }
if ('number' === $blockPrefix) { if ('number' === $blockPrefix) {
$property->setType('number'); $property->setType('number');
break; break;
} }
if ('integer' === $blockPrefix) { if ('integer' === $blockPrefix) {
$property->setType('integer'); $property->setType('integer');
break; break;
} }
if ('date' === $blockPrefix) { if ('date' === $blockPrefix) {
$property->setType('string'); $property->setType('string');
$property->setFormat('date'); $property->setFormat('date');
break; break;
} }
if ('datetime' === $blockPrefix) { if ('datetime' === $blockPrefix) {
$property->setType('string'); $property->setType('string');
$property->setFormat('date-time'); $property->setFormat('date-time');
break; break;
} }
@ -115,6 +120,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
$model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $subType), null); $model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $subType), null);
$property->getItems()->setRef($this->modelRegistry->register($model)); $property->getItems()->setRef($this->modelRegistry->register($model));
$property->setExample(sprintf('[{%s}]', $subType)); $property->setExample(sprintf('[{%s}]', $subType));
break; break;
} }
@ -129,6 +135,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
$property->setType('string'); $property->setType('string');
$property->setFormat(sprintf('%s id', $entityClass)); $property->setFormat(sprintf('%s id', $entityClass));
} }
break; break;
} }
@ -136,6 +143,7 @@ final class FormModelDescriber implements ModelDescriberInterface, ModelRegistry
//if form type is not builtin in Form component. //if form type is not builtin in Form component.
$model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $formClass)); $model = new Model(new Type(Type::BUILTIN_TYPE_OBJECT, false, $formClass));
$property->setRef($this->modelRegistry->register($model)); $property->setRef($this->modelRegistry->register($model));
break; break;
} }
} }

View File

@ -119,6 +119,7 @@ class JMSModelDescriber implements ModelDescriberInterface, ModelRegistryAwareIn
public function supports(Model $model): bool public function supports(Model $model): bool
{ {
$className = $model->getType()->getClassName(); $className = $model->getType()->getClassName();
try { try {
if ($this->factory->getMetadataForClass($className)) { if ($this->factory->getMetadataForClass($className)) {
return true; return true;

View File

@ -11,8 +11,8 @@
namespace Nelmio\ApiDocBundle\ModelDescriber; namespace Nelmio\ApiDocBundle\ModelDescriber;
use EXSyst\Component\Swagger\Schema;
use EXSyst\Component\Swagger\Items; use EXSyst\Component\Swagger\Items;
use EXSyst\Component\Swagger\Schema;
use phpDocumentor\Reflection\DocBlock\Tags\Var_; use phpDocumentor\Reflection\DocBlock\Tags\Var_;
use phpDocumentor\Reflection\DocBlockFactory; use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\DocBlockFactoryInterface; use phpDocumentor\Reflection\DocBlockFactoryInterface;
@ -56,13 +56,15 @@ class PhpdocPropertyAnnotationReader
continue; continue;
} }
$title = $description->render(); $title = $description->render();
if ($title) break; if ($title) {
break;
}
} }
} }
if ($property->getTitle() === null && $title) { if (null === $property->getTitle() && $title) {
$property->setTitle($title); $property->setTitle($title);
} }
if ($property->getDescription() === null && $docBlock->getDescription() && $docBlock->getDescription()->render()) { if (null === $property->getDescription() && $docBlock->getDescription() && $docBlock->getDescription()->render()) {
$property->setDescription($docBlock->getDescription()->render()); $property->setDescription($docBlock->getDescription()->render());
} }
} }

View File

@ -39,6 +39,7 @@ final class PhpDocDescriber implements RouteDescriberInterface
$classDocBlock = $this->docBlockFactory->create($reflectionMethod->getDeclaringClass()); $classDocBlock = $this->docBlockFactory->create($reflectionMethod->getDeclaringClass());
} catch (\Exception $e) { } catch (\Exception $e) {
} }
try { try {
$docBlock = $this->docBlockFactory->create($reflectionMethod); $docBlock = $this->docBlockFactory->create($reflectionMethod);
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -23,6 +23,7 @@ use Symfony\Component\Routing\RouteCollection;
class RouteDescriberTest extends AbstractDescriberTest class RouteDescriberTest extends AbstractDescriberTest
{ {
private $routes; private $routes;
private $routeDescriber; private $routeDescriber;
public function testIgnoreWhenNoController() public function testIgnoreWhenNoController()

View File

@ -77,7 +77,7 @@ class FunctionalTest extends WebTestCase
{ {
$operation = $this->getOperation('/api/swagger/implicit', $method); $operation = $this->getOperation('/api/swagger/implicit', $method);
$this->assertEquals(array(new Tag('implicit')), $operation->getTags()); $this->assertEquals([new Tag('implicit')], $operation->getTags());
$responses = $operation->getResponses(); $responses = $operation->getResponses();
$this->assertTrue($responses->has('201')); $this->assertTrue($responses->has('201'));

View File

@ -78,7 +78,7 @@ class JMSFunctionalTest extends WebTestCase
], $this->getModel('VirtualProperty')->toArray()); ], $this->getModel('VirtualProperty')->toArray());
} }
protected static function createKernel(array $options = array()) protected static function createKernel(array $options = [])
{ {
return new TestKernel(true); return new TestKernel(true);
} }

View File

@ -17,7 +17,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
class WebTestCase extends BaseWebTestCase class WebTestCase extends BaseWebTestCase
{ {
protected static function createKernel(array $options = array()) protected static function createKernel(array $options = [])
{ {
return new TestKernel(); return new TestKernel();
} }

View File

@ -20,6 +20,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
final class ControllerReflector final class ControllerReflector
{ {
private $container; private $container;
private $controllerNameParser; private $controllerNameParser;
private $controllers = []; private $controllers = [];
@ -45,6 +46,7 @@ final class ControllerReflector
} }
list($class, $method) = $callable; list($class, $method) = $callable;
try { try {
return new \ReflectionMethod($class, $method); return new \ReflectionMethod($class, $method);
} catch (\ReflectionException $e) { } catch (\ReflectionException $e) {
@ -61,6 +63,7 @@ final class ControllerReflector
} }
list($class, $method) = $callable; list($class, $method) = $callable;
try { try {
return [new \ReflectionClass($class), new \ReflectionMethod($class, $method)]; return [new \ReflectionClass($class), new \ReflectionMethod($class, $method)];
} catch (\ReflectionException $e) { } catch (\ReflectionException $e) {