Passed
Push — master ( cbf6d3...d62b89 )
by Michiel
08:56
created

DefaultExcludes::main()   B

Complexity

Conditions 9
Paths 17

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 9.111

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 25
ccs 16
cts 18
cp 0.8889
rs 8.0555
c 0
b 0
f 0
cc 9
nc 17
nop 0
crap 9.111
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
namespace Phing\Task\System;
21
22
use Phing\Exception\BuildException;
23
use Phing\Io\DirectoryScanner;
24
use Phing\Phing;
25
use Phing\Project;
26
use Phing\Task;
27
28
/**
29
 * Alters the default excludes for the <strong>entire</strong> build.
30
 *
31
 * @author  Siad Ardroumli <[email protected]>
32
 */
33
class DefaultExcludes extends Task
34
{
35
    /**
36
     * @var string $add
37
     */
38
    private $add = "";
39
40
    /**
41
     * @var string $remove
42
     */
43
    private $remove = "";
44
45
    /**
46
     * @var boolean $defaultrequested
47
     */
48
    private $defaultrequested = false;
49
50
    /**
51
     * @var boolean $echo
52
     */
53
    private $echo = false;
54
55
    /**
56
     * by default, messages are always displayed
57
     *
58
     * @var int
59
     */
60
    private $logLevel = Project::MSG_WARN;
61
62
    /**
63
     * Does the work.
64
     *
65
     * @throws BuildException if something goes wrong with the build
66
     */
67 6
    public function main()
68
    {
69 6
        if (!$this->defaultrequested && $this->add === "" && $this->remove === "" && !$this->echo) {
70
            throw new BuildException(
71
                "<defaultexcludes> task must set at least one attribute (echo=\"false\")"
72
                . " doesn't count since that is the default"
73
            );
74
        }
75 6
        if ($this->defaultrequested) {
76 6
            DirectoryScanner::resetDefaultExcludes();
77
        }
78 6
        if ($this->add !== "") {
79 1
            DirectoryScanner::addDefaultExclude($this->add);
80
        }
81 6
        if ($this->remove !== "") {
82 1
            DirectoryScanner::removeDefaultExclude($this->remove);
83
        }
84 6
        if ($this->echo) {
85 3
            $lineSep = Phing::getProperty('line.separator');
86 3
            $message = "Current Default Excludes:";
87 3
            $message .= $lineSep;
88 3
            $excludes = DirectoryScanner::getDefaultExcludes();
89 3
            $message .= "  ";
90 3
            $message .= implode($lineSep . "  ", $excludes);
91 3
            $this->log($message, $this->logLevel);
92
        }
93 6
    }
94
95
    /**
96
     * go back to standard default patterns
97
     *
98
     * @param boolean $def if true go back to default patterns
99
     */
100 6
    public function setDefault($def)
101
    {
102 6
        $this->defaultrequested = $def;
103 6
    }
104
105
    /**
106
     * Pattern to add to the default excludes
107
     *
108
     * @param string $add Sets the value for the pattern to exclude.
109
     */
110 1
    public function setAdd($add)
111
    {
112 1
        $this->add = $add;
113 1
    }
114
115
    /**
116
     * Pattern to remove from the default excludes.
117
     *
118
     * @param string $remove Sets the value for the pattern that
119
     *                       should no longer be excluded.
120
     */
121 1
    public function setRemove($remove)
122
    {
123 1
        $this->remove = $remove;
124 1
    }
125
126
    /**
127
     * If true, echo the default excludes.
128
     *
129
     * @param boolean $echo whether or not to echo the contents of
130
     *                      the default excludes.
131
     */
132 3
    public function setEcho($echo)
133
    {
134 3
        $this->echo = $echo;
135 3
    }
136
}
137