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

Byterange   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromString() 0 6 1
A getLength() 0 4 1
A getOffset() 0 4 1
A __toString() 0 8 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 Byterange
15
{
16
    private $length;
17
18
    private $offset;
19
20
    public function __construct(int $length, string $offset = null)
21
    {
22
        $this->length = $length;
23
        $this->offset = $offset;
24
    }
25
26
    public static function fromString(string $string)
27
    {
28
        [$length, $offset] = array_pad(explode('@', $string), 2, null);
0 ignored issues
show
Bug introduced by
The variable $length 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 $offset 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...
29
30
        return new self($length, $offset);
31
    }
32
33
    public function getLength()
34
    {
35
        return $this->length;
36
    }
37
38
    public function getOffset()
39
    {
40
        return $this->offset;
41
    }
42
43
    public function __toString()
44
    {
45
        if (null === $this->offset) {
46
            return (string) $this->length;
47
        }
48
49
        return sprintf('%d@%d', $this->length, $this->offset);
50
    }
51
}
52