Files
weather/src/Infrastructure/Persistence/User/InMemoryUserRepository.php
Oh 120dee172b
Some checks failed
Tests / Tests PHP 7.4 (push) Has been cancelled
Tests / Tests PHP 8 (push) Has been cancelled
Tests / Tests PHP 8.1 (push) Has been cancelled
PKG
2025-09-04 14:47:18 +02:00

52 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Ohrionmartin\Weather\Infrastructure\Persistence\User;
use App\Domain\User\User;
use App\Domain\User\UserNotFoundException;
use App\Domain\User\UserRepository;
class InMemoryUserRepository implements UserRepository
{
/**
* @var User[]
*/
private array $users;
/**
* @param User[]|null $users
*/
public function __construct(array $users = null)
{
$this->users = $users ?? [
1 => new User(1, 'bill.gates', 'Bill', 'Gates'),
2 => new User(2, 'steve.jobs', 'Steve', 'Jobs'),
3 => new User(3, 'mark.zuckerberg', 'Mark', 'Zuckerberg'),
4 => new User(4, 'evan.spiegel', 'Evan', 'Spiegel'),
5 => new User(5, 'jack.dorsey', 'Jack', 'Dorsey'),
];
}
/**
* {@inheritdoc}
*/
public function findAll(): array
{
return array_values($this->users);
}
/**
* {@inheritdoc}
*/
public function findUserOfId(int $id): User
{
if (!isset($this->users[$id])) {
throw new UserNotFoundException();
}
return $this->users[$id];
}
}