Fix codestyle

This commit is contained in:
Filip Benčo 2019-12-13 22:45:32 +01:00
parent 2de03859c0
commit 5d8765db04
9 changed files with 260 additions and 262 deletions

View File

@ -93,11 +93,11 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
} }
$type = $types[0]; $type = $types[0];
$this->describeProperty($type, $model, $property); $this->describeProperty($type, $model, $property, $propertyName);
} }
} }
private function describeProperty(Type $type, Model $model, Schema $property) private function describeProperty(Type $type, Model $model, Schema $property, string $propertyName)
{ {
foreach ($this->propertyDescribers as $propertyDescriber) { foreach ($this->propertyDescribers as $propertyDescriber) {
if ($propertyDescriber instanceof ModelRegistryAwareInterface) { if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
@ -110,11 +110,9 @@ class ObjectModelDescriber implements ModelDescriberInterface, ModelRegistryAwar
} }
} }
throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `@SWG\Property(type="")` annotation to specify it manually.', $type->getBuiltinType(), $class, $propertyName)); throw new \Exception(sprintf('Type "%s" is not supported in %s::$%s. You may use the `@SWG\Property(type="")` annotation to specify it manually.', $type->getBuiltinType(), $model->getType()->getClassName(), $propertyName));
} }
public function supports(Model $model): bool public function supports(Model $model): bool
{ {
return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && class_exists($model->getType()->getClassName()); return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && class_exists($model->getType()->getClassName());

View File

@ -1,58 +1,58 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{ {
use ModelRegistryAwareTrait; use ModelRegistryAwareTrait;
/** @var PropertyDescriberInterface[] */ /** @var PropertyDescriberInterface[] */
private $propertyDescribers; private $propertyDescribers;
public function __construct($propertyDescribers = []) public function __construct($propertyDescribers = [])
{ {
$this->propertyDescribers = $propertyDescribers; $this->propertyDescribers = $propertyDescribers;
} }
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$type = $type->getCollectionValueType(); $type = $type->getCollectionValueType();
if (null === $type) { if (null === $type) {
throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName)); throw new \LogicException(sprintf('Property "%s:%s" is an array, but its items type isn\'t specified. You can specify that by using the type `string[]` for instance or `@SWG\Property(type="array", @SWG\Items(type="string"))`.', $class, $propertyName));
} }
$property->setType('array'); $property->setType('array');
$property = $property->getItems(); $property = $property->getItems();
foreach ($this->propertyDescribers as $propertyDescriber) { foreach ($this->propertyDescribers as $propertyDescriber) {
if ($propertyDescriber instanceof ModelRegistryAwareInterface) { if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
$propertyDescriber->setModelRegistry($this->modelRegistry); $propertyDescriber->setModelRegistry($this->modelRegistry);
} }
if ($propertyDescriber->supports($type)) { if ($propertyDescriber->supports($type)) {
$propertyDescriber->describe($type, $property); $propertyDescriber->describe($type, $property);
break; break;
} }
} }
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return $type->isCollection(); return $type->isCollection();
} }
} }

View File

@ -1,29 +1,29 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class BooleanPropertyDescriber implements PropertyDescriberInterface class BooleanPropertyDescriber implements PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$property->setType('boolean'); $property->setType('boolean');
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType(); return Type::BUILTIN_TYPE_BOOL === $type->getBuiltinType();
} }
} }

View File

@ -1,31 +1,31 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class DateTimePropertyDescriber implements PropertyDescriberInterface class DateTimePropertyDescriber implements PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$property->setType('string'); $property->setType('string');
$property->setFormat('date-time'); $property->setFormat('date-time');
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType() return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
&& is_a($type->getClassName(), \DateTimeInterface::class, true); && is_a($type->getClassName(), \DateTimeInterface::class, true);
} }
} }

View File

@ -1,30 +1,30 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class FloatPropertyDescriber implements PropertyDescriberInterface class FloatPropertyDescriber implements PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$property->setType('number'); $property->setType('number');
$property->setFormat('float'); $property->setFormat('float');
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType(); return Type::BUILTIN_TYPE_FLOAT === $type->getBuiltinType();
} }
} }

View File

@ -1,29 +1,29 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class IntegerPropertyDescriber implements PropertyDescriberInterface class IntegerPropertyDescriber implements PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$property->setType('integer'); $property->setType('integer');
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_INT === $type->getBuiltinType(); return Type::BUILTIN_TYPE_INT === $type->getBuiltinType();
} }
} }

View File

@ -1,37 +1,37 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait; use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Nelmio\ApiDocBundle\Model\Model; use Nelmio\ApiDocBundle\Model\Model;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{ {
use ModelRegistryAwareTrait; use ModelRegistryAwareTrait;
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$type = new Type($type->getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field $type = new Type($type->getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field
$property->setRef( $property->setRef(
$this->modelRegistry->register(new Model($type, $groups)) $this->modelRegistry->register(new Model($type, $groups))
); );
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType(); return Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType();
} }
} }

View File

@ -1,22 +1,22 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
interface PropertyDescriberInterface interface PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups); public function describe(Type $type, Schema $property, array $groups);
public function supports(Type $type): bool; public function supports(Type $type): bool;
} }

View File

@ -1,29 +1,29 @@
<?php <?php
/* /*
* This file is part of the NelmioApiDocBundle package. * This file is part of the NelmioApiDocBundle package.
* *
* (c) Nelmio * (c) Nelmio
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Nelmio\ApiDocBundle\PropertyDescriber; namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema; use EXSyst\Component\Swagger\Schema;
use Symfony\Component\PropertyInfo\Type; use Symfony\Component\PropertyInfo\Type;
class StringPropertyDescriber implements PropertyDescriberInterface class StringPropertyDescriber implements PropertyDescriberInterface
{ {
public function describe(Type $type, Schema $property, array $groups) public function describe(Type $type, Schema $property, array $groups)
{ {
$property->setType('string'); $property->setType('string');
} }
public function supports(Type $type): bool public function supports(Type $type): bool
{ {
return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType(); return Type::BUILTIN_TYPE_STRING === $type->getBuiltinType();
} }
} }