Passed
Push — main ( 7acf43...7c92cb )
by Michiel
06:10
created

DefaultExcludes::setAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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