From e5807fae58bf3147ddf5d3326755994b50731f7c Mon Sep 17 00:00:00 2001
From: Perreal Guillaume <guillaume.perreal@irstea.fr>
Date: Tue, 20 Aug 2019 15:41:55 +0200
Subject: [PATCH] CS.

---
 src/php/ContextCache.php                      | 35 ++++++++++++-------
 src/php/ContextFactory.php                    |  7 ++--
 src/php/ContextFactoryInterface.php           |  2 +-
 src/php/Exceptions/EmptyModelException.php    | 27 +++++++++-----
 src/php/Exceptions/InvalidModelException.php  | 28 ++++++++++-----
 .../Exceptions/MissingIdentifierException.php | 27 +++++++++-----
 .../TooManyIdentifiersException.php           | 27 +++++++++-----
 src/php/ModelGenerator.php                    | 19 +++++-----
 .../Factory/AbstractTypeFactoryDecorator.php  |  1 +
 .../Types/Factory/BuiltinTypeFactory.php      | 13 ++++---
 .../Types/Factory/CollectionTypeFactory.php   |  5 ++-
 .../Types/Factory/DeferrableTypeFactory.php   |  2 +-
 src/php/Models/Types/Reference.php            |  7 ++--
 src/php/OperationMapper.php                   | 11 +++---
 src/php/SerializationMapper.php               |  2 --
 15 files changed, 128 insertions(+), 85 deletions(-)

diff --git a/src/php/ContextCache.php b/src/php/ContextCache.php
index 8d84c0f..377221c 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 30ef018..a69981f 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 6fa9f19..612b7ff 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 5d9ba0f..8d10fe4 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 c00379a..95b7cc0 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 be89b73..4850c4e 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 7932050..2f787ef 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 31af395..76a2a05 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 98ca281..d39efcf 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 20025a2..aab6da8 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 84bfc32..8e86158 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 c12428e..b0599ba 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 ed9ff8a..d22261b 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 4bef97f..4519039 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 2bfa3f1..43f6311 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;
         }
-- 
GitLab