CopyPasteDetector::getCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 7
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Finder\Logic\Tools;
3
4
use Finder\Logic\AnalysisResult;
5
use Support\Helps\ArrayHelper;
6
use Sabre\Xml\Reader;
7
8
/**
9
 * Integration of CodeAnalyser with CopyPasteDetector.
10
 *
11
 * @see https://github.com/sebastianbergmann/phpcpd
12
 */
13 View Code Duplication
class CopyPasteDetector extends AbstractTool
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...
14
{
15
    /**
16
     * @inheritdoc
17
     */
18
    public function getDescription()
19
    {
20
        return 'CopyPasteDetector';
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function getIgnoredArgument()
27
    {
28
        if (!empty($this->ignoredPaths)) {
29
            return '--exclude={' . implode(',', $this->ignoredPaths) . '} ';
30
        }
31
        return '';
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function getCommand($targetPaths)
38
    {
39
        return $this->binariesPath . 'phpcpd '
40
            . implode(' ', $targetPaths) . ' '
41
            . $this->getIgnoredArgument() . '--log-pmd="'
42
            . $this->temporaryFilePath . '"';
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    protected function addIssuesFromXml(Reader $xml)
49
    {
50
        $xmlArray = $xml->parse();
51
52
        foreach ((array) $xmlArray['value'] as $duplicationTag) {
53
            if ($duplicationTag['name'] != '{}duplication'
54
                || empty($duplicationTag['value'])
55
            ) {
56
                continue;
57
            }
58
59
            foreach ((array) $duplicationTag['value'] as $fileTag) {
60
                if ($fileTag['name'] != '{}file') {
61
                    continue;
62
                }
63
64
                $fileName = $fileTag['attributes']['path'];
65
                $line = $fileTag['attributes']['line'];
66
                $tool = 'CopyPasteDetector';
67
                $type = 'duplication';
68
                $message = 'Duplicated code';
69
70
                $this->result->addIssue($fileName, $line, $tool, $type, $message);
71
            }
72
        }
73
    }
74
}
75