Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | final class AuthorService |
||
14 | { |
||
15 | private $authors; |
||
16 | private $assembler; |
||
17 | |||
18 | public function __construct(AuthorRepository $authors, Assembler $assembler) |
||
19 | { |
||
20 | $this->authors = $authors; |
||
21 | $this->assembler = $assembler; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @throws AuthorNotFound |
||
26 | */ |
||
27 | public function fetch(string $id): AuthorDto |
||
28 | { |
||
29 | $authorId = AuthorId::fromString($id); |
||
30 | |||
31 | if (null === $author = $this->authors->byId($authorId)) { |
||
32 | throw AuthorNotFound::byId($authorId); |
||
33 | } |
||
34 | |||
35 | return $this->assembler->toAuthorDto($author); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return AuthorDto[] |
||
40 | */ |
||
41 | public function fetchAll(): array |
||
42 | { |
||
43 | return array_map([$this->assembler, 'toAuthorDto'], $this->authors->all()); |
||
44 | } |
||
46 |