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

UriAwareAttrTagParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A parse() 0 8 1
A supports() 0 4 1
A isRepeatable() 0 4 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Parser;
4
5
use Chrisyue\PhpM3u8\Line\LinesInterface;
6
use Chrisyue\PhpM3u8\Line\LineInterface;
7
use Chrisyue\PhpM3u8\Transformer\AttrListTransformer;
8
9
class UriAwareAttrTagParser extends TagParser
10
{
11
    private $uriParser;
12
13
    private $dataAccessor;
14
15
    public function __construct(
16
        LineInterface $line,
17
        AttrListTransformer $transformer = null,
18
        ChildParserInterface $uriParser,
19
        $repeatable = false
20
    ) {
21
        parent::__construct($line, $transformer, $repeatable);
22
23
        $this->uriParser = $uriParser;
24
        $this->dataAccessor = $transformer->getDataAccessor();
0 ignored issues
show
Bug introduced by
It seems like $transformer is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
25
    }
26
27
    public function parse(LinesInterface $lines)
28
    {
29
        parent::parse($lines);
30
        $lines->goNext();
31
        $this->dataAccessor->set('uri', $this->uriParser->parse($lines));
32
33
        return $this->dataAccessor->getData();
34
    }
35
36
    public function supports(LineInterface $line)
37
    {
38
        return parent::supports($line);
39
    }
40
41
    public function isRepeatable()
42
    {
43
        return true;
44
    }
45
}
46