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
 * A wrapper for the implementations of PHPCPDResultFormatter.
22
 *
23
 * @package phing.tasks.ext.phpcpd
24
 * @author  Benjamin Schultz <bschultz@proqrent.de>
25
 */
26
class PHPCPDFormatterElement
27
{
28
    /**
29
     * The report result formatter.
30
     *
31
     * @var PHPCPDResultFormatter
32
     */
33
    protected $formatter = null;
34

35
    /**
36
     * The type of the formatter.
37
     *
38
     * @var string
39
     */
40
    protected $type = '';
41

42
    /**
43
     * Whether to use file (or write output to phing log).
44
     *
45
     * @var boolean
46
     */
47
    protected $useFile = true;
48

49
    /**
50
     * Output file for formatter.
51
     *
52
     * @var PhingFile
53
     */
54
    protected $outfile = null;
55

56
    /**
57
     * The parent task
58
     *
59
     * @var PHPCPDTask
60
     */
61
    private $parentTask;
62

63
    /**
64
     * Construct a new PHPCPDFormatterElement with parent task.
65
     *
66
     * @param PHPCPDTask $parentTask
67
     */
68 1
    public function __construct(PHPCPDTask $parentTask)
69
    {
70 1
        $this->parentTask = $parentTask;
71
    }
72

73
    /**
74
     * Sets the formatter type.
75
     *
76
     * @param string $type Type of the formatter
77
     *
78
     * @throws BuildException
79
     */
80 1
    public function setType($type)
81
    {
82 1
        $this->type = $type;
83

84 1
        switch ($this->type) {
85 1
            case 'pmd':
86 1
                if ($this->useFile === false) {
87 0
                    throw new BuildException('Formatter "' . $this->type . '" can only print the result to an file');
88
                }
89

90 1
                include_once 'phing/tasks/ext/phpcpd/formatter/PMDPHPCPDResultFormatter.php';
91

92 1
                $this->formatter = new PMDPHPCPDResultFormatter();
93 1
                break;
94

95 1
            case 'default':
96 1
                include_once 'phing/tasks/ext/phpcpd/formatter/DefaultPHPCPDResultFormatter.php';
97

98 1
                $this->formatter = new DefaultPHPCPDResultFormatter();
99 1
                break;
100

101
            default:
102 0
                throw new BuildException('Formatter "' . $this->type . '" not implemented');
103
        }
104
    }
105

106
    /**
107
     * Get the formatter type
108
     *
109
     * @return string
110
     */
111 1
    public function getType()
112
    {
113 1
        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 1
    public function setUseFile($useFile)
122
    {
123 1
        $this->useFile = StringHelper::booleanValue($useFile);
124
    }
125

126
    /**
127
     * Return whether to write formatter results to file or not.
128
     *
129
     * @return boolean
130
     */
131 1
    public function getUseFile()
132
    {
133 1
        return $this->useFile;
134
    }
135

136
    /**
137
     * Sets the output file for the formatter results.
138
     *
139
     * @param PhingFile $outfile The output file
140
     */
141 1
    public function setOutfile(PhingFile $outfile)
142
    {
143 1
        $this->outfile = $outfile;
144
    }
145

146
    /**
147
     * Get the output file.
148
     *
149
     * @return PhingFile
150
     */
151 1
    public function getOutfile()
152
    {
153 1
        return $this->outfile;
154
    }
155

156
    /**
157
     * Returns the report formatter.
158
     *
159
     * @return PHPCPDResultFormatter
160
     */
161 1
    public function getFormatter()
162
    {
163 1
        return $this->formatter;
164
    }
165
}

Read our documentation on viewing source code .

Loading