diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/skip_static_function_mapping.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/skip_static_function_mapping.php.inc new file mode 100644 index 00000000000..20864e87bec --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/skip_static_function_mapping.php.inc @@ -0,0 +1,23 @@ +name = $name; + } + + public static function loadMetadata(ClassMetadata $metadata): void + { + $metadata->mapField([ + 'fieldName' => 'name', + 'type' => 'string', + ]); + } +} diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php index 4351c5a7337..6c7f13c089c 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php @@ -92,6 +92,12 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + // skip Doctrine static function mapping, properties are mapped in loadMetadata() method + // @see https://www.doctrine-project.org/projects/doctrine-orm/en/3.6/reference/php-mapping.html#static-function + if ($node->getMethod('loadMetadata') instanceof ClassMethod) { + return null; + } + $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT); if (! $constructClassMethod instanceof ClassMethod) { return null;