From c1d42b5a0a51f50c9b37f10d33dbd135fb0c7e8c Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Aug 2026 23:19:35 +0200 Subject: [PATCH 1/2] Skip constraint without own constructor in LoadValidatorMetadataToAttributeRector --- ...constraint_without_own_constructor.php.inc | 19 ++++++++++ .../Source/UniqueUserAlias.php | 29 ++++++++++++++ ...LoadValidatorMetadataToAttributeRector.php | 7 ++++ .../ConstraintConstructorAnalyzer.php | 38 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Fixture/skip_constraint_without_own_constructor.php.inc create mode 100644 rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Source/UniqueUserAlias.php create mode 100644 src/NodeAnalyzer/ValidatorAssert/ConstraintConstructorAnalyzer.php diff --git a/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Fixture/skip_constraint_without_own_constructor.php.inc b/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Fixture/skip_constraint_without_own_constructor.php.inc new file mode 100644 index 00000000..e80c145c --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Fixture/skip_constraint_without_own_constructor.php.inc @@ -0,0 +1,19 @@ +addConstraint(new UniqueUserAlias([ + 'field' => 'alias', + 'message' => 'mautic.lead.list.alias.unique', + ])); + } +} diff --git a/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Source/UniqueUserAlias.php b/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Source/UniqueUserAlias.php new file mode 100644 index 00000000..74296c82 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/LoadValidatorMetadataToAttributeRector/Source/UniqueUserAlias.php @@ -0,0 +1,29 @@ + 'alias']) - the options have no matching constructor arguments + if ($new->args !== [] && ! $this->constraintConstructorAnalyzer->hasOwnConstructor($constraintClass)) { + return null; + } + return $constraintClass; } } diff --git a/src/NodeAnalyzer/ValidatorAssert/ConstraintConstructorAnalyzer.php b/src/NodeAnalyzer/ValidatorAssert/ConstraintConstructorAnalyzer.php new file mode 100644 index 00000000..bfa3badb --- /dev/null +++ b/src/NodeAnalyzer/ValidatorAssert/ConstraintConstructorAnalyzer.php @@ -0,0 +1,38 @@ +reflectionProvider->hasClass($constraintClass)) { + return false; + } + + $classReflection = $this->reflectionProvider->getClass($constraintClass); + if (! $classReflection->hasConstructor()) { + return false; + } + + $extendedMethodReflection = $classReflection->getConstructor(); + + return $extendedMethodReflection->getDeclaringClass() + ->getName() !== Constraint::class; + } +} From 876953a83ca257f86ce546049c11baabe9bd4c56 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Aug 2026 23:21:01 +0200 Subject: [PATCH 2/2] Fix method chaining indentation in ConstantExpressionAnalyzerTest --- .../ValidatorAssert/ConstantExpressionAnalyzerTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/NodeAnalyzer/ValidatorAssert/ConstantExpressionAnalyzerTest.php b/tests/NodeAnalyzer/ValidatorAssert/ConstantExpressionAnalyzerTest.php index a9af9caa..4453e4c5 100644 --- a/tests/NodeAnalyzer/ValidatorAssert/ConstantExpressionAnalyzerTest.php +++ b/tests/NodeAnalyzer/ValidatorAssert/ConstantExpressionAnalyzerTest.php @@ -53,7 +53,8 @@ public static function provideData(): iterable private function parseNew(string $newExpression): New_ { - $parser = new ParserFactory()->createForNewestSupportedVersion(); + $parser = new ParserFactory() + ->createForNewestSupportedVersion(); $stmts = $parser->parse('assertIsArray($stmts);