diff --git a/src/php/ModelGenerator.php b/src/php/ModelGenerator.php index 76a2a05c9f77abb117ab7c6c3aa880cdc3106044..a2f747795a89b0b1e0312db639e2325c0b28e444 100644 --- a/src/php/ModelGenerator.php +++ b/src/php/ModelGenerator.php @@ -22,6 +22,7 @@ namespace Irstea\NgModelGeneratorBundle; use ApiPlatform\Core\Documentation\Documentation; +use Assert\Assertion; use Irstea\NgModelGeneratorBundle\Exceptions\DomainException; use Irstea\NgModelGeneratorBundle\Exceptions\EmptyModelException; use Irstea\NgModelGeneratorBundle\Exceptions\Exception; @@ -62,9 +63,8 @@ final class ModelGenerator * Serializer constructor. * * @param MetadataFactoryInterface $metadataFactory - * @param ContextFactoryInterface $contextFactory - * @param TypeFactoryInterface $typeFactory - * @param Environment $twigEnv + * @param ContextFactoryInterface $contextFactory + * @param Environment $twigEnv */ public function __construct( MetadataFactoryInterface $metadataFactory, @@ -177,7 +177,8 @@ final class ModelGenerator { $classNames = iterator_to_array($this->documentation->getResourceNameCollection()->getIterator()); $classes = array_map([PHPClass::class, 'get'], $classNames); - usort($classes, [PHPClass::class, 'baseNameOrdering']); + $sorter = \Closure::fromCallable([PHPClass::class, 'baseNameOrdering']); + usort($classes, $sorter); foreach ($classes as $class) { yield $class => $this->metadataFactory->getResourceMetadata($class); @@ -247,6 +248,7 @@ final class ModelGenerator } $identifier = array_shift($identifiers); + Assertion::notNull($identifier); $operations = []; $pathParser = new PathParser($properties); diff --git a/src/php/Models/ClassInfo.php b/src/php/Models/ClassInfo.php index 9d57ed7ab8c49a5da71a8035534ae8bbf615de02..636b89f02ebecc637355bc31a3160724c684dc2c 100644 --- a/src/php/Models/ClassInfo.php +++ b/src/php/Models/ClassInfo.php @@ -21,8 +21,10 @@ namespace Irstea\NgModelGeneratorBundle\Models; +use Assert\Assertion; use Irstea\NgModelGeneratorBundle\Exceptions\DomainException; use Irstea\NgModelGeneratorBundle\Metadata\PropertyMetadata; +use Irstea\NgModelGeneratorBundle\Models\Types\Objects\Property; /** * Class ClassInfo. @@ -315,6 +317,7 @@ final class ClassInfo implements ClassName return; } + /** @var PropertyMetadata[][] $classProperties */ $classProperties = []; if (!$this->abstract) { $classProperties[] = $this->virtualProperties; @@ -324,6 +327,7 @@ final class ClassInfo implements ClassName $classProperties[] = $child->virtualProperties; } + /** @var PropertyMetadata[] $commonProperties */ switch (\count($classProperties)) { case 0: return; @@ -338,7 +342,10 @@ final class ClassInfo implements ClassName return; } - $this->virtualProperties = array_replace($this->virtualProperties, $commonProperties); + $result = array_replace($this->virtualProperties, $commonProperties); + Assertion::notNull($result); + + $this->virtualProperties = $result; } /** diff --git a/src/php/Models/Types/Objects/AnonymousObject.php b/src/php/Models/Types/Objects/AnonymousObject.php index 9799b69f2c22f67fcd086f1e6dbe45459de32d2a..e48d7931931e54c14f8d372bcf09817c584aa318 100644 --- a/src/php/Models/Types/Objects/AnonymousObject.php +++ b/src/php/Models/Types/Objects/AnonymousObject.php @@ -22,6 +22,7 @@ namespace Irstea\NgModelGeneratorBundle\Models\Types\Objects; use Irstea\NgModelGeneratorBundle\Exceptions\DomainException; +use Irstea\NgModelGeneratorBundle\Models\PHPClass; use Irstea\NgModelGeneratorBundle\Models\Types\AbstractType; use Irstea\NgModelGeneratorBundle\Models\Types\BuiltinType; use Irstea\NgModelGeneratorBundle\TypescriptHelper; @@ -50,7 +51,9 @@ class AnonymousObject extends AbstractType } $this->properties[$name] = $property; } - uasort($this->properties, [Property::class, 'compare']); + + $sorter = \Closure::fromCallable([Property::class, 'compare']); + uasort($this->properties, $sorter); } /** @@ -110,13 +113,19 @@ class AnonymousObject extends AbstractType /** @var Property $property */ foreach ($this->properties as $property) { - $tpl = $property->isNullable() ? '(!(%s) || %s)' : '(%s && %s)'; - $tests[] = sprintf( - $tpl, - TypescriptHelper::propertyTestor($expr, $property->getName()), - $expr, - $property->getType()->checkType($property->getUsage($expr), false) - ); + if ($property->isNullable()) { + $tests[] = sprintf( + '(!(%s) || %s)', + TypescriptHelper::propertyTestor($expr, $property->getName()), + $property->getType()->checkType($property->getUsage($expr), false) + ); + } else { + $tests[] = sprintf( + '(%s && %s)', + TypescriptHelper::propertyTestor($expr, $property->getName()), + $property->getType()->checkType($property->getUsage($expr), false) + ); + } } return '(' . implode("\n && ", $tests) . ')'; diff --git a/src/php/OperationMapper.php b/src/php/OperationMapper.php index 4519039870d4e4b98eabb6c3082ed27527b08319..4b7bb4f1d36f72bd75f612af0f205b7fa57a5ace 100644 --- a/src/php/OperationMapper.php +++ b/src/php/OperationMapper.php @@ -64,11 +64,10 @@ final class OperationMapper /** * OperationMapper constructor. * - * @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,