Completed
Push — master ( 6695d4...9bc3b7 )
by Harry
04:41
created

LocalFile::setEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Graze\DataFile\Node;
4
5
use Graze\DataFile\Modify\Compress\CompressionType;
6
use League\Flysystem\Adapter\Local;
7
use League\Flysystem\Filesystem;
8
9
class LocalFile extends FileNode implements LocalFileNodeInterface
10
{
11
    /**
12
     * @var string - CompressionType::
13
     */
14
    protected $compression;
15
16
    /**
17
     * @var string|null
18
     */
19
    protected $encoding;
20
21
    /**
22
     * @param string $path
23
     */
24 89
    public function __construct($path)
25
    {
26 89
        parent::__construct(new FileSystem(new Local('/')), $path);
27
28 89
        $this->compression = CompressionType::NONE;
29 89
        $this->encoding = null;
30 89
    }
31
32
    /**
33
     * @return string
34
     */
35 10
    public function getEncoding()
36
    {
37 10
        return $this->encoding;
38
    }
39
40
    /**
41
     * @param string $encoding
42
     *
43
     * @return $this
44
     */
45 10
    public function setEncoding($encoding)
46
    {
47 10
        $this->encoding = $encoding;
48
49 10
        return $this;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 16
    public function getContents()
56
    {
57 16
        if ($this->exists() &&
58 16
            $this->getCompression() != CompressionType::NONE
59
        ) {
60
            $uncompressed = $this->decompress();
0 ignored issues
show
Documentation Bug introduced by
The method decompress does not exist on object<Graze\DataFile\Node\LocalFile>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
61
            $content = $uncompressed->getContents();
62
            $uncompressed->delete();
63
            return $content;
64
        } else {
65 16
            return parent::getContents();
66
        }
67
    }
68
69
    /**
70
     * @return string - see CompressionType::
71
     */
72 25
    public function getCompression()
73
    {
74 25
        return $this->compression;
75
    }
76
77
    /**
78
     * @param string $compression - @see CompressionType::
79
     *
80
     * @return $this
81
     */
82 16
    public function setCompression($compression)
83
    {
84 16
        $this->compression = $compression;
85
86 16
        return $this;
87
    }
88
}
89