Completed
Push — id3-metadata-objects ( 3a53b8...e55453 )
by Daniel
14:15
created

Tag::addFrame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the Metadata package.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Metadata\ID3v2;
9
10
use GravityMedia\Metadata\Exception\BadMethodCallException;
11
use GravityMedia\Metadata\ID3v2\Enum\Version;
12
use GravityMedia\Metadata\Metadata\ExtendedHeaderInterface;
13
use GravityMedia\Metadata\Metadata\FrameInterface;
14
use GravityMedia\Metadata\Metadata\HeaderInterface;
15
use GravityMedia\Metadata\Metadata\TagInterface;
16
17
/**
18
 * ID3v2 tag
19
 *
20
 * @package GravityMedia\Metadata\ID3v2
21
 */
22
class Tag implements TagInterface
23
{
24
    /**
25
     * @var HeaderInterface
26
     */
27
    protected $header;
28
29
    /**
30
     * @var ExtendedHeader
31
     */
32
    protected $extendedHeader;
33
34
    /**
35
     * @var FrameInterface[]
36
     */
37
    protected $frames;
38
39
    /**
40
     * Create tag object.
41
     *
42
     * @param HeaderInterface $header
43
     */
44
    public function __construct(HeaderInterface $header)
45
    {
46
        $this->header = $header;
47
        $this->frames = new \ArrayObject();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \ArrayObject() of type object<ArrayObject> is incompatible with the declared type array<integer,object<Gra...tadata\FrameInterface>> of property $frames.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
    }
49
50
    /**
51
     * Get header
52
     *
53
     * @return HeaderInterface
54
     */
55
    public function getHeader()
56
    {
57
        return $this->header;
58
    }
59
60
    /**
61
     * Get extended header
62
     *
63
     * @return ExtendedHeader
64
     */
65
    public function getExtendedHeader()
66
    {
67
        return $this->extendedHeader;
68
    }
69
70
    /**
71
     * Set extended header
72
     *
73
     * @param ExtendedHeaderInterface $extendedHeader
74
     *
75
     * @throws BadMethodCallException An exception is thrown on ID3 v2.2 tag
76
     *
77
     * @return $this
78
     */
79
    public function setExtendedHeader(ExtendedHeaderInterface $extendedHeader)
80
    {
81
        if (!in_array($this->getVersion(), [Version::VERSION_23, Version::VERSION_24])) {
82
            throw new BadMethodCallException('Extended header is not supported in this version.');
83
        }
84
85
        $this->extendedHeader = $extendedHeader;
0 ignored issues
show
Documentation Bug introduced by
$extendedHeader is of type object<GravityMedia\Meta...xtendedHeaderInterface>, but the property $extendedHeader was declared to be of type object<GravityMedia\Meta...a\ID3v2\ExtendedHeader>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
86
87
        return $this;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getVersion()
94
    {
95
        return $this->header->getVersion();
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getTitle()
102
    {
103
        // TODO: Implement getTitle() method.
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function getArtist()
110
    {
111
        // TODO: Implement getArtist() method.
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function getAlbum()
118
    {
119
        // TODO: Implement getAlbum() method.
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function getYear()
126
    {
127
        // TODO: Implement getYear() method.
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    public function getComment()
134
    {
135
        // TODO: Implement getComment() method.
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    public function getTrack()
142
    {
143
        // TODO: Implement getTrack() method.
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    public function getGenre()
150
    {
151
        // TODO: Implement getGenre() method.
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    public function getFrames()
158
    {
159
        return $this->frames;
160
    }
161
162
    /**
163
     * Add frame
164
     *
165
     * @param FrameInterface $frame
166
     *
167
     * @return $this
168
     */
169
    public function addFrame(FrameInterface $frame)
170
    {
171
        $this->frames->append($frame);
0 ignored issues
show
Bug introduced by
The method append cannot be called on $this->frames (of type array<integer,object<Gra...tadata\FrameInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
172
        return $this;
173
    }
174
}
175