Skip to content

Commit d82b2c3

Browse files
authored
Merge pull request #914 from dunglas/exclude_static
Exclude static methods in AnnotationPropertyNameCollectionFactory
2 parents a7e52f5 + 5bad148 commit d82b2c3

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/Metadata/Property/Factory/AnnotationPropertyNameCollectionFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function create(string $resourceClass, array $options = []): PropertyName
6969

7070
// Methods
7171
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
72+
if ($reflectionMethod->isStatic()) {
73+
continue;
74+
}
75+
7276
$propertyName = $this->reflection->getProperty($reflectionMethod->name);
7377
if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
7478
$propertyName = lcfirst($propertyName);

tests/Fixtures/TestBundle/Entity/Dummy.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class Dummy
130130
*/
131131
public $nameConverted;
132132

133+
public static function staticMethod()
134+
{
135+
}
136+
133137
public function __construct()
134138
{
135139
$this->relatedDummies = new ArrayCollection();

tests/Metadata/Property/Factory/AnnotationPropertyNameCollectionFactoryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function testCreate(ProphecyInterface $decorated = null, array $results)
3636
$reader->getPropertyAnnotation(Argument::type(\ReflectionProperty::class), ApiProperty::class)->willReturn(null)->shouldBeCalled();
3737
$reader->getMethodAnnotation(new \ReflectionMethod(Dummy::class, 'getName'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
3838
$reader->getMethodAnnotation(new \ReflectionMethod(Dummy::class, 'getAlias'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled();
39+
$reader->getMethodAnnotation(new \ReflectionMethod(Dummy::class, 'staticMethod'), ApiProperty::class)->shouldNotBeCalled();
3940
$reader->getMethodAnnotation(Argument::type(\ReflectionMethod::class), ApiProperty::class)->willReturn(null)->shouldBeCalled();
4041

4142
$factory = new AnnotationPropertyNameCollectionFactory($reader->reveal(), $decorated ? $decorated->reveal() : null);

0 commit comments

Comments
 (0)