Repository: phpstan/phpstan-doctrine (php)

Issue:
EntityNotFinalRule should allow for final keyword for embeddables
## State

Project with some entities and embeddables.

## Current

```
 ------ -------------------------------------------------------------------------------------------- 
  Line   src/Entity/Bar.php                                                                      
 ------ -------------------------------------------------------------------------------------------- 
  10     Entity class App\Foo\Entity\Bar is final which can cause problems with proxies.  
 ------ -------------------------------------------------------------------------------------------- 
```

## Expected

No errors :)

Pull request description:
Allow for final embeddable class
Fixes #215 

Patch:
diff --git a/src/Rules/Doctrine/ORM/EntityNotFinalRule.php b/src/Rules/Doctrine/ORM/EntityNotFinalRule.php
index c69112b..a80fbe6 100644
--- a/src/Rules/Doctrine/ORM/EntityNotFinalRule.php
+++ b/src/Rules/Doctrine/ORM/EntityNotFinalRule.php
@@ -43,6 +43,11 @@ class EntityNotFinalRule implements Rule
 			return [];
 		}
 
+		$metadata = $this->objectMetadataResolver->getClassMetadata($classReflection->getName());
+		if ($metadata !== null && $metadata->isEmbeddedClass === true) {
+			return [];
+		}
+
 		return [sprintf(
 			'Entity class %s is final which can cause problems with proxies.',
 			$classReflection->getDisplayName()


Test patch:
diff --git a/tests/Rules/Doctrine/ORM/EntityNotFinalRuleTest.php b/tests/Rules/Doctrine/ORM/EntityNotFinalRuleTest.php
index cd29cf9..7ee88a3 100644
--- a/tests/Rules/Doctrine/ORM/EntityNotFinalRuleTest.php
+++ b/tests/Rules/Doctrine/ORM/EntityNotFinalRuleTest.php
@@ -72,6 +72,16 @@ class EntityNotFinalRuleTest extends RuleTestCase
 			__DIR__ . '/data/MyEntity.php',
 			[],
 		];
+
+		yield 'final embeddable' => [
+			__DIR__ . '/data/FinalEmbeddable.php',
+			[],
+		];
+
+		yield 'non final embeddable' => [
+			__DIR__ . '/data/MyEmbeddable.php',
+			[],
+		];
 	}
 
 }
diff --git a/tests/Rules/Doctrine/ORM/data/FinalEmbeddable.php b/tests/Rules/Doctrine/ORM/data/FinalEmbeddable.php
new file mode 100644
index 0000000..2dedb38
--- /dev/null
+++ b/tests/Rules/Doctrine/ORM/data/FinalEmbeddable.php
@@ -0,0 +1,21 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\Rules\Doctrine\ORM;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Embeddable()
+ */
+final class FinalEmbeddable
+{
+	/**
+	 * @ORM\Id()
+	 * @ORM\GeneratedValue()
+	 * @ORM\Column(type="integer")
+	 *
+	 * @var int
+	 */
+	private $id;
+
+}
diff --git a/tests/Rules/Doctrine/ORM/data/MyEmbeddable.php b/tests/Rules/Doctrine/ORM/data/MyEmbeddable.php
new file mode 100644
index 0000000..61e83f6
--- /dev/null
+++ b/tests/Rules/Doctrine/ORM/data/MyEmbeddable.php
@@ -0,0 +1,17 @@
+<?php declare(strict_types = 1);
+
+namespace PHPStan\Rules\Doctrine\ORM;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Embeddable()
+ */
+class MyEmbeddable
+{
+	/**
+	 * @var string
+	 * @ORM\Column(type="string")
+	 */
+	private $title;
+}