Skip to content

Commit 753f9e8

Browse files
committed
Avoid error about unknown annotations
1 parent 47aa7ca commit 753f9e8

File tree

3 files changed

+517
-1
lines changed

3 files changed

+517
-1
lines changed

src/Doctrine/Mapping/ClassMetadataFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Doctrine\Mapping;
44

55
use Doctrine\Common\Annotations\AnnotationReader;
6+
use Doctrine\Common\Annotations\DocParser;
67
use Doctrine\Common\EventManager;
78
use Doctrine\DBAL\Platforms\MySqlPlatform;
89
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -24,7 +25,9 @@ protected function initialize(): void
2425

2526
$drivers = [];
2627
if (class_exists(AnnotationReader::class)) {
27-
$drivers[] = new AnnotationDriver(new AnnotationReader());
28+
$docParser = new DocParser();
29+
$docParser->setIgnoreNotImportedAnnotations(true);
30+
$drivers[] = new AnnotationDriver(new AnnotationReader($docParser));
2831
}
2932
if (class_exists(AttributeDriver::class) && PHP_VERSION_ID >= 80000) {
3033
$drivers[] = new AttributeDriver([]);

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,14 @@ public function testEnumType(?string $objectManagerLoader): void
364364
]);
365365
}
366366

367+
/**
368+
* @dataProvider dataObjectManagerLoader
369+
*/
370+
public function testPhpStanBug6445(?string $objectManagerLoader): void
371+
{
372+
$this->allowNullablePropertyForRequiredField = false;
373+
$this->objectManagerLoader = $objectManagerLoader;
374+
$this->analyse([__DIR__ . '/data/phpstan-bug-6445.php'], []);
375+
}
376+
367377
}

0 commit comments

Comments
 (0)