Completed
Push — master ( ce7b38...6ec792 )
by Peter
04:34
created

ZipCompressor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compress() 0 15 4
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace GpsLab\Component\Sitemap\Compressor;
10
11
class ZipCompressor implements CompressorInterface
12
{
13
    /**
14
     * @var \ZipArchive
15
     */
16
    protected $zip;
17
18
    /**
19
     * @param \ZipArchive $zip
20
     */
21
    public function __construct(\ZipArchive $zip)
22
    {
23
        $this->zip = $zip;
24
    }
25
26
    /**
27
     * @param string $source
28
     * @param string $target
29
     *
30
     * @return bool
31
     */
32
    public function compress($source, $target = '')
33
    {
34
        $target = $target ?: $source.'.zip';
35
36
        if ($this->zip->open($target) === false) {
37
            return false;
38
        }
39
40
        if ($this->zip->addFile($source, basename($source)) == false) {
41
            $this->zip->close();
42
            return false;
43
        }
44
45
        return $this->zip->close();
46
    }
47
}
48