Completed
Pull Request — develop (#27)
by Chris
01:48
created

Inf   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromString() 0 6 1
A getDuration() 0 4 1
A getTitle() 0 4 1
A __toString() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of the PhpM3u8 package.
5
 *
6
 * (c) Chrisyue <https://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\Value\Tag;
13
14
class Inf
15
{
16
    private $duration;
17
18
    private $title;
19
20
    private $version;
21
22
    public function __construct($duration, string $title = null, $version = 6)
23
    {
24
        $this->duration = +$duration;
25
        $this->title = $title;
26
        $this->version = $version;
27
    }
28
29
    public static function fromString(string $string)
30
    {
31
        [$duration, $title] = explode(',', $string);
0 ignored issues
show
Bug introduced by
The variable $duration does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $title does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
32
33
        return new self($duration, $title);
34
    }
35
36
    public function getDuration()
37
    {
38
        return $this->duration;
39
    }
40
41
    public function getTitle()
42
    {
43
        return $this->title;
44
    }
45
46
    public function __toString()
47
    {
48
        /*
49
         * @see https://tools.ietf.org/html/rfc8216#section-4.3.2.1
50
         */
51
        if ($this->version < 3) {
52
            return sprintf('%d,%s', round($this->duration), $this->title);
53
        }
54
55
        return sprintf('%.3f,%s', $this->duration, $this->title);
56
    }
57
}
58