Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
CreateBookRequest
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 fromHttpRequest
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
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
8declare(strict_types=1);
9
10namespace AppDemo\Library\Presentation\Request;
11
12use AppDemo\Library\Presentation\Validator\BookFieldValidator;
13use Psr\Http\Message\ServerRequestInterface;
14
15final readonly class CreateBookRequest
16{
17    private function __construct(
18        public string $title,
19        public string $author,
20        public string $isbn
21    ) {}
22
23    public static function fromHttpRequest(ServerRequestInterface $request): self
24    {
25        $data = (array) $request->getParsedBody();
26
27        return new self(
28            $data['title'] ?? '',
29            $data['author'] ?? '',
30            $data['isbn'] ?? ''
31        );
32    }
33
34    public function validate(): array
35    {
36        return BookFieldValidator::validate($this->title, $this->author, $this->isbn);
37    }
38
39    public function toArray(): array
40    {
41        return [
42            'title' => $this->title,
43            'author' => $this->author,
44            'isbn' => $this->isbn,
45        ];
46    }
47}