Passed
Push — main ( 430e79...a41548 )
by Daniel
14:15
created

Album::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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