Passed
Push — master ( e9611b...a3681d )
by f
13:07
created

Lzma::getSupportedFormats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
namespace wapmorgan\UnifiedArchive\Drivers\OneFile;
3
4
use wapmorgan\UnifiedArchive\Drivers\BasicDriver;
5
use wapmorgan\UnifiedArchive\Formats;
6
use wapmorgan\UnifiedArchive\Drivers\OneFile\OneFileDriver;
7
8
/**
9
 * Class Lzma
10
 *
11
 * @package wapmorgan\UnifiedArchive\Formats
12
 * @requires ext-lzma2
13
 */
14
class Lzma extends OneFileDriver
15
{
16
    const FORMAT_SUFFIX =  'xz';
17
    const PHP_EXTENSION = 'xz';
18
    const FORMAT = Formats::LZMA;
19
20 1
    /**
21
     * @inheritDoc
22
     */
23 1
    public static function getDescription()
24
    {
25
        return 'adapter for ext-xz';
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public static function getInstallationInstruction()
32
    {
33
        return 'install [xz] extension' . "\n" . 'For 5.x: https://github.com/payden/php-xz' . "\n" . 'For 7.x: https://github.com/codemasher/php-ext-xz';
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function __construct($archiveFileName, $format, $password = null)
40
    {
41
        parent::__construct($archiveFileName, $password);
42
        $this->modificationTime = filemtime($this->fileName);
43
    }
44
45
    /**
46
     * @param string $fileName
47
     *
48
     * @return string|false
49
     */
50
    public function getFileContent($fileName = null)
51
    {
52
        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

52
        return stream_get_contents(/** @scrutinizer ignore-call */ xzopen($this->fileName, 'r'));
Loading history...
53
    }
54
55
    /**
56
     * @param string $fileName
57
     *
58
     * @return bool|resource|string
59
     */
60
    public function getFileStream($fileName = null)
61
    {
62
        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

62
        return /** @scrutinizer ignore-call */ xzopen($this->fileName, 'r');
Loading history...
63
    }
64
65
    /**
66
     * @param $data
67
     * @param $compressionLevel
68
     * @return mixed|string
69
     */
70
    protected static function compressData($data, $compressionLevel)
71
    {
72
        $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

72
        $fp = /** @scrutinizer ignore-call */ xzopen('php://temp', 'w');
Loading history...
73
        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

73
        /** @scrutinizer ignore-call */ 
74
        xzwrite($fp, $data);
Loading history...
74
        $data = stream_get_contents($fp);
75
        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

75
        /** @scrutinizer ignore-call */ 
76
        xzclose($fp);
Loading history...
76
        return $data;
77
    }
78
}