Passed
Push — main ( 4c3994...11b1e9 )
by Michiel
13:02 queued 05:33
created

ZipFileSet::getFiles()   C

Complexity

Conditions 12
Paths 3

Size

Total Lines 46
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 12.0155

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 46
rs 6.9666
c 0
b 0
f 0
ccs 20
cts 21
cp 0.9524
cc 12
nc 3
nop 2
crap 12.0155

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\Ext\Archive;
22
23
use Phing\Type\FileSet;
24
25
/**
26
 * This is a FileSet with the to specify permissions.
27
 *
28
 * Permissions are currently not implemented by PEAR Archive_Tar,
29
 * but hopefully they will be in the future.
30
 *
31
 * @package phing.tasks.ext
32
 */
33
class ZipFileSet extends FileSet
34
{
35
    private $files = null;
36
37
    /**
38
     *  Get a list of files and directories specified in the fileset.
39
     *
40
     * @param bool $includeEmpty
41
     * @param array ...$options
42
     *
43
     * @return array a list of file and directory names, relative to
44
     *               the baseDir for the project.
45
     *
46
     * @throws \Exception
47
     */
48 6
    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

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