Passed
Push — master ( d62b89...abb8c8 )
by Michiel
06:34
created

PHPCPDFormatterElement::getFormatter()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\File;
22
use Phing\Util\StringHelper;
23
24
/**
25
 * A wrapper for the implementations of PHPCPDResultFormatter.
26
 *
27
 * @package phing.tasks.ext.phpcpd
28
 * @author  Benjamin Schultz <[email protected]>
29
 */
30
class PHPCPDFormatterElement
31
{
32
    /**
33
     * The report result formatter.
34
     *
35
     * @var PHPCPDResultFormatter
36
     */
37
    protected $formatter = null;
38
39
    /**
40
     * The type of the formatter.
41
     *
42
     * @var string
43
     */
44
    protected $type = '';
45
46
    /**
47
     * Whether to use file (or write output to phing log).
48
     *
49
     * @var boolean
50
     */
51
    protected $useFile = true;
52
53
    /**
54
     * Output file for formatter.
55
     *
56
     * @var File
57
     */
58
    protected $outfile = null;
59
60
    /**
61
     * The parent task
62
     *
63
     * @var PHPCPDTask
64
     */
65
    private $parentTask;
66
67
    /**
68
     * Construct a new PHPCPDFormatterElement with parent task.
69
     *
70
     * @param PHPCPDTask $parentTask
71
     */
72 3
    public function __construct(PHPCPDTask $parentTask)
73
    {
74 3
        $this->parentTask = $parentTask;
75 3
    }
76
77
    /**
78
     * Sets the formatter type.
79
     *
80
     * @param string $type Type of the formatter
81
     *
82
     * @throws BuildException
83
     */
84 3
    public function setType($type)
85
    {
86 3
        $this->type = $type;
87
88 3
        switch ($this->type) {
89 3
            case 'pmd':
90 1
                if ($this->useFile === false) {
91
                    throw new BuildException('Formatter "' . $this->type . '" can only print the result to an file');
92
                }
93
94 1
                $this->formatter = new PMDPHPCPDResultFormatter();
95 1
                break;
96
97 2
            case 'default':
98 2
                $this->formatter = new DefaultPHPCPDResultFormatter();
99 2
                break;
100
101
            default:
102
                throw new BuildException('Formatter "' . $this->type . '" not implemented');
103
        }
104 3
    }
105
106
    /**
107
     * Get the formatter type
108
     *
109
     * @return string
110
     */
111 3
    public function getType()
112
    {
113 3
        return $this->type;
114
    }
115
116
    /**
117
     * Set whether to write formatter results to file or not.
118
     *
119
     * @param boolean $useFile True or false.
120
     */
121 3
    public function setUseFile($useFile)
122
    {
123 3
        $this->useFile = StringHelper::booleanValue($useFile);
124 3
    }
125
126
    /**
127
     * Return whether to write formatter results to file or not.
128
     *
129
     * @return boolean
130
     */
131 3
    public function getUseFile()
132
    {
133 3
        return $this->useFile;
134
    }
135
136
    /**
137
     * Sets the output file for the formatter results.
138
     *
139
     * @param File $outfile The output file
140
     */
141 2
    public function setOutfile(File $outfile)
142
    {
143 2
        $this->outfile = $outfile;
144 2
    }
145
146
    /**
147
     * Get the output file.
148
     *
149
     * @return File
150
     */
151 3
    public function getOutfile()
152
    {
153 3
        return $this->outfile;
154
    }
155
156
    /**
157
     * Returns the report formatter.
158
     *
159
     * @return PHPCPDResultFormatter
160
     */
161 3
    public function getFormatter()
162
    {
163 3
        return $this->formatter;
164
    }
165
}
166