Completed
Push — master ( e3c367...50cdb6 )
by Siad
21:57
created

ZipFileSet   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 61
rs 10
c 1
b 0
f 0
ccs 19
cts 21
cp 0.9048
wmc 12

1 Method

Rating   Name   Duplication   Size   Complexity  
C getFiles() 0 46 12
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
 * This is a FileSet with the to specify permissions.
22
 *
23
 * Permissions are currently not implemented by PEAR Archive_Tar,
24
 * but hopefully they will be in the future.
25
 *
26
 * @package phing.tasks.ext
27
 */
28
class ZipFileSet extends FileSet
29
{
30
    private $files = null;
31
32
    /**
33
     *  Get a list of files and directories specified in the fileset.
34
     *
35
     * @param bool $includeEmpty
36
     * @param array ...$options
37
     *
38
     * @return array a list of file and directory names, relative to
39
     *               the baseDir for the project.
40
     *
41
     * @throws Exception
42
     */
43 4
    protected function getFiles($includeEmpty = true, ...$options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    protected function getFiles($includeEmpty = true, /** @scrutinizer ignore-unused */ ...$options)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45 4
        if ($this->files === null) {
46 4
            $ds = $this->getDirectoryScanner($this->getProject());
47 4
            $this->files = $ds->getIncludedFiles();
48
49
            // build a list of directories implicitly added by any of the files
50 4
            $implicitDirs = [];
51 4
            foreach ($this->files as $file) {
52 4
                $implicitDirs[] = dirname($file);
53
            }
54
55 4
            $incDirs = $ds->getIncludedDirectories();
56
57
            // we'll need to add to that list of implicit dirs any directories
58
            // that contain other *directories* (and not files), since otherwise
59
            // we get duplicate directories in the resulting tar
60 4
            foreach ($incDirs as $dir) {
61 1
                foreach ($incDirs as $dircheck) {
62 1
                    if (!empty($dir) && $dir == dirname($dircheck)) {
63
                        $implicitDirs[] = $dir;
64
                    }
65
                }
66
            }
67
68 4
            $implicitDirs = array_unique($implicitDirs);
69
70 4
            $emptyDirectories = [];
71
72 4
            if ($includeEmpty) {
73
                // Now add any empty dirs (dirs not covered by the implicit dirs)
74
                // to the files array.
75
76 4
                foreach ($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs
77 1
                    if ($dir != "" && $dir !== "." && !in_array($dir, $implicitDirs)) {
78
                        // it's an empty dir, so we'll add it.
79
                        $emptyDirectories[] = $dir;
80
                    }
81
                }
82
            } // if $includeEmpty
83
84 4
            $this->files = array_merge($implicitDirs, $emptyDirectories, $this->files);
85 4
            sort($this->files);
86
        } // if ($this->files===null)
87
88 4
        return $this->files;
89
    }
90
}
91