Completed
Push — id3-metadata-objects ( 161f4c...a3a88a )
by Daniel
03:11
created

Tag::getYear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 1
nc 1
nop 0
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
13
/**
14
 * ID3v2 tag
15
 *
16
 * @package GravityMedia\Metadata\ID3v2
17
 */
18
class Tag implements TagInterface
19
{
20
    /**
21
     * @var HeaderInterface
22
     */
23
    protected $header;
24
25
    /**
26
     * @var ExtendedHeader
27
     */
28
    protected $extendedHeader;
29
30
    /**
31
     * @var FrameInterface[]
32
     */
33
    protected $frames;
34
35
    /**
36
     * Create tag object.
37
     *
38
     * @param HeaderInterface $header
39
     */
40
    public function __construct(HeaderInterface $header)
41
    {
42
        $this->header = $header;
43
        $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...\ID3v2\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...
44
    }
45
46
    /**
47
     * Get header
48
     *
49
     * @return HeaderInterface
50
     */
51
    public function getHeader()
52
    {
53
        return $this->header;
54
    }
55
56
    /**
57
     * Get extended header
58
     *
59
     * @return ExtendedHeader
60
     */
61
    public function getExtendedHeader()
62
    {
63
        return $this->extendedHeader;
64
    }
65
66
    /**
67
     * Set extended header
68
     *
69
     * @param ExtendedHeaderInterface $extendedHeader
70
     *
71
     * @throws BadMethodCallException An exception is thrown on ID3 v2.2 tag
72
     *
73
     * @return $this
74
     */
75
    public function setExtendedHeader(ExtendedHeaderInterface $extendedHeader)
76
    {
77
        if (!in_array($this->getVersion(), [Version::VERSION_23, Version::VERSION_24])) {
78
            throw new BadMethodCallException('Extended header is not supported in this version.');
79
        }
80
81
        $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...
82
83
        return $this;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function getVersion()
90
    {
91
        return $this->header->getVersion();
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function getFrames()
98
    {
99
        return $this->frames;
100
    }
101
102
    /**
103
     * Add frame
104
     *
105
     * @param FrameInterface $frame
106
     *
107
     * @return $this
108
     */
109
    public function addFrame(FrameInterface $frame)
110
    {
111
        $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...\ID3v2\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...
112
        return $this;
113
    }
114
}
115