Passed
Push — 1.1.x ( 3d3019...6d4a67 )
by f
02:55 queued 01:04
created

Lzma::getSupportedFormats()   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 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace wapmorgan\UnifiedArchive\Drivers\OneFile;
3
4
use wapmorgan\UnifiedArchive\Formats;
5
use wapmorgan\UnifiedArchive\Drivers\OneFile\OneFileDriver;
6
7
/**
8
 * Class Lzma
9
 *
10
 * @package wapmorgan\UnifiedArchive\Formats
11
 * @requires ext-lzma2
12
 */
13
class Lzma extends OneFileDriver
14
{
15
    const FORMAT_SUFFIX =  'xz';
16
17
    /**
18
     * @return array
19
     */
20 1
    public static function getSupportedFormats()
21
    {
22
        return [
23 1
            Formats::LZMA,
24
        ];
25
    }
26
27
    /**
28
     * @param $format
29
     * @return bool
30
     */
31
    public static function checkFormatSupport($format)
32
    {
33
        switch ($format) {
34
            case Formats::LZMA:
35
                return extension_loaded('xz');
36
        }
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public static function getDescription()
43
    {
44
        return 'adapter for ext-xz';
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public static function getInstallationInstruction()
51
    {
52
        return !extension_loaded('xz')
53
            ? 'install `xz` extension'
54
            : null;
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function __construct($archiveFileName, $format, $password = null)
61
    {
62
        parent::__construct($archiveFileName, $password);
63
        $this->modificationTime = filemtime($this->fileName);
64
    }
65
66
    /**
67
     * @param string $fileName
68
     *
69
     * @return string|false
70
     */
71
    public function getFileContent($fileName = null)
72
    {
73
        return stream_get_contents(xzopen($this->fileName, 'r'));
0 ignored issues
show
Bug introduced by
The function xzopen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        return stream_get_contents(/** @scrutinizer ignore-call */ xzopen($this->fileName, 'r'));
Loading history...
74
    }
75
76
    /**
77
     * @param string $fileName
78
     *
79
     * @return bool|resource|string
80
     */
81
    public function getFileStream($fileName = null)
82
    {
83
        return xzopen($this->fileName, 'r');
0 ignored issues
show
Bug introduced by
The function xzopen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        return /** @scrutinizer ignore-call */ xzopen($this->fileName, 'r');
Loading history...
84
    }
85
86
    /**
87
     * @param $data
88
     * @param $compressionLevel
89
     * @return mixed|string
90
     */
91
    protected static function compressData($data, $compressionLevel)
92
    {
93
        $fp = xzopen('php://temp', 'w');
0 ignored issues
show
Bug introduced by
The function xzopen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
        $fp = /** @scrutinizer ignore-call */ xzopen('php://temp', 'w');
Loading history...
94
        xzwrite($fp, $data);
0 ignored issues
show
Bug introduced by
The function xzwrite was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        /** @scrutinizer ignore-call */ 
95
        xzwrite($fp, $data);
Loading history...
95
        $data = stream_get_contents($fp);
96
        xzclose($fp);
0 ignored issues
show
Bug introduced by
The function xzclose was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
        /** @scrutinizer ignore-call */ 
97
        xzclose($fp);
Loading history...
97
        return $data;
98
    }
99
}