ProgramDateTimeTag::dump()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0
crap 3.0261
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <http://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Chrisyue\PhpM3u8\Tag;
13
14
class ProgramDateTimeTag extends AbstractTag
15
{
16
    use SingleValueTagTrait;
17
18
    const TAG_IDENTIFIER = '#EXT-X-PROGRAM-DATE-TIME';
19
20
    /**
21
     * @var string Absolute date and/or time of the first sample of the Media Segment in ISO_8601 format
22
     */
23
    private $programDateTime;
24
25
    /**
26
     * @param \DateTime $programDateTime
27
     *
28
     * @return self
29
     */
30 1
    public function setProgramDateTime(\DateTime $programDateTime)
31
    {
32 1
        $this->programDateTime = $programDateTime;
0 ignored issues
show
Documentation Bug introduced by
It seems like $programDateTime of type object<DateTime> is incompatible with the declared type string of property $programDateTime.

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...
33
34 1
        return $this;
35
    }
36
37
    /**
38
     * @return \DateTime
39
     */
40 1
    public function getProgramDateTime()
41
    {
42 1
        return $this->programDateTime;
43
    }
44
45
    /**
46
     * @return string
47
     */
48 1
    public function dump()
49
    {
50 1
        if (null === $this->programDateTime) {
51 1
            return;
52
        }
53
54 1
        if (version_compare(phpversion(), '7.0.0') >= 0) {
55
            return sprintf('%s:%s', self::TAG_IDENTIFIER, $this->programDateTime->format('Y-m-d\TH:i:s.vP'));
0 ignored issues
show
Bug introduced by
The method format cannot be called on $this->programDateTime (of type string).

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...
56
        }
57
58 1
        $dateString = substr($this->programDateTime->format('Y-m-d\TH:i:s.u'), 0, -3);
0 ignored issues
show
Bug introduced by
The method format cannot be called on $this->programDateTime (of type string).

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...
59
60 1
        return sprintf('%s:%s%s', self::TAG_IDENTIFIER, $dateString, $this->programDateTime->format('P'));
0 ignored issues
show
Bug introduced by
The method format cannot be called on $this->programDateTime (of type string).

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...
61
    }
62
63
    /**
64
     * @param string $line
65
     */
66 1
    protected function read($line)
67
    {
68 1
        $this->programDateTime = new \DateTime(self::extractValue($line));
0 ignored issues
show
Documentation Bug introduced by
It seems like new \DateTime(self::extractValue($line)) of type object<DateTime> is incompatible with the declared type string of property $programDateTime.

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...
69 1
    }
70
}
71