Passed
Push — master ( fedd27...f10ad5 )
by Michiel
11:13
created

DefaultExcludes   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 36.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 102
ccs 11
cts 30
cp 0.3667
rs 10
c 1
b 0
f 0
wmc 13

5 Methods

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