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

Bzip   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileResource() 0 3 1
A getFileContent() 0 3 1
A __construct() 0 4 1
A compressData() 0 3 1
1
<?php
2
namespace wapmorgan\UnifiedArchive\Formats;
3
4
use Exception;
5
6
class Bzip extends OneFileFormat
7
{
8
    const FORMAT_SUFFIX =  'bz2';
9
10
    /**
11
     * Bzip constructor.
12
     *
13
     * @param $archiveFileName
14
     *
15
     * @throws \Exception
16
     */
17
    public function __construct($archiveFileName)
18
    {
19
        parent::__construct($archiveFileName);
20
        $this->modificationTime = filemtime($this->fileName);
21
    }
22
23
    /**
24
     * @param string $fileName
25
     *
26
     * @return string|false
27
     */
28
    public function getFileContent($fileName = null)
29
    {
30
        return bzdecompress(file_get_contents($this->fileName));
31
    }
32
33
    /**
34
     * @param string $fileName
35
     *
36
     * @return bool|resource|string
37
     */
38
    public function getFileResource($fileName = null)
39
    {
40
        return bzopen($this->fileName, 'r');
41
    }
42
43
    /**
44
     * @param $data
45
     *
46
     * @return mixed|string
47
     */
48
    protected static function compressData($data)
49
    {
50
        return bzcompress($data);
51
    }
52
}