Skip to content

Commit f9baa0e

Browse files
committed
put error pattern into a const
1 parent 9bb9994 commit f9baa0e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/Pet/Repository/PetRepository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
final class PetRepository implements RepositoryInterface
1616
{
17+
private const string TYPE_ERROR_PATTERN = '%s() expects parameter 1 to be %s, %s given';
18+
1719
public function __construct(private readonly EntityManager $entityManager) {}
1820

1921
/**
@@ -24,7 +26,7 @@ public function resolveCollection(CollectionInterface $petCollection): void
2426
if (!$petCollection instanceof PetCollection) {
2527
throw new \TypeError(
2628
\sprintf(
27-
'%s() expects parameter 1 to be %s, %s given',
29+
self::TYPE_ERROR_PATTERN,
2830
__METHOD__,
2931
PetCollection::class,
3032
$petCollection::class
@@ -73,7 +75,7 @@ public function persist(ModelInterface $pet): void
7375
if (!$pet instanceof Pet) {
7476
throw new \TypeError(
7577
\sprintf(
76-
'%s() expects parameter 1 to be %s, %s given',
78+
self::TYPE_ERROR_PATTERN,
7779
__METHOD__,
7880
Pet::class,
7981
$pet::class
@@ -89,7 +91,7 @@ public function remove(ModelInterface $pet): void
8991
if (!$pet instanceof Pet) {
9092
throw new \TypeError(
9193
\sprintf(
92-
'%s() expects parameter 1 to be %s, %s given',
94+
self::TYPE_ERROR_PATTERN,
9395
__METHOD__,
9496
Pet::class,
9597
$pet::class

0 commit comments

Comments
 (0)