PHPMDTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 135
Duplicated Lines 68.15 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 92
loc 135
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testRunWithDefaultSettingsAndXmlRenderer() 20 20 1
A testRunWithDefaultSettingsAndXmlRendererAgainstDirectory() 19 19 1
A testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile() 19 19 1
A testHasViolationsReturnsFalseByDefault() 0 5 1
A testHasViolationsReturnsFalseForSourceWithoutViolations() 17 17 1
A testHasViolationsReturnsTrueForSourceWithViolation() 17 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD;
19
20
use PHPMD\Renderer\XMLRenderer;
21
use PHPMD\Stubs\WriterStub;
22
23
/**
24
 * Test case for the main PHPMD class.
25
 *
26
 * @covers \PHPMD\PHPMD
27
 */
28
class PHPMDTest extends AbstractTest
29
{
30
    /**
31
     * Tests the main PHPMD interface with default settings an a xml-renderer.
32
     *
33
     * @return void
34
     */
35 View Code Duplication
    public function testRunWithDefaultSettingsAndXmlRenderer()
0 ignored issues
show
Duplication introduced by
This method 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...
36
    {
37
        self::changeWorkingDirectory();
38
39
        $writer = new WriterStub();
40
41
        $renderer = new XMLRenderer();
42
        $renderer->setWriter($writer);
43
44
        $phpmd = new PHPMD();
45
46
        $phpmd->processFiles(
47
            self::createFileUri('source/ccn_function.php'),
48
            'pmd-refset1',
49
            array($renderer),
50
            new RuleSetFactory()
51
        );
52
53
        $this->assertXmlEquals($writer->getData(), 'pmd/default-xml.xml');
54
    }
55
56
    /**
57
     * testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile
58
     *
59
     * @return void
60
     */
61 View Code Duplication
    public function testRunWithDefaultSettingsAndXmlRendererAgainstDirectory()
0 ignored issues
show
Duplication introduced by
This method 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...
62
    {
63
        self::changeWorkingDirectory();
64
65
        $writer = new WriterStub();
66
67
        $renderer = new XMLRenderer();
68
        $renderer->setWriter($writer);
69
70
        $phpmd = new PHPMD();
71
        $phpmd->processFiles(
72
            self::createFileUri('source'),
73
            'pmd-refset1',
74
            array($renderer),
75
            new RuleSetFactory()
76
        );
77
78
        $this->assertXmlEquals($writer->getData(), 'pmd/single-directory.xml');
79
    }
80
81
    /**
82
     * testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile
83
     *
84
     * @return void
85
     */
86 View Code Duplication
    public function testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile()
0 ignored issues
show
Duplication introduced by
This method 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...
87
    {
88
        self::changeWorkingDirectory();
89
90
        $writer = new WriterStub();
91
92
        $renderer = new XMLRenderer();
93
        $renderer->setWriter($writer);
94
95
        $phpmd = new PHPMD();
96
        $phpmd->processFiles(
97
            self::createFileUri('source/ccn_function.php'),
98
            'pmd-refset1',
99
            array($renderer),
100
            new RuleSetFactory()
101
        );
102
103
        $this->assertXmlEquals($writer->getData(), 'pmd/single-file.xml');
104
    }
105
106
    /**
107
     * testHasViolationsReturnsFalseByDefault
108
     *
109
     * @return void
110
     */
111
    public function testHasViolationsReturnsFalseByDefault()
112
    {
113
        $phpmd = new PHPMD();
114
        $this->assertFalse($phpmd->hasViolations());
115
    }
116
117
    /**
118
     * testHasViolationsReturnsFalseForSourceWithoutViolations
119
     *
120
     * @return void
121
     */
122 View Code Duplication
    public function testHasViolationsReturnsFalseForSourceWithoutViolations()
0 ignored issues
show
Duplication introduced by
This method 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...
123
    {
124
        self::changeWorkingDirectory();
125
126
        $renderer = new XMLRenderer();
127
        $renderer->setWriter(new WriterStub());
128
129
        $phpmd = new PHPMD();
130
        $phpmd->processFiles(
131
            self::createFileUri('source/source_without_violations.php'),
132
            'pmd-refset1',
133
            array($renderer),
134
            new RuleSetFactory()
135
        );
136
137
        $this->assertFalse($phpmd->hasViolations());
138
    }
139
140
    /**
141
     * testHasViolationsReturnsTrueForSourceWithViolation
142
     *
143
     * @return void
144
     */
145 View Code Duplication
    public function testHasViolationsReturnsTrueForSourceWithViolation()
0 ignored issues
show
Duplication introduced by
This method 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...
146
    {
147
        self::changeWorkingDirectory();
148
149
        $renderer = new XMLRenderer();
150
        $renderer->setWriter(new WriterStub());
151
152
        $phpmd = new PHPMD();
153
        $phpmd->processFiles(
154
            self::createFileUri('source/source_with_npath_violation.php'),
155
            'pmd-refset1',
156
            array($renderer),
157
            new RuleSetFactory()
158
        );
159
160
        $this->assertTrue($phpmd->hasViolations());
161
    }
162
}
163