Passed
Push — main ( 199c59...bc8763 )
by Daniel
10:26
created

Album::getLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 5
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;
37
38
    /**
39
     * @Column(type="string", length="32", nullable="true", unique=true)
40
     */
41
    private ?string $mbid = null;
42
43
    /**
44
     * @ManyToOne(targetEntity="Artist", inversedBy="albums")
45
     * @JoinColumn(name="artist_id", referencedColumnName="id", onDelete="CASCADE")
46
     */
47
    private ArtistInterface $artist;
48
49
    /**
50
     * @ManyToOne(targetEntity="Catalog")
51
     * @JoinColumn(name="catalog_id", referencedColumnName="id", onDelete="CASCADE")
52
     */
53
    private CatalogInterface $catalog;
54
55
    /**
56
     * @OneToMany(targetEntity="Disc", mappedBy="album", cascade={"ALL"}, indexBy="id")
57
     *
58
     * @var ArrayCollection<int, DiscInterface>
59
     */
60
    private iterable $discs;
61
62 1
    #[Pure]
63
    public function __construct()
64
    {
65 1
        $this->discs = new ArrayCollection();
66 1
    }
67
68
    public function getId(): int
69
    {
70
        return $this->id;
71
    }
72
73
    public function getTitle(): ?string
74
    {
75
        return $this->title;
76
    }
77
78
    public function setTitle(?string $title): AlbumInterface
79
    {
80
        $this->title = $title;
81
        return $this;
82
    }
83
84
    public function getArtist(): ArtistInterface
85
    {
86
        return $this->artist;
87
    }
88
89
    public function setArtist(ArtistInterface $artist): AlbumInterface
90
    {
91
        $this->artist = $artist;
92
        return $this;
93
    }
94
95
    public function getMbid(): ?string
96
    {
97
        return $this->mbid;
98
    }
99
100
    public function setMbid(?string $mbid): AlbumInterface
101
    {
102
        $this->mbid = $mbid;
103
        return $this;
104
    }
105
106
    public function getDiscs(): iterable
107
    {
108
        return $this->discs;
109
    }
110
111
    public function getDiscCount(): int
112
    {
113
        return $this->discs->count();
114
    }
115
116
    public function getCatalog(): CatalogInterface
117
    {
118
        return $this->catalog;
119
    }
120
121
    public function setCatalog(CatalogInterface $catalog): AlbumInterface
122
    {
123
        $this->catalog = $catalog;
124
        return $this;
125
    }
126
127
    public function getLength(): int
128
    {
129
        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...
130
            array_map(
131
                fn (DiscInterface $disc): int => $disc->getLength(),
132
                $this->discs->toArray()
133
            )
134
        );
135
    }
136
}
137