Skip to content

Commit b562610

Browse files
committed
minor #49881 [Validator] Throw Symfony/OutOfBounds exception instead of default one in ConstraintViolationList (VincentLanglet)
This PR was merged into the 6.3 branch. Discussion ---------- [Validator] Throw Symfony/OutOfBounds exception instead of default one in ConstraintViolationList | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Symfony seems to almost always using namespaced Exception rather than default one. This is useful: - In order to do custom catch - When using static analysis and you want to track some exception and exclude others But the ConstraintViolationList was throwing the PHP OutOfBounds exception even if a namespaced one exists for Validator component. This PR is BC and change this. Commits ------- 8689920c49 Throw Symfony OutOfBounds exception instead of default one
2 parents e047c78 + ec7df1c commit b562610

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ConstraintViolationList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Validator;
1313

14+
use Symfony\Component\Validator\Exception\OutOfBoundsException;
15+
1416
/**
1517
* Default implementation of {@ConstraintViolationListInterface}.
1618
*
@@ -77,7 +79,7 @@ public function addAll(ConstraintViolationListInterface $otherList)
7779
public function get(int $offset): ConstraintViolationInterface
7880
{
7981
if (!isset($this->violations[$offset])) {
80-
throw new \OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
82+
throw new OutOfBoundsException(sprintf('The offset "%s" does not exist.', $offset));
8183
}
8284

8385
return $this->violations[$offset];

ConstraintViolationListInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Validator;
1313

14+
use Symfony\Component\Validator\Exception\OutOfBoundsException;
15+
1416
/**
1517
* A list of constraint violations.
1618
*
@@ -42,7 +44,7 @@ public function addAll(self $otherList);
4244
*
4345
* @param int $offset The offset of the violation
4446
*
45-
* @throws \OutOfBoundsException if the offset does not exist
47+
* @throws OutOfBoundsException if the offset does not exist
4648
*/
4749
public function get(int $offset): ConstraintViolationInterface;
4850

0 commit comments

Comments
 (0)