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

PlaylistFacade   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 40.68 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 8
dl 24
loc 59
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parse() 0 6 1
A dump() 12 12 1
A parseFromFile() 0 6 1
A dumpToFile() 12 12 1
A checkPlaylist() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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