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

ZipCompressor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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