Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Doctrine/Common/Annotations/AnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class AnnotationReader implements Reader
// PHP CodeSniffer
'codingStandardsIgnoreStart' => true,
'codingStandardsIgnoreEnd' => true,
// PHPStan
'template' => true, 'implements' => true, 'extends' => true, 'use' => true,
];

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtClassLevel;
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtMethodLevel;
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtPropertyLevel;
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPStanGenericsAnnotations;

class AnnotationReaderTest extends AbstractReaderTest
{
Expand Down Expand Up @@ -165,4 +166,18 @@ public function testPHPCodeSnifferAnnotationsAreIgnored()

self::assertEmpty($reader->getClassAnnotations($ref));
}

public function testPHPStanGenericsAnnotationsAreIgnored()
{
$reader = $this->getReader();
$ref = new \ReflectionClass(ClassWithPHPStanGenericsAnnotations::class);

self::assertEmpty($reader->getClassAnnotations($ref));
self::assertEmpty($reader->getPropertyAnnotations($ref->getProperty('bar')));
self::assertEmpty($reader->getMethodAnnotations($ref->getMethod('foo')));

$this->expectException('\Doctrine\Common\Annotations\AnnotationException');
$this->expectExceptionMessage('[Semantical Error] The annotation "@Template" in method Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPStanGenericsAnnotations::twigTemplateFunctionName() was never imported.');
self::assertEmpty($reader->getMethodAnnotations($ref->getMethod('twigTemplateFunctionName')));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Doctrine\Tests\Common\Annotations\Fixtures;

/**
* @template T
*/
interface WithPHPStanExtendsAnnotationsInterface
{

}

/**
* @template T
*/
class ClassWithPHPStanExtendsAnnotationsGeneric
{

}

/**
* @template T
*/
trait GenericPHPStanTrait
{

}

/**
* @template T
* @implements WithPHPStanExtendsAnnotationsInterface<int>
* @extends ClassWithPHPStanExtendsAnnotationsGeneric<int>
*/
class ClassWithPHPStanGenericsAnnotations extends ClassWithPHPStanExtendsAnnotationsGeneric implements WithPHPStanExtendsAnnotationsInterface
{
/**
* @use GenericPHPStanTrait<T>
*/
use GenericPHPStanTrait;

/**
* @var array<T>
*/
private $bar;

/**
* @param array<T> $array
*
* @return array<T>
*/
public function foo($array)
{
return $this->bar;
}

/**
* @Template("@foo.html.twig")
*/
public function twigTemplateFunctionName()
{

}
}