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];
$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) {
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
{
return Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && class_exists($model->getType()->getClassName());

View File

@ -1,58 +1,58 @@
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Symfony\Component\PropertyInfo\Type;
class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{
use ModelRegistryAwareTrait;
/** @var PropertyDescriberInterface[] */
private $propertyDescribers;
public function __construct($propertyDescribers = [])
{
$this->propertyDescribers = $propertyDescribers;
}
public function describe(Type $type, Schema $property, array $groups)
{
$type = $type->getCollectionValueType();
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));
}
$property->setType('array');
$property = $property->getItems();
foreach ($this->propertyDescribers as $propertyDescriber) {
if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
$propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($propertyDescriber->supports($type)) {
$propertyDescriber->describe($type, $property);
break;
}
}
}
public function supports(Type $type): bool
{
return $type->isCollection();
}
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\PropertyDescriber;
use EXSyst\Component\Swagger\Schema;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareInterface;
use Nelmio\ApiDocBundle\Describer\ModelRegistryAwareTrait;
use Symfony\Component\PropertyInfo\Type;
class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistryAwareInterface
{
use ModelRegistryAwareTrait;
/** @var PropertyDescriberInterface[] */
private $propertyDescribers;
public function __construct($propertyDescribers = [])
{
$this->propertyDescribers = $propertyDescribers;
}
public function describe(Type $type, Schema $property, array $groups)
{
$type = $type->getCollectionValueType();
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));
}
$property->setType('array');
$property = $property->getItems();
foreach ($this->propertyDescribers as $propertyDescriber) {
if ($propertyDescriber instanceof ModelRegistryAwareInterface) {
$propertyDescriber->setModelRegistry($this->modelRegistry);
}
if ($propertyDescriber->supports($type)) {
$propertyDescriber->describe($type, $property);
break;
}
}
}
public function supports(Type $type): bool
{
return $type->isCollection();
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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