PHPCopyPasteDetector::addIssuesFromXml()   B
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 8.439
c 0
b 0
f 0
cc 6
eloc 15
nc 3
nop 1
1
<?php
2
namespace phphound\integration;
3
4
use phphound\AnalysisResult;
5
use phphound\helper\ArrayHelper;
6
use Sabre\Xml\Reader;
7
8
/**
9
 * Integration of PHPHound with PHPCopyPasteDetector.
10
 * @see https://github.com/sebastianbergmann/phpcpd
11
 */
12 View Code Duplication
class PHPCopyPasteDetector extends AbstractIntegration
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * @inheritdoc
16
     */
17
    public function getDescription()
18
    {
19
        return 'PHPCopyPasteDetector';
20
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function getIgnoredArgument()
26
    {
27
        if (!empty($this->ignoredPaths)) {
28
            return '--exclude={' . implode(',', $this->ignoredPaths) . '} ';
29
        }
30
        return '';
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function getCommand($targetPaths)
37
    {
38
        return $this->binariesPath . 'phpcpd '
39
            . implode(' ', $targetPaths) . ' '
40
            . $this->getIgnoredArgument() . '--log-pmd="'
41
            . $this->temporaryFilePath . '"';
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47
    protected function addIssuesFromXml(Reader $xml)
48
    {
49
        $xmlArray = $xml->parse();
50
51
        foreach ((array) $xmlArray['value'] as $duplicationTag) {
52
            if ($duplicationTag['name'] != '{}duplication'
53
                || empty($duplicationTag['value'])) {
54
                continue;
55
            }
56
57
            foreach ((array) $duplicationTag['value'] as $fileTag) {
58
                if ($fileTag['name'] != '{}file') {
59
                    continue;
60
                }
61
62
                $fileName = $fileTag['attributes']['path'];
63
                $line = $fileTag['attributes']['line'];
64
                $tool = 'PHPCopyPasteDetector';
65
                $type = 'duplication';
66
                $message = 'Duplicated code';
67
68
                $this->result->addIssue($fileName, $line, $tool, $type, $message);
69
            }
70
        }
71
    }
72
}
73