Passed
Push — main ( 0ace76...960e41 )
by Daniel
04:09
created

Album::getYear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Orm\Model;
6
7
use DateTimeInterface;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\DBAL\Types\Types;
10
use Doctrine\ORM\Mapping as ORM;
11
use Uxmp\Core\Orm\Repository\AlbumRepository;
12
13
#[ORM\Table(name: 'album')]
14
#[ORM\Entity(repositoryClass: AlbumRepository::class)]
15
class Album implements AlbumInterface
16
{
17
    #[ORM\Column(type: Types::INTEGER)]
18
    #[ORM\Id, ORM\GeneratedValue(strategy: 'AUTO')]
19
    private int $id;
20
21
    #[ORM\Column(type: Types::STRING, nullable: true)]
22
    private ?string $title = null;
23
24
    #[ORM\Column(type: Types::STRING, nullable: true)]
25
    private ?string $searchTitle = '';
26
27
    #[ORM\Column(type: Types::INTEGER)]
28
    private int $artist_id;
0 ignored issues
show
introduced by
The private property $artist_id is not used, and could be removed.
Loading history...
29
30
    #[ORM\Column(type: Types::INTEGER)]
31
    private int $catalog_id;
0 ignored issues
show
introduced by
The private property $catalog_id is not used, and could be removed.
Loading history...
32
33
    #[ORM\Column(type: Types::DATETIME_MUTABLE)]
34
    private DateTimeInterface $last_modified;
35
36
    #[ORM\Column(type: Types::STRING, length: 36, unique: true, nullable: true)]
37
    private ?string $mbid = null;
38
39
    #[ORM\Column(type: Types::INTEGER, nullable: true)]
40
    private ?int $year = null;
41
42
    #[ORM\ManyToOne(targetEntity: ArtistInterface::class, inversedBy: 'albums')]
43
    #[ORM\JoinColumn(name: 'artist_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
44
    private ArtistInterface $artist;
45
46
    #[ORM\ManyToOne(targetEntity: CatalogInterface::class)]
47
    #[ORM\JoinColumn(name: 'catalog_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
48
    private CatalogInterface $catalog;
49
50
    /** @var ArrayCollection<int, DiscInterface> */
51
    #[ORM\OneToMany(mappedBy: 'album', targetEntity: DiscInterface::class, cascade: ['ALL'], indexBy: 'id')]
52
    #[ORM\OrderBy(['number' => 'ASC'])]
53
    private iterable $discs;
54
55 15
    public function __construct()
56
    {
57 15
        $this->discs = new ArrayCollection();
58
    }
59
60
    public function getId(): int
61
    {
62
        return $this->id;
63
    }
64
65 1
    public function getTitle(): ?string
66
    {
67 1
        return $this->title;
68
    }
69
70 1
    public function setTitle(?string $title): AlbumInterface
71
    {
72 1
        $this->title = $title;
73 1
        return $this;
74
    }
75
76 1
    public function getSearchTitle(): string
77
    {
78 1
        return (string) $this->searchTitle;
79
    }
80
81 1
    public function setSearchTitle(string $searchTitle): AlbumInterface
82
    {
83 1
        $this->searchTitle = $searchTitle;
84 1
        return $this;
85
    }
86
87 1
    public function getArtist(): ArtistInterface
88
    {
89 1
        return $this->artist;
90
    }
91
92 1
    public function setArtist(ArtistInterface $artist): AlbumInterface
93
    {
94 1
        $this->artist = $artist;
95 1
        return $this;
96
    }
97
98 2
    public function getMbid(): ?string
99
    {
100 2
        return $this->mbid;
101
    }
102
103 2
    public function setMbid(?string $mbid): AlbumInterface
104
    {
105 2
        $this->mbid = $mbid;
106 2
        return $this;
107
    }
108
109 1
    public function getDiscs(): iterable
110
    {
111 1
        return $this->discs;
112
    }
113
114 1
    public function getDiscCount(): int
115
    {
116 1
        return $this->discs->count();
117
    }
118
119 2
    public function addDisc(DiscInterface $disc): AlbumInterface
120
    {
121 2
        $this->discs->add($disc);
122 2
        return $this;
123
    }
124
125 1
    public function getCatalog(): CatalogInterface
126
    {
127 1
        return $this->catalog;
128
    }
129
130 1
    public function setCatalog(CatalogInterface $catalog): AlbumInterface
131
    {
132 1
        $this->catalog = $catalog;
133 1
        return $this;
134
    }
135
136 1
    public function getLength(): int
137
    {
138 1
        return array_sum(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_sum(array_m...his->discs->toArray())) could return the type double which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
139 1
            array_map(
140 1
                static fn (DiscInterface $disc): int => $disc->getLength(),
141 1
                $this->discs->toArray()
142 1
            )
143 1
        );
144
    }
145
146 1
    public function getSongCount(): int
147
    {
148 1
        return array_sum(
0 ignored issues
show
Bug Best Practice introduced by
The expression return array_sum(array_m...his->discs->toArray())) could return the type double which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
149 1
            array_map(
150 1
                static fn (DiscInterface $disc): int => $disc->getSongCount(),
151 1
                $this->discs->toArray()
152 1
            )
153 1
        );
154
    }
155
156 1
    public function getLastModified(): DateTimeInterface
157
    {
158 1
        return $this->last_modified;
159
    }
160
161 1
    public function setLastModified(DateTimeInterface $last_modified): AlbumInterface
162
    {
163 1
        $this->last_modified = $last_modified;
164 1
        return $this;
165
    }
166
167 1
    public function getYear(): ?int
168
    {
169 1
        return $this->year;
170
    }
171
172 1
    public function setYear(?int $year): AlbumInterface
173
    {
174 1
        $this->year = $year;
175 1
        return $this;
176
    }
177
178 1
    public function getArtItemType(): string
179
    {
180 1
        return 'album';
181
    }
182
183 1
    public function getArtItemId(): ?string
184
    {
185 1
        return $this->getMbid();
186
    }
187
188 1
    public function getType(): FavoriteItemTypeEnum
189
    {
190 1
        return FavoriteItemTypeEnum::ALBUM;
191
    }
192
}
193