Lzma   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 11.76%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 58
rs 10
ccs 2
cts 17
cp 0.1176
wmc 7

6 Methods

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

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

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

71
        return /** @scrutinizer ignore-call */ xzencode($data);
Loading history...
72
    }
73
}
74