Passed
Push — master ( b5ca42...8fe651 )
by Siad
05:05
created

DefaultExcludes   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 36.67%

Importance

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

5 Methods

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