fix test warning for undefined array key by using array_find
This commit is contained in:
parent
b3453a4604
commit
424d46104b
2 changed files with 11 additions and 1 deletions
|
|
@ -9,6 +9,11 @@ class Text
|
|||
private string $name,
|
||||
) {}
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,12 @@ class FakeTextRepository implements TextRepository
|
|||
|
||||
public function find(int $id): ?Text
|
||||
{
|
||||
$text = $this->existingTexts[$id];
|
||||
$text = array_find(
|
||||
$this->existingTexts,
|
||||
function (Text $text) use ($id){
|
||||
return $text->getId() === $id;
|
||||
}
|
||||
);
|
||||
if ($text === null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue