Passed
Push — master ( 30bcbc...eba4fe )
by Siad
06:53
created

PHPLocFormatterFactory::createFormatter()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 28
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 5.0187

Importance

Changes 0
Metric Value
cc 5
eloc 22
nc 5
nop 1
dl 0
loc 28
ccs 20
cts 22
cp 0.9091
crap 5.0187
rs 9.2568
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
/**
21
 * A wrapper for the implementations of PHPUnit2ResultFormatter.
22
 *
23
 * @author  Michiel Rook <[email protected]>
24
 * @package phing.tasks.ext.phploc
25
 */
26
class PHPLocFormatterFactory
27
{
28
    /**
29
     * Returns formatter object
30
     *
31
     * @param  PHPLocFormatterElement $formatterElement
32
     * @throws BuildException
33
     * @return AbstractPHPLocFormatter
34
     */
35 4
    public static function createFormatter($formatterElement)
36
    {
37 4
        $formatter = null;
38 4
        $type = $formatterElement->getType();
39
40 4
        switch ($type) {
41 4
            case "xml":
42 2
                include_once 'phing/tasks/ext/phploc/PHPLocXMLFormatter.php';
43 2
                $formatter = new PHPLocXMLFormatter();
44 2
                break;
45 3
            case "csv":
46 2
                include_once 'phing/tasks/ext/phploc/PHPLocCSVFormatter.php';
47 2
                $formatter = new PHPLocCSVFormatter();
48 2
                break;
49 2
            case "txt":
50
            case "cli":
51 2
                include_once 'phing/tasks/ext/phploc/PHPLocTextFormatter.php';
52 2
                $formatter = new PHPLocTextFormatter();
53 2
                break;
54
            default:
55
                throw new BuildException("Formatter '" . $type . "' not implemented");
56
        }
57
58 4
        $formatter->setOutfile($formatterElement->getOutfile());
59 4
        $formatter->setToDir($formatterElement->getToDir());
60 4
        $formatter->setUseFile($formatterElement->getUseFile());
61
62 4
        return $formatter;
63
    }
64
}
65