Skip to content

[CodeQuality] Skip loadValidatorMetadata() containing addConstraint(new Callback()) - #1038

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-callback-load-validator-metadata
Aug 12, 2026
Merged

[CodeQuality] Skip loadValidatorMetadata() containing addConstraint(new Callback())#1038
TomasVotruba merged 1 commit into
mainfrom
skip-callback-load-validator-metadata

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

A Callback constraint wraps a closure or a method reference. It cannot be expressed as constant attribute arguments, so moving the surrounding constraints out and leaving (or converting) the Callback breaks validation.

Now LoadValidatorMetadataToAttributeRector leaves the whole loadValidatorMetadata() method untouched when it contains $metadata->addConstraint(new Callback(...)).

Before this change, a Callback class constraint was converted to a class attribute:

-final class SomeClass
-{
-    public static function loadValidatorMetadata(ClassMetadata $metadata): void
-    {
-        $metadata->addConstraint(new Assert\Callback('validatePostalCode'));
-    }
-}
+#[\Symfony\Component\Validator\Constraints\Callback('validatePostalCode')]
+final class SomeClass
+{
+}

Now such a method is skipped entirely — no change — including when a movable constraint sits beside the Callback:

// left untouched
public static function loadValidatorMetadata(ClassMetadata $metadata): void
{
    $metadata->addPropertyConstraint('city', new Assert\NotBlank());
    $metadata->addConstraint(new Assert\Callback('validateCity'));
}

@TomasVotruba
TomasVotruba force-pushed the skip-callback-load-validator-metadata branch from 0376648 to fb6d768 Compare August 12, 2026 16:23
@TomasVotruba
TomasVotruba marked this pull request as ready for review August 12, 2026 16:25
@TomasVotruba
TomasVotruba merged commit d5d5148 into main Aug 12, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the skip-callback-load-validator-metadata branch August 12, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant