Passed
Push — main ( c61767...b346c5 )
by Daniel
03:42
created

Album::getDiscCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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