Skip to content

Commit c1d4373

Browse files
committed
Deprecate ValidationResult::setSource
The last change added a huge explanation comment on how this method is to be used. This commit now names the field `setSourceForAllViolations` to make it more clear to the dependent code what the method does. We should remove the `setSource` method together with the CanValidateField trait. Bug: https://phabricator.wikimedia.org/T383340
1 parent 928687e commit c1d4373

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/ValidationResult.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public function getViolations(): array {
3030
return $this->violations;
3131
}
3232

33+
/**
34+
* @deprecated Use {@see setSourceForAllViolations()} instead
35+
*/
36+
public function setSource( string $sourceName ): self {
37+
return $this->setSourceForAllViolations( $sourceName );
38+
}
39+
3340
/**
3441
* Set source of an error in all violations.
3542
*
@@ -41,7 +48,7 @@ public function getViolations(): array {
4148
* that validate several sources. In those cases, the responsibility to
4249
* set the source is with the validator and not its calling code.
4350
*/
44-
public function setSource( string $sourceName ): self {
51+
public function setSourceForAllViolations( string $sourceName ): self {
4552
foreach ( $this->violations as $violation ) {
4653
$violation->setSource( $sourceName );
4754
}

tests/Unit/ValidationResultTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public function testResultWithViolationsIsNotSuccessful(): void {
2828
$this->assertSame( [ $violation1, $violation2 ], $result->getViolations() );
2929
}
3030

31-
public function testSetSourceSetsSourceForAllViolations(): void {
31+
public function testSetSourceForAllViolationsChangesAllViolations(): void {
3232
$violation1 = new ConstraintViolation( 'value?', 'test_message_1' );
3333
$violation2 = new ConstraintViolation( 'value!', 'test_message_2' );
3434
$result = new ValidationResult( $violation1, $violation2 );
3535

36-
$result->setSource( 'a_test_field' );
36+
$result->setSourceForAllViolations( 'a_test_field' );
3737

3838
$this->assertSame( 'a_test_field', $violation1->getSource() );
3939
$this->assertSame( 'a_test_field', $violation2->getSource() );

0 commit comments

Comments
 (0)