Passed
Push — master ( d4a5ea...20f78d )
by Michiel
07:52
created

UnzipTask   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 53
ccs 18
cts 22
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractArchive() 0 24 3
A listArchiveContent() 0 13 2
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
/**
21
 * Extracts one or several zip archives using ZipArchive class.
22
 *
23
 * @author  Joakim Bodin <[email protected]>
24
 * @author  George Miroshnikov <[email protected]>
25
 * @package phing.tasks.ext
26
 */
27
class UnzipTask extends ExtractBaseTask
28
{
29
    /**
30
     * Extract archive content into $this->todir directory
31
     *
32
     * @param  PhingFile Zip file to extract
33
     * @return boolean
34
     */
35 1
    protected function extractArchive(PhingFile $zipfile)
36
    {
37 1
        $this->log(
38 1
            "Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(),
39 1
            Project::MSG_INFO
40
        );
41
42 1
        $zip = new ZipArchive();
43
44 1
        $result = $zip->open($zipfile->getAbsolutePath());
45 1
        if (!$result) {
46
            $this->log("Unable to open zipfile " . $zipfile->__toString(), Project::MSG_ERR);
47
48
            return false;
49
        }
50
51 1
        $result = $zip->extractTo($this->todir->getAbsolutePath());
52 1
        if (!$result) {
53
            $this->log("Unable to extract zipfile " . $zipfile->__toString(), Project::MSG_ERR);
54
55
            return false;
56
        }
57
58 1
        return true;
59
    }
60
61
    /**
62
     * List archive content
63
     *
64
     * @param  PhingFile Zip file to list content
65
     * @return array List of files inside $zipfile
66
     */
67 1
    protected function listArchiveContent(PhingFile $zipfile)
68
    {
69 1
        $zip = new ZipArchive();
70 1
        $zip->open($zipfile->getAbsolutePath());
71
72 1
        $content = [];
73 1
        for ($i = 0; $i < $zip->numFiles; $i++) {
74 1
            $content[] = [
75 1
                'filename' => $zip->getNameIndex($i)
76
            ];
77
        }
78
79 1
        return $content;
80
    }
81
}
82