diff --git a/src/php/ContextCache.php b/src/php/ContextCache.php index 8d84c0f05b17cf73c3f5e6a0fceba44fcd935652..377221c5f5c858262aeef41436698607d2f9c9df 100644 --- a/src/php/ContextCache.php +++ b/src/php/ContextCache.php @@ -1,21 +1,31 @@ <?php declare(strict_types=1); -/** - * Copyright (C) 2019 IRSTEA - * All rights reserved. +/* + * This file is part of "irstea/ng-model-generator-bundle". + * + * "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata. + * Copyright (C) 2018-2019 IRSTEA + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * @copyright 2019 IRSTEA - * @author guillaume.perreal + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License and the GNU + * Lesser General Public License along with this program. If not, see + * <https://www.gnu.org/licenses/>. */ - namespace Irstea\NgModelGeneratorBundle; - use Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata; use Irstea\NgModelGeneratorBundle\Models\Types\Factory\ContextInterface; /** - * Class ContextCache + * Class ContextCache. */ final class ContextCache implements ContextFactoryInterface { @@ -24,23 +34,21 @@ final class ContextCache implements ContextFactoryInterface */ private $contextFactory; - /** @var ContextInterface[] */ private $cache = []; - /** * ContextCache constructor. + * * @param ContextFactoryInterface $contextFactory */ public function __construct(ContextFactoryInterface $contextFactory) { - $this->contextFactory = $contextFactory; } /** - * {@inheritDoc} + * {@inheritdoc} */ public function create(SerializationMetadata $serialization, bool $withAtFields): ContextInterface { @@ -55,7 +63,8 @@ final class ContextCache implements ContextFactoryInterface /** * @param SerializationMetadata $serialization - * @param bool $withAtFields + * @param bool $withAtFields + * * @return string */ private function getCacheKey(SerializationMetadata $serialization, bool $withAtFields): string diff --git a/src/php/ContextFactory.php b/src/php/ContextFactory.php index 30ef01825c3f88bb1fda3c7575245435d6ea8107..a69981fc59339f10b6648777069781239b865cf8 100644 --- a/src/php/ContextFactory.php +++ b/src/php/ContextFactory.php @@ -56,6 +56,7 @@ final class ContextFactory implements ContextFactoryInterface /** * ContextFactory constructor. + * * @param PropertyInfoExtractor $propertyInfoExtractor */ public function __construct(PropertyInfoExtractor $propertyInfoExtractor) @@ -68,7 +69,7 @@ final class ContextFactory implements ContextFactoryInterface } /** - * {@inheritDoc} + * {@inheritdoc} */ public function create(SerializationMetadata $serialization, bool $withAtFields): ContextInterface { @@ -82,10 +83,10 @@ final class ContextFactory implements ContextFactoryInterface DeferrableTypeFactory::decorate( new CompositeTypeFactory([ $serializationMapper, - $this->reflectionTypeFactory + $this->reflectionTypeFactory, ]) ), - $this->builtinScalarsTypeFactory + $this->builtinScalarsTypeFactory, ]) ); diff --git a/src/php/ContextFactoryInterface.php b/src/php/ContextFactoryInterface.php index 6fa9f1959fd747cadc46473a8b588a33733e0560..612b7ff8dde5a3dad6651b83828332e77a6ce524 100644 --- a/src/php/ContextFactoryInterface.php +++ b/src/php/ContextFactoryInterface.php @@ -31,7 +31,7 @@ interface ContextFactoryInterface { /** * @param SerializationMetadata $serialization - * @param bool $withAtFields + * @param bool $withAtFields * * @return ContextInterface */ diff --git a/src/php/Exceptions/EmptyModelException.php b/src/php/Exceptions/EmptyModelException.php index 5d9ba0ffec188c487a2a4a528ce08b941bb223d1..8d10fe4fb12d06f63f3d48edf206958681f64fff 100644 --- a/src/php/Exceptions/EmptyModelException.php +++ b/src/php/Exceptions/EmptyModelException.php @@ -1,20 +1,29 @@ <?php declare(strict_types=1); -/** - * Copyright (C) 2019 IRSTEA - * All rights reserved. +/* + * This file is part of "irstea/ng-model-generator-bundle". + * + * "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata. + * Copyright (C) 2018-2019 IRSTEA + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * @copyright 2019 IRSTEA - * @author guillaume.perreal + * You should have received a copy of the GNU General Public License and the GNU + * Lesser General Public License along with this program. If not, see + * <https://www.gnu.org/licenses/>. */ - namespace Irstea\NgModelGeneratorBundle\Exceptions; - /** - * Class EmptyModelException + * Class EmptyModelException. */ final class EmptyModelException extends InvalidModelException { - } diff --git a/src/php/Exceptions/InvalidModelException.php b/src/php/Exceptions/InvalidModelException.php index c00379a646ddb9798148fe0a33cf3ad008bd7da8..95b7cc0f129d75f917fe367dbd6413691570ae6b 100644 --- a/src/php/Exceptions/InvalidModelException.php +++ b/src/php/Exceptions/InvalidModelException.php @@ -1,20 +1,30 @@ <?php declare(strict_types=1); -/** - * Copyright (C) 2019 IRSTEA - * All rights reserved. +/* + * This file is part of "irstea/ng-model-generator-bundle". + * + * "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata. + * Copyright (C) 2018-2019 IRSTEA + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. * - * @copyright 2019 IRSTEA - * @author guillaume.perreal + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License and the GNU + * Lesser General Public License along with this program. If not, see + * <https://www.gnu.org/licenses/>. */ - namespace Irstea\NgModelGeneratorBundle\Exceptions; - use Throwable; /** - * Class InvalidModelException + * Class InvalidModelException. */ class InvalidModelException extends DomainException { @@ -24,7 +34,7 @@ class InvalidModelException extends DomainException private $className; /** - * {@inheritDoc} + * {@inheritdoc} */ public function __construct(string $className, $message = '', Throwable $previous = null) { diff --git a/src/php/Exceptions/MissingIdentifierException.php b/src/php/Exceptions/MissingIdentifierException.php index be89b733f9927e9e31c26713fcff161639e079fc..4850c4eb2876cf3aaa9a97d046242d25d8a1c334 100644 --- a/src/php/Exceptions/MissingIdentifierException.php +++ b/src/php/Exceptions/MissingIdentifierException.php @@ -1,20 +1,29 @@ <?php declare(strict_types=1); -/** - * Copyright (C) 2019 IRSTEA - * All rights reserved. +/* + * This file is part of "irstea/ng-model-generator-bundle". + * + * "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata. + * Copyright (C) 2018-2019 IRSTEA + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * @copyright 2019 IRSTEA - * @author guillaume.perreal + * You should have received a copy of the GNU General Public License and the GNU + * Lesser General Public License along with this program. If not, see + * <https://www.gnu.org/licenses/>. */ - namespace Irstea\NgModelGeneratorBundle\Exceptions; - /** - * Class MissingIdentifierException + * Class MissingIdentifierException. */ final class MissingIdentifierException extends InvalidModelException { - } diff --git a/src/php/Exceptions/TooManyIdentifiersException.php b/src/php/Exceptions/TooManyIdentifiersException.php index 7932050994f74ebbf01d72ea01823917d9fce820..2f787efa70a0679d5b5899930d386ad825d4fe7b 100644 --- a/src/php/Exceptions/TooManyIdentifiersException.php +++ b/src/php/Exceptions/TooManyIdentifiersException.php @@ -1,20 +1,29 @@ <?php declare(strict_types=1); -/** - * Copyright (C) 2019 IRSTEA - * All rights reserved. +/* + * This file is part of "irstea/ng-model-generator-bundle". + * + * "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata. + * Copyright (C) 2018-2019 IRSTEA + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. * - * @copyright 2019 IRSTEA - * @author guillaume.perreal + * You should have received a copy of the GNU General Public License and the GNU + * Lesser General Public License along with this program. If not, see + * <https://www.gnu.org/licenses/>. */ - namespace Irstea\NgModelGeneratorBundle\Exceptions; - /** - * Class TooManyIdentifiersException + * Class TooManyIdentifiersException. */ final class TooManyIdentifiersException extends InvalidModelException { - } diff --git a/src/php/ModelGenerator.php b/src/php/ModelGenerator.php index 31af395056502df38a44a7319894565ba3bc1813..76a2a05c9f77abb117ab7c6c3aa880cdc3106044 100644 --- a/src/php/ModelGenerator.php +++ b/src/php/ModelGenerator.php @@ -38,9 +38,7 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Factory\TypeHelper; use Irstea\NgModelGeneratorBundle\Models\Types\Objects\Property; use Irstea\NgModelGeneratorBundle\Models\Types\Objects\Repository; use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation; -use Irstea\NgModelGeneratorBundle\Models\Types\Type; use Irstea\NgModelGeneratorBundle\Writers\MultiFileWriter; -use PHPStan\Type\ResourceType; use Twig\Environment; /** @@ -63,10 +61,10 @@ final class ModelGenerator /** * Serializer constructor. * - * @param MetadataFactoryInterface $metadataFactory - * @param ContextFactoryInterface $contextFactory - * @param TypeFactoryInterface $typeFactory - * @param Environment $twigEnv + * @param MetadataFactoryInterface $metadataFactory + * @param ContextFactoryInterface $contextFactory + * @param TypeFactoryInterface $typeFactory + * @param Environment $twigEnv */ public function __construct( MetadataFactoryInterface $metadataFactory, @@ -229,13 +227,14 @@ final class ModelGenerator $properties = $defaultType->getProperties(); if (!$properties) { - throw new EmptyModelException($resourceMeta->getFullName(), "no properties"); + throw new EmptyModelException($resourceMeta->getFullName(), 'no properties'); } $identifiers = \array_filter( $properties, - function(Property $property): bool { - return $property->getName(){0} !== '@' && $property->isIdentifier(); + function (Property $property): bool { + return $property->getName(){0} + !== '@' && $property->isIdentifier(); } ); @@ -267,7 +266,7 @@ final class ModelGenerator } if (!$operations) { - throw new EmptyModelException($resourceMeta->getFullName(), "no operations"); + throw new EmptyModelException($resourceMeta->getFullName(), 'no operations'); } return new Repository($resourceMeta, $defaultType, $identifier, $iri, $operations); diff --git a/src/php/Models/Types/Factory/AbstractTypeFactoryDecorator.php b/src/php/Models/Types/Factory/AbstractTypeFactoryDecorator.php index 98ca281e6bf9955155e42e95bb38deeb9fef3eb7..d39efcfcbc876b6cbdb36ba938f08a05b8317713 100644 --- a/src/php/Models/Types/Factory/AbstractTypeFactoryDecorator.php +++ b/src/php/Models/Types/Factory/AbstractTypeFactoryDecorator.php @@ -62,6 +62,7 @@ abstract class AbstractTypeFactoryDecorator implements TypeFactoryInterface /** * @param TypeFactoryInterface $decorated + * * @return TypeFactoryInterface */ public static function decorate(TypeFactoryInterface $decorated): TypeFactoryInterface diff --git a/src/php/Models/Types/Factory/BuiltinTypeFactory.php b/src/php/Models/Types/Factory/BuiltinTypeFactory.php index 20025a2cb97e8ea3f692ee876307a1a968e1ae5f..aab6da88ff4149c709188d94b993f5bdb81730b6 100644 --- a/src/php/Models/Types/Factory/BuiltinTypeFactory.php +++ b/src/php/Models/Types/Factory/BuiltinTypeFactory.php @@ -65,7 +65,7 @@ class BuiltinTypeFactory implements TypeFactoryInterface */ public function createType(PropertyType $type, ContextInterface $context): Type { - Assertion::true($this->supportsType($type, $context), '%s is not supported by '. static::class); + Assertion::true($this->supportsType($type, $context), '%s is not supported by ' . static::class); return $this->types[TypeHelper::getTypeKey($type)]; } @@ -93,15 +93,14 @@ class BuiltinTypeFactory implements TypeFactoryInterface public static function createWithClasses(): BuiltinTypeFactory { $types = [ - 'Ramsey\Uuid\Uuid' => UUID::get(), + 'Ramsey\Uuid\Uuid' => UUID::get(), 'Ramsey\Uuid\UuidInterface' => UUID::get(), - 'DateTime' => BuiltinType::get('string'), - 'DateTimeInterface' => BuiltinType::get('string'), - 'DateTimeImmutable' => BuiltinType::get('string'), - 'Ordering' => new Alias('Ordering', Union::create([StringConst::get('asc'), StringConst::get('desc')]), 'Allowed values for ordering parameters'), + 'DateTime' => BuiltinType::get('string'), + 'DateTimeInterface' => BuiltinType::get('string'), + 'DateTimeImmutable' => BuiltinType::get('string'), + 'Ordering' => new Alias('Ordering', Union::create([StringConst::get('asc'), StringConst::get('desc')]), 'Allowed values for ordering parameters'), ]; return new BuiltinTypeFactory($types); } - } diff --git a/src/php/Models/Types/Factory/CollectionTypeFactory.php b/src/php/Models/Types/Factory/CollectionTypeFactory.php index 84bfc3208ad99a418287b7b782d4a6b16c60ba7c..8e861588ce418c61a339fe44b47909b05b516cee 100644 --- a/src/php/Models/Types/Factory/CollectionTypeFactory.php +++ b/src/php/Models/Types/Factory/CollectionTypeFactory.php @@ -32,9 +32,8 @@ use Symfony\Component\PropertyInfo\Type as PropertyType; */ final class CollectionTypeFactory implements TypeFactoryInterface { - /** - * {@inheritDoc} + * {@inheritdoc} */ public function supportsType(PropertyType $type, ContextInterface $context): bool { @@ -42,7 +41,7 @@ final class CollectionTypeFactory implements TypeFactoryInterface } /** - * {@inheritDoc} + * {@inheritdoc} */ public function createType(PropertyType $type, ContextInterface $context): Type { diff --git a/src/php/Models/Types/Factory/DeferrableTypeFactory.php b/src/php/Models/Types/Factory/DeferrableTypeFactory.php index c12428e96a6819a68d599fe98ad6af59e59c5621..b0599baadd95af1b1947bf97d4304c1cf901bc3d 100644 --- a/src/php/Models/Types/Factory/DeferrableTypeFactory.php +++ b/src/php/Models/Types/Factory/DeferrableTypeFactory.php @@ -37,7 +37,7 @@ final class DeferrableTypeFactory extends AbstractTypeFactoryDecorator { $key = TypeHelper::getTypeKey($type); - $deferred = function () use ($type, $context) : Type { + $deferred = function () use ($type, $context): Type { return parent::createType($type, $context); }; diff --git a/src/php/Models/Types/Reference.php b/src/php/Models/Types/Reference.php index ed9ff8aff079a3b8f1523b0469c505a7e80d2bc6..d22261bacc09e46d3015cfe7542d62f0c04a6b9d 100644 --- a/src/php/Models/Types/Reference.php +++ b/src/php/Models/Types/Reference.php @@ -21,8 +21,6 @@ namespace Irstea\NgModelGeneratorBundle\Models\Types; -use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CircularReference; - /** * Class Ref. */ @@ -48,7 +46,7 @@ class Reference extends AbstractType * Reference constructor. * * @param callable $deferred - * @param string $name + * @param string $name */ public function __construct(callable $deferred, string $name = 'anonymous reference') { @@ -65,7 +63,7 @@ class Reference extends AbstractType public function getTarget(): Type { if ($this->state === self::RESOLVING) { - throw new \RuntimeException("circular reference"); + throw new \RuntimeException('circular reference'); } if ($this->state === self::UNRESOLVED) { @@ -89,6 +87,7 @@ class Reference extends AbstractType if ($target instanceof self && $target !== $this) { return $target->dereference(); } + return $target; } diff --git a/src/php/OperationMapper.php b/src/php/OperationMapper.php index 4bef97f987f9cc30b328a96f60e299036f709279..4519039870d4e4b98eabb6c3082ed27527b08319 100644 --- a/src/php/OperationMapper.php +++ b/src/php/OperationMapper.php @@ -64,11 +64,11 @@ final class OperationMapper /** * OperationMapper constructor. * - * @param TypeFactoryInterface $typeFactory + * @param TypeFactoryInterface $typeFactory * @param ContextFactoryInterface $contextFactory - * @param PathParserInterface $pathParser - * @param OperationMetadata $operation - * @param Path|null $iri + * @param PathParserInterface $pathParser + * @param OperationMetadata $operation + * @param Path|null $iri */ public function __construct( ContextFactoryInterface $contextFactory, @@ -218,7 +218,8 @@ final class OperationMapper return $clientCall; } -//// + + //// //// /** //// * @return Property[] //// */ diff --git a/src/php/SerializationMapper.php b/src/php/SerializationMapper.php index 2bfa3f149ec4f5572263678233cb436921f421a0..43f63114f027b1267ed7d9c27ce5ff8954f18856 100644 --- a/src/php/SerializationMapper.php +++ b/src/php/SerializationMapper.php @@ -34,7 +34,6 @@ use Irstea\NgModelGeneratorBundle\Models\Types\Factory\ContextInterface; use Irstea\NgModelGeneratorBundle\Models\Types\Factory\TypeFactoryInterface; use Irstea\NgModelGeneratorBundle\Models\Types\Factory\TypeHelper; use Irstea\NgModelGeneratorBundle\Models\Types\Objects\Property; -use Irstea\NgModelGeneratorBundle\Models\Types\Reference; use Irstea\NgModelGeneratorBundle\Models\Types\Resources\IRI; use Irstea\NgModelGeneratorBundle\Models\Types\Resources\Representation; use Irstea\NgModelGeneratorBundle\Models\Types\StringConst; @@ -183,7 +182,6 @@ final class SerializationMapper implements TypeFactoryInterface foreach ($classInfo->getConcreteProperties() as $propertyMeta) { /** @var PropertyMetadata $propertyMeta */ - $property = $this->mapProperty($propertyMeta, $context); $properties[$property->getName()] = $property; }