Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| UpdateBookRequest | |
100.00% |
15 / 15 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromHttpRequest | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| validate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\Library\Presentation\Request; |
| 11 | |
| 12 | use AppDemo\Library\Presentation\Validator\BookFieldValidator; |
| 13 | use Psr\Http\Message\ServerRequestInterface; |
| 14 | |
| 15 | final readonly class UpdateBookRequest |
| 16 | { |
| 17 | private function __construct( |
| 18 | public string $title, |
| 19 | public string $author, |
| 20 | public string $isbn, |
| 21 | public string $status |
| 22 | ) {} |
| 23 | |
| 24 | public static function fromHttpRequest(ServerRequestInterface $request): self |
| 25 | { |
| 26 | $data = (array) $request->getParsedBody(); |
| 27 | |
| 28 | return new self( |
| 29 | $data['title'] ?? '', |
| 30 | $data['author'] ?? '', |
| 31 | $data['isbn'] ?? '', |
| 32 | $data['status'] ?? '' |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | public function validate(): array |
| 37 | { |
| 38 | return BookFieldValidator::validate($this->title, $this->author, $this->isbn); |
| 39 | } |
| 40 | |
| 41 | public function toArray(): array |
| 42 | { |
| 43 | return [ |
| 44 | 'title' => $this->title, |
| 45 | 'author' => $this->author, |
| 46 | 'isbn' => $this->isbn, |
| 47 | 'status' => $this->status, |
| 48 | ]; |
| 49 | } |
| 50 | } |