Passed
Push — main ( 6f91e7...b3043b )
by Daniel
04:24
created

Album::getSongCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
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\ManyToOne(targetEntity: Artist::class, inversedBy: 'albums')]
38
    #[ORM\JoinColumn(name: 'artist_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
39
    private ArtistInterface $artist;
40
41
    #[ORM\ManyToOne(targetEntity: Catalog::class)]
42
    #[ORM\JoinColumn(name: 'catalog_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
43
    private CatalogInterface $catalog;
44
45
    /**
46
     * @var ArrayCollection<int, DiscInterface>
47
     */
48
    #[ORM\OneToMany(mappedBy: 'album', targetEntity: Disc::class, cascade: ['ALL'], indexBy: 'id')]
49
    #[ORM\OrderBy(['number' => 'ASC'])]
50
    private iterable $discs;
51
52 13
    #[Pure]
53
    public function __construct()
54
    {
55 13
        $this->discs = new ArrayCollection();
56
    }
57
58
    public function getId(): int
59
    {
60
        return $this->id;
61
    }
62
63 1
    public function getTitle(): ?string
64
    {
65 1
        return $this->title;
66
    }
67
68 1
    public function setTitle(?string $title): AlbumInterface
69
    {
70 1
        $this->title = $title;
71 1
        return $this;
72
    }
73
74 1
    public function getArtist(): ArtistInterface
75
    {
76 1
        return $this->artist;
77
    }
78
79 1
    public function setArtist(ArtistInterface $artist): AlbumInterface
80
    {
81 1
        $this->artist = $artist;
82 1
        return $this;
83
    }
84
85 2
    public function getMbid(): ?string
86
    {
87 2
        return $this->mbid;
88
    }
89
90 2
    public function setMbid(?string $mbid): AlbumInterface
91
    {
92 2
        $this->mbid = $mbid;
93 2
        return $this;
94
    }
95
96 1
    public function getDiscs(): iterable
97
    {
98 1
        return $this->discs;
99
    }
100
101 1
    public function getDiscCount(): int
102
    {
103 1
        return $this->discs->count();
104
    }
105
106 2
    public function addDisc(DiscInterface $disc): AlbumInterface
107
    {
108 2
        $this->discs->add($disc);
109 2
        return $this;
110
    }
111
112 1
    public function getCatalog(): CatalogInterface
113
    {
114 1
        return $this->catalog;
115
    }
116
117 1
    public function setCatalog(CatalogInterface $catalog): AlbumInterface
118
    {
119 1
        $this->catalog = $catalog;
120 1
        return $this;
121
    }
122
123 1
    public function getLength(): int
124
    {
125 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...
126 1
            array_map(
127 1
                fn (DiscInterface $disc): int => $disc->getLength(),
128 1
                $this->discs->toArray()
129
            )
130
        );
131
    }
132
133 1
    public function getSongCount(): int
134
    {
135 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...
136 1
            array_map(
137 1
                fn (DiscInterface $disc): int => $disc->getSongCount(),
138 1
                $this->discs->toArray()
139
            )
140
        );
141
    }
142
143 1
    public function getLastModified(): DateTimeInterface
144
    {
145 1
        return $this->last_modified;
146
    }
147
148 1
    public function setLastModified(DateTimeInterface $last_modified): AlbumInterface
149
    {
150 1
        $this->last_modified = $last_modified;
151 1
        return $this;
152
    }
153
154 2
    #[Pure]
155
    public function getArtItemType(): string
156
    {
157 2
        return 'album';
158
    }
159
160 1
    #[Pure]
161
    public function getArtItemId(): ?string
162
    {
163 1
        return $this->getMbid();
164
    }
165
166 1
    public function getType(): string
167
    {
168 1
        return $this->getArtItemType();
169
    }
170
}
171