Skip to content

Commit 755bb32

Browse files
authored
[TypeDeclaration] Skip class with Doctrine static function mapping (loadMetadata) in TypedPropertyFromStrictConstructorRector (#8060)
1 parent cbeefaa commit 755bb32

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector\Fixture;
4+
5+
use Doctrine\ORM\Mapping\ClassMetadata;
6+
7+
final class SkipStaticFunctionMapping
8+
{
9+
private $name;
10+
11+
public function __construct(string $name)
12+
{
13+
$this->name = $name;
14+
}
15+
16+
public static function loadMetadata(ClassMetadata $metadata): void
17+
{
18+
$metadata->mapField([
19+
'fieldName' => 'name',
20+
'type' => 'string',
21+
]);
22+
}
23+
}

‎rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public function getNodeTypes(): array
9292
*/
9393
public function refactor(Node $node): ?Node
9494
{
95+
// skip Doctrine static function mapping, properties are mapped in loadMetadata() method
96+
// @see https://www.doctrine-project.org/projects/doctrine-orm/en/3.6/reference/php-mapping.html#static-function
97+
if ($node->getMethod('loadMetadata') instanceof ClassMethod) {
98+
return null;
99+
}
100+
95101
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
96102
if (! $constructClassMethod instanceof ClassMethod) {
97103
return null;

0 commit comments

Comments
 (0)