Passed
Push — main ( 81c4dd...0f62ea )
by Daniel
03:56
created

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