Completed
Pull Request — develop (#27)
by Chris
13:09
created

Inf::fromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Model\Tag;
4
5
use Chrisyue\PhpM3u8\Model\Context;
6
7
class Inf implements FormattedTagInterface
8
{
9
    /**
10
     * @var int|float
11
     */
12
    private $duration;
13
14
    /**
15
     * @var string
16
     */
17
    private $title;
18
19
    static public function fromString($string)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
20
    {
21
        $self = new self();
22
        list($self->duration, $self->title) = explode(',', $string);
23
24
        return $self;
25
    }
26
27
    /**
28
     * @param int|float $duration
29
     *
30
     * @return self
31
     */
32
    public function setDuration($duration)
33
    {
34
        $this->duration = $duration;
35
36
        return $this;
37
    }
38
39
    /**
40
     * @return int|float
41
     */
42
    public function getDuration()
43
    {
44
        return $this->duration;
45
    }
46
47
    /**
48
     * @param string $title
49
     *
50
     * @return self
51
     */
52
    public function setTitle($title)
53
    {
54
        $this->title = $title;
55
56
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getTitle()
63
    {
64
        return $this->title;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function __toString()
71
    {
72
        if (Context::$params['version'] > 2) {
73
            return sprintf('%.3f,%s', $this->duration, $this->title);
74
        }
75
76
        return sprintf('%d,%s', $this->duration, $this->title);
77
    }
78
}
79