Completed
Pull Request — develop (#27)
by Chris
05:29
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
namespace Chrisyue\PhpM3u8\Value\Tag;
4
5
class Byterange
6
{
7
    private $length;
8
9
    private $offset;
10
11
    public function __construct(int $length, string $offset = null)
12
    {
13
        $this->length = $length;
14
        $this->offset = $offset;
15
    }
16
17
    public static function fromString(string $string)
18
    {
19
        [$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...
20
21
        return new self($length, $offset);
22
    }
23
24
    public function getLength()
25
    {
26
        return $this->length;
27
    }
28
29
    public function getOffset()
30
    {
31
        return $this->offset;
32
    }
33
34
    public function __toString()
35
    {
36
        if (null === $this->offset) {
37
            return (string) $this->length;
38
        }
39
40
        return sprintf('%d@%d', $this->length, $this->offset);
41
    }
42
}
43