Skip to content

[composer-based] Bond AddViolationToBuildViolationRector to symfony/validator 2.5 - #983

Merged
TomasVotruba merged 1 commit into
mainfrom
bind-add-violation-to-validator-2.5
Aug 2, 2026
Merged

[composer-based] Bond AddViolationToBuildViolationRector to symfony/validator 2.5#983
TomasVotruba merged 1 commit into
mainfrom
bind-add-violation-to-validator-2.5

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

AddViolationToBuildViolationRector rewrites ExecutionContextInterface::addViolationAt() into the buildViolation() fluent builder:

-$this->context->addViolationAt('property', 'The value {{ value }} is invalid.', [
-    '{{ value }}' => $value,
-]);
+$this->context->buildViolation('The value {{ value }} is invalid.')
+    ->atPath('property')
+    ->setParameter('{{ value }}', $value)
+    ->addViolation();

That builder arrived in the validator component in 2.5, so the rule can declare the constraint itself:

public function provideComposerPackageConstraint(): ComposerPackageConstraint
{
    return new ComposerPackageConstraint('symfony/validator', '>=2.5');
}

and be registered once in the composer-based set, instead of relying on the Symfony 2.5 version set to be picked up on a direct upgrade from an older version.

symfony/validator, not symfony/symfony — a project installing the split components, which is nearly all of them today, carries no symfony/symfony to match against. Same package the neighbouring ValidatorBuilderEnableAnnotationMappingRector binds to.

A fixture in tests/ComposerBased/Fixture/ covers it through the set itself, so the rule being dropped from the list would fail a test rather than pass quietly.

…alidator 2.5

The rule rewrites ExecutionContextInterface::addViolationAt() into the
buildViolation() fluent builder, which the validator component added in 2.5. It
now declares that constraint itself, so the composer-based set can register it
once instead of leaving it to the Symfony 2.5 version set alone.

The constraint names symfony/validator rather than symfony/symfony: a project
installing the split components — nearly all of them today — carries no
symfony/symfony to match against.
@TomasVotruba
TomasVotruba merged commit d39f390 into main Aug 2, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the bind-add-violation-to-validator-2.5 branch August 2, 2026 09:08
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