Books::isbn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TPG\Pcflib\Categories;
4
5
class Books extends Category
6
{
7
    const FORMAT_HARDCOVER = 'Hardcover';
8
    const FORMAT_SOFTCOVER = 'Soft Cover';
9
    const FORMAT_AUDIO = 'Audio';
10
    const FORMAT_EBOOK = 'eBook';
11
12
    protected $requiredAttributes = [
13
        'Format',
14
        'ISBN'
15
    ];
16
17
18
    public function format(string $format)
19
    {
20
        $this->attributes['Format'] = $format;
21
        return $this;
22
    }
23
24
    public function isbn(string $isbn)
25
    {
26
        $this->attributes['ISBN'] = $isbn;
27
        return $this;
28
    }
29
30
    public function author(string ...$authors)
31
    {
32
        $this->attributes['Author'] = $authors;
33
        return $this;
34
    }
35
36
    public function edition(int $edition)
37
    {
38
        $this->attributes['Edition'] = $edition;
39
        return $this;
40
    }
41
42
    public function genre(string $genre)
43
    {
44
        $this->attributes['Genre'] = $genre;
45
        return $this;
46
    }
47
48
    public function pages(int $pages)
49
    {
50
        $this->attributes['Pages'] = $pages;
51
        return $this;
52
    }
53
54
    public function publicationDate($year, int $month = null, int $day = null)
55
    {
56
        $date = $year;
57
58
        if (get_class($year) !== \DateTime::class && !is_subclass_of($year, \DateTime::class)) {
59
60
            $date = new \DateTime(implode('-', [$year, $month, $day]));
61
        }
62
63
        $this->attributes['PublicationDate'] = $date->format('Y-m-d');
64
        return $this;
65
    }
66
67
    public function publisher(string $publisher)
68
    {
69
        $this->attributes['Publisher'] = $publisher;
70
        return $this;
71
    }
72
73
    protected function getAuthorString()
74
    {
75
        return implode(',', $this->attributes['Author']);
76
    }
77
78
    public function toArray(): array
79
    {
80
        return array_merge(parent::toArray(), [
81
            'Author' => $this->getAuthorString(),
82
        ]);
83
    }
84
}