Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CadastroAutorService | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Core\Services\Emprestimo; |
| 4 | |
| 5 | use Core\Models\{ |
| 6 | Autor, |
| 7 | }; |
| 8 | |
| 9 | use Core\Repositories\{ |
| 10 | IAutoresRepository, |
| 11 | }; |
| 12 | |
| 13 | class CadastroAutorService |
| 14 | { |
| 15 | function __construct( |
| 16 | private IAutoresRepository $repo, |
| 17 | ){} |
| 18 | |
| 19 | public function execute( |
| 20 | string $nome, |
| 21 | ?int $id = null, |
| 22 | ): Autor { |
| 23 | $a = null; |
| 24 | |
| 25 | if(!is_null($id)) { |
| 26 | $a = $this->repo->findById($id); |
| 27 | $a->nome = $nome; |
| 28 | } else { |
| 29 | $a = new Autor( |
| 30 | id: $id, |
| 31 | nome: $nome, |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | return $this->repo->save($a); |
| 36 | } |
| 37 | } |
| 38 |