Completed
Push — master ( 9bc3b7...a15851 )
by Harry
02:46
created

LocalFile::getEncoding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Graze\DataFile\Node;
4
5
use Graze\DataFile\Modify\Compress\CompressionFactory;
6
use Graze\DataFile\Modify\Compress\CompressionType;
7
use League\Flysystem\Adapter\Local;
8
use League\Flysystem\Filesystem;
9
10
class LocalFile extends FileNode implements LocalFileNodeInterface
11
{
12
    /**
13
     * @var string - CompressionType::
14
     */
15
    protected $compression;
16
17
    /**
18
     * @var string|null
19
     */
20
    protected $encoding;
21
22
    /**
23
     * @param string $path
24
     */
25 106
    public function __construct($path)
26
    {
27 106
        parent::__construct(new FileSystem(new Local('/')), $path);
28
29 106
        $this->compression = CompressionType::NONE;
30 106
        $this->encoding = null;
31 106
    }
32
33
    /**
34
     * @return string
35
     */
36 13
    public function getEncoding()
37
    {
38 13
        return $this->encoding;
39
    }
40
41
    /**
42
     * @param string $encoding
43
     *
44
     * @return $this
45
     */
46 14
    public function setEncoding($encoding)
47
    {
48 14
        $this->encoding = $encoding;
49
50 14
        return $this;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 20
    public function getContents()
57
    {
58 20
        if ($this->exists() &&
59 20
            $this->getCompression() != CompressionType::NONE
60
        ) {
61 2
            $factory = new CompressionFactory();
62 2
            $compressor = $factory->getDeCompressor($this->getCompression());
63 2
            $uncompressed = $compressor->decompress($this);
64 2
            $content = $uncompressed->getContents();
65 2
            $uncompressed->delete();
66 2
            return $content;
67
        } else {
68 20
            return parent::getContents();
69
        }
70
    }
71
72
    /**
73
     * @return string - see CompressionType::
74
     */
75 30
    public function getCompression()
76
    {
77 30
        return $this->compression;
78
    }
79
80
    /**
81
     * @param string $compression - @see CompressionType::
82
     *
83
     * @return $this
84
     */
85 21
    public function setCompression($compression)
86
    {
87 21
        $this->compression = $compression;
88
89 21
        return $this;
90
    }
91
}
92