Completed
Pull Request — develop (#27)
by Chris
05:17
created

PlaylistFacade::dump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\M3u8;
4
5
use Chrisyue\PhpM3u8\M3u8\Builder\ObjectBuilder;
6
use Chrisyue\PhpM3u8\M3u8\Core\Playlist;
7
use Chrisyue\PhpM3u8\M3u8\Lines\Lines;
8
use Chrisyue\PhpM3u8\M3u8\PropertyReader\Reader;
9
use Chrisyue\PhpM3u8\M3u8\Transformer\TagInfo;
10
use Chrisyue\PhpM3u8\Stream\FileStream;
11
use Chrisyue\PhpM3u8\Stream\TextStream;
12
13
class PlaylistFacade
14
{
15
    private $core;
16
17
    public function __construct($class)
18
    {
19
        $this->core = new Playlist();
20
        $this->core->class = $class;
21
        $this->core->reader = new Reader();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Chrisyue\PhpM3u8\M3u8\PropertyReader\Reader() of type object<Chrisyue\PhpM3u8\...\PropertyReader\Reader> is incompatible with the declared type object<Chrisyue\PhpM3u8\...ropertyReaderInterface> of property $reader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
        $this->core->builder = new ObjectBuilder();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Chrisyue\PhpM3u8\M3u8\Builder\ObjectBuilder() of type object<Chrisyue\PhpM3u8\...\Builder\ObjectBuilder> is incompatible with the declared type object<Chrisyue\PhpM3u8\...ilder\BuilderInterface> of property $builder.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    public function parse($text)
26
    {
27
        $lines = new Lines(new TextStream($text), new TagInfo());
28
29
        return $this->core->setLines($lines)->parse();
30
    }
31
32 View Code Duplication
    public function dump($playlist)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $this->checkPlaylist($playlist);
35
36
        $text = new TextStream();
37
        $lines = new Lines($text, new TagInfo());
38
39
        $this->core->setLines($lines);
40
        $this->core->dump($playlist);
41
42
        return $text;
43
    }
44
45
    public function parseFromFile($path)
46
    {
47
        $lines = new Lines(new FileStream(new \SplFileObject($path)), new TagInfo());
48
49
        return $this->core->setLines($lines)->parse();
50
    }
51
52 View Code Duplication
    public function dumpToFile($playlist, $path)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->checkPlaylist($playlist);
55
56
        $file = new \SplFileObject($path);
57
        $lines = new Lines(new FileStream($file), new TagInfo());
58
59
        $this->core->setLines($lines);
60
        $this->core->dump($playlist);
61
62
        return $file;
63
    }
64
65
    private function checkPlaylist($playlist)
66
    {
67
        if (!$playlist instanceof $this->core->class) {
68
            throw new \InvalidArgumentException('Only playlist of class `%s` is supported, `%s` is given', $this->core->class, get_class($playlist));
69
        }
70
    }
71
}
72