Passed
Push — 0.1.x ( 81ff64...72f342 )
by f
01:32
created

Lzma::getFileResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace wapmorgan\UnifiedArchive\Formats;
3
4
/**
5
 * Class Lzma
6
 *
7
 * @package wapmorgan\UnifiedArchive\Formats
8
 * @requires ext-lzma2
9
 */
10
class Lzma extends OneFileFormat
11
{
12
    const FORMAT_SUFFIX =  'xz';
13
14
    /**
15
     * Lzma constructor.
16
     *
17
     * @param $archiveFileName
18
     *
19
     * @throws \Exception
20
     */
21
    public function __construct($archiveFileName)
22
    {
23
        parent::__construct($archiveFileName);
24
        $this->modificationTime = filemtime($this->fileName);
25
    }
26
27
    /**
28
     * @param string $fileName
29
     *
30
     * @return string|false
31
     */
32
    public function getFileContent($fileName = null)
33
    {
34
        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

34
        return stream_get_contents(/** @scrutinizer ignore-call */ xzopen($this->fileName, 'r'));
Loading history...
35
    }
36
37
    /**
38
     * @param string $fileName
39
     *
40
     * @return bool|resource|string
41
     */
42
    public function getFileResource($fileName = null)
43
    {
44
        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

44
        return /** @scrutinizer ignore-call */ xzopen($this->fileName, 'r');
Loading history...
45
    }
46
47
    /**
48
     * @param $data
49
     *
50
     * @return mixed|string
51
     */
52
    protected static function compressData($data)
53
    {
54
        $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

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

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

57
        /** @scrutinizer ignore-call */ 
58
        xzclose($fp);
Loading history...
58
        return $data;
59
    }
60
}