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

Inf   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 72
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 7 1
A setDuration() 0 6 1
A getDuration() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A __toString() 0 8 2
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