Passed
Push — master ( dd99a9...c8547b )
by Michiel
10:09
created

DefaultPHPCPDResultFormatter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 54.55%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 55
ccs 12
cts 22
cp 0.5455
rs 10
c 1
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A processClones() 0 24 5
A processClonesNew() 0 11 3
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 SebastianBergmann\PHPCPD\CodeCloneMap;
21
22
/**
23
 * Prints plain text output of phpcpd run
24
 *
25
 * @package phing.tasks.ext.phpcpd.formatter
26
 * @author  Benjamin Schultz <[email protected]>
27
 */
28
class DefaultPHPCPDResultFormatter extends PHPCPDResultFormatter
29
{
30
    /**
31
     * Processes a list of clones.
32
     *
33
     * @param CodeCloneMap   $clones
34
     * @param Project        $project
35
     * @param boolean        $useFile
36
     * @param PhingFile|null $outFile
37
     */
38 2
    public function processClones($clones, Project $project, $useFile = false, $outFile = null)
39
    {
40 2
        if (get_class($clones) == 'SebastianBergmann\PHPCPD\CodeCloneMap') {
41 2
            if (class_exists('SebastianBergmann\PHPCPD\Log\Text')) {
42 2
                $this->processClonesNew($clones, $useFile, $outFile);
43
44 2
                return;
45
            }
46
47
            $logger = new \SebastianBergmann\PHPCPD\TextUI\ResultPrinter();
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\PHPCPD\TextUI\ResultPrinter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
        } else {
49
            $logger = new PHPCPD_TextUI_ResultPrinter();
0 ignored issues
show
Bug introduced by
The type PHPCPD_TextUI_ResultPrinter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
        }
51
52
        // default format goes to logs, no buffering
53
        ob_start();
54
        $logger->printResult($clones, $project->getBaseDir(), true);
55
        $output = ob_get_contents();
56
        ob_end_clean();
57
58
        if (!$useFile || empty($outFile)) {
59
            echo $output;
60
        } else {
61
            file_put_contents($outFile->getPath(), $output);
62
        }
63
    }
64
65
    /**
66
     * Wrapper for PHPCPD 2.0
67
     *
68
     * @param CodeCloneMap   $clones
69
     * @param boolean        $useFile
70
     * @param PhingFile|null $outFile
71
     */
72 2
    private function processClonesNew($clones, $useFile = false, $outFile = null)
73
    {
74 2
        if ($useFile) {
75 1
            ob_start();
76
        }
77
78 2
        $logger = new \SebastianBergmann\PHPCPD\Log\Text();
79 2
        $logger->printResult($clones, true);
80
81 2
        if ($useFile) {
82 1
            file_put_contents($outFile->getPath(), ob_get_clean());
0 ignored issues
show
Bug introduced by
The method getPath() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
            file_put_contents($outFile->/** @scrutinizer ignore-call */ getPath(), ob_get_clean());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
        }
84 2
    }
85
}
86