Skip to content

Commit f140c02

Browse files
committed
put error pattern into a const
1 parent f076d68 commit f140c02

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
@@ -15,6 +15,8 @@
1515

1616
final class PetRepository implements RepositoryInterface
1717
{
18+
private const string TYPE_ERROR_PATTERN = '%s() expects parameter 1 to be %s, %s given';
19+
1820
public function __construct(private readonly DocumentManager $documentManager) {}
1921

2022
/**
@@ -25,7 +27,7 @@ public function resolveCollection(CollectionInterface $petCollection): void
2527
if (!$petCollection instanceof PetCollection) {
2628
throw new \TypeError(
2729
\sprintf(
28-
'%s() expects parameter 1 to be %s, %s given',
30+
self::TYPE_ERROR_PATTERN,
2931
__METHOD__,
3032
PetCollection::class,
3133
$petCollection::class
@@ -77,7 +79,7 @@ public function persist(ModelInterface $pet): void
7779
if (!$pet instanceof Pet) {
7880
throw new \TypeError(
7981
\sprintf(
80-
'%s() expects parameter 1 to be %s, %s given',
82+
self::TYPE_ERROR_PATTERN,
8183
__METHOD__,
8284
Pet::class,
8385
$pet::class
@@ -93,7 +95,7 @@ public function remove(ModelInterface $pet): void
9395
if (!$pet instanceof Pet) {
9496
throw new \TypeError(
9597
\sprintf(
96-
'%s() expects parameter 1 to be %s, %s given',
98+
self::TYPE_ERROR_PATTERN,
9799
__METHOD__,
98100
Pet::class,
99101
$pet::class

0 commit comments

Comments
 (0)