Book   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 68
ccs 20
cts 20
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAuthorLoaded() 0 3 1
A setAuthor() 0 5 1
A create() 0 9 1
A fill() 0 12 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LibraryCatalog\Entity;
6
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
62
    {
63 4
        return $this->isAuthorLoaded;
64
    }
65
66
    /**
67
     * @param Author $author
68
     * @return Book
69
     */
70 2
    public function setAuthor(Author $author): Book
71
    {
72 2
        $this->author = $author;
73 2
        $this->isAuthorLoaded = true;
74 2
        return $this;
75
    }
76
}
77