Skip to content

Commit b2799b9

Browse files
authored
Allow for final embeddable class
1 parent 85339d7 commit b2799b9

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

src/Rules/Doctrine/ORM/EntityNotFinalRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function processNode(Node $node, Scope $scope): array
4343
return [];
4444
}
4545

46+
$metadata = $this->objectMetadataResolver->getClassMetadata($classReflection->getName());
47+
if ($metadata !== null && $metadata->isEmbeddedClass === true) {
48+
return [];
49+
}
50+
4651
return [sprintf(
4752
'Entity class %s is final which can cause problems with proxies.',
4853
$classReflection->getDisplayName()

tests/Rules/Doctrine/ORM/EntityNotFinalRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public function ruleProvider(): Iterator
7272
__DIR__ . '/data/MyEntity.php',
7373
[],
7474
];
75+
76+
yield 'final embeddable' => [
77+
__DIR__ . '/data/FinalEmbeddable.php',
78+
[],
79+
];
80+
81+
yield 'non final embeddable' => [
82+
__DIR__ . '/data/MyEmbeddable.php',
83+
[],
84+
];
7585
}
7686

7787
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Doctrine\ORM;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Embeddable()
9+
*/
10+
final class FinalEmbeddable
11+
{
12+
/**
13+
* @ORM\Id()
14+
* @ORM\GeneratedValue()
15+
* @ORM\Column(type="integer")
16+
*
17+
* @var int
18+
*/
19+
private $id;
20+
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Doctrine\ORM;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* @ORM\Embeddable()
9+
*/
10+
class MyEmbeddable
11+
{
12+
/**
13+
* @var string
14+
* @ORM\Column(type="string")
15+
*/
16+
private $title;
17+
}

0 commit comments

Comments
 (0)