Skip to content

Commit

Permalink
Merge pull request #1490 from scyzoryck/alternative-doc-blocks-names
Browse files Browse the repository at this point in the history
feat(TypeResolvers): Add support for alternative name in doc blocs.
  • Loading branch information
scyzoryck authored Jun 24, 2023
2 parents 72a24a3 + a57be74 commit 926a7d5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 2 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<file>src/</file>
<file>tests/</file>

<exclude-pattern>tests/Fixtures/DocBlockType/AlternativePHPDocsNames.php</exclude-pattern>
<rule ref="Doctrine">
<exclude name="Generic.Formatting.SpaceAfterNot"/>
<exclude name="Generic.Formatting.MultipleStatementAlignment"/>
Expand All @@ -40,7 +40,7 @@

<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>

<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property
name="forbiddenAnnotations"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ private function endsWith(string $statementClassToCheck, string $typeHintToSearc

private function isPrimitiveType(string $type): bool
{
return in_array($type, ['int', 'float', 'bool', 'string']);
return in_array($type, ['int', 'integer', 'float', 'bool', 'boolean', 'double', 'string']);
}

private function hasGlobalNamespacePrefix(string $typeHint): bool
Expand Down
17 changes: 17 additions & 0 deletions tests/Fixtures/DocBlockType/AlternativePHPDocsNames.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace JMS\Serializer\Tests\Fixtures\DocBlockType;

class AlternativePHPDocsNames
{
/** @var integer */
public $integer;

/** @var double */
public $double;

/** @var boolean */
public $boolean;
}
21 changes: 21 additions & 0 deletions tests/Metadata/Driver/DocBlockDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use JMS\Serializer\Metadata\Driver\DocBlockDriver;
use JMS\Serializer\Metadata\Driver\TypedPropertiesDriver;
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
use JMS\Serializer\Tests\Fixtures\DocBlockType\AlternativePHPDocsNames;
use JMS\Serializer\Tests\Fixtures\DocBlockType\Collection\CollectionAsList;
use JMS\Serializer\Tests\Fixtures\DocBlockType\Collection\CollectionOfClassesFromDifferentNamespace;
use JMS\Serializer\Tests\Fixtures\DocBlockType\Collection\CollectionOfClassesFromDifferentNamespaceUsingGroupAlias;
Expand Down Expand Up @@ -462,4 +463,24 @@ public function testInferTypeForVirtualPropertyGetter()
$m->propertyMetadata['arrayOfStrings']->type
);
}

public function testAlternativeNames()
{
$m = $this->resolve(AlternativePHPDocsNames::class);

self::assertEquals(
['name' => 'integer', 'params' => []],
$m->propertyMetadata['integer']->type
);

self::assertEquals(
['name' => 'double', 'params' => []],
$m->propertyMetadata['double']->type
);

self::assertEquals(
['name' => 'boolean', 'params' => []],
$m->propertyMetadata['boolean']->type
);
}
}

0 comments on commit 926a7d5

Please sign in to comment.