Total Complexity | 7 |
Total Lines | 68 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class Book |
||
8 | { |
||
9 | /** @var mixed */ |
||
10 | public $id; |
||
11 | /** @var string */ |
||
12 | public string $title; |
||
13 | /** @var string */ |
||
14 | public ?string $summary; |
||
15 | /** @var mixed */ |
||
16 | public $authorId; |
||
17 | /** @var Author|null */ |
||
18 | public ?Author $author; |
||
19 | |||
20 | /** @var bool */ |
||
21 | protected bool $isAuthorLoaded = false; |
||
22 | |||
23 | /** |
||
24 | * @param mixed $authorId |
||
25 | * @param string $title |
||
26 | * @param string|null $summary |
||
27 | * @return Book |
||
28 | */ |
||
29 | 6 | public static function create($authorId, string $title, string $summary = null): Book |
|
30 | { |
||
31 | 6 | $book = new static(); |
|
32 | |||
33 | 6 | $book->authorId = $authorId; |
|
34 | 6 | $book->title = $title; |
|
35 | 6 | $book->summary = $summary; |
|
36 | |||
37 | 6 | return $book; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param array $data |
||
42 | * @return Book |
||
43 | */ |
||
44 | 1 | public function fill(array $data): Book |
|
45 | { |
||
46 | 1 | if (isset($data['title'])) { |
|
47 | 1 | $this->title = (string)$data['title']; |
|
48 | } |
||
49 | 1 | if (isset($data['summary'])) { |
|
50 | 1 | $this->summary = (string)$data['summary']; |
|
51 | } |
||
52 | 1 | if (isset($data['authorId'])) { |
|
53 | 1 | $this->authorId = $data['authorId']; |
|
54 | } |
||
55 | 1 | return $this; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | 4 | public function isAuthorLoaded(): bool |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param Author $author |
||
68 | * @return Book |
||
69 | */ |
||
70 | 2 | public function setAuthor(Author $author): Book |
|
75 | } |
||
76 | } |
||
77 |