-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathDoctrineEntityDocumentAnalyser.php
More file actions
45 lines (34 loc) · 1.17 KB
/
DoctrineEntityDocumentAnalyser.php
File metadata and controls
45 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\CodeQuality\NodeAnalyser;
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\Reflection\ReflectionProvider;
final readonly class DoctrineEntityDocumentAnalyser
{
/**
* @var string[]
*/
private const array ENTITY_DOCBLOCK_MARKERS = ['@Document', '@ORM\\Document', '@Entity', '@ORM\\Entity'];
public function __construct(
private ReflectionProvider $reflectionProvider,
) {
}
public function isEntityClass(string $className): bool
{
if (! $this->reflectionProvider->hasClass($className)) {
return false;
}
$classReflection = $this->reflectionProvider->getClass($className);
$resolvedPhpDocBlock = $classReflection->getResolvedPhpDoc();
if (! $resolvedPhpDocBlock instanceof ResolvedPhpDocBlock) {
return false;
}
foreach (self::ENTITY_DOCBLOCK_MARKERS as $entityDocBlockMarkers) {
if (str_contains($resolvedPhpDocBlock->getPhpDocString(), $entityDocBlockMarkers)) {
return true;
}
}
// @todo apply attributes as well
return false;
}
}