Initial commit
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

This commit is contained in:
Oh
2025-09-04 08:59:22 +02:00
commit c87bf18b4e
47 changed files with 5182 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace App\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];
}
}