|
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\Rule\Design; |
|
19
|
|
|
|
|
20
|
|
|
use PHPMD\AbstractTest; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Test case for the {@link \PHPMD\Rule\Design\GotoStatement} class. |
|
24
|
|
|
* |
|
25
|
|
|
* @link https://www.pivotaltracker.com/story/show/10474873 |
|
26
|
|
|
* |
|
27
|
|
|
* @covers \PHPMD\Rule\Design\GotoStatement |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
class GotoStatementTest extends AbstractTest |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* testRuleNotAppliesToMethodWithoutGotoStatement |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testRuleNotAppliesToMethodWithoutGotoStatement() |
|
37
|
|
|
{ |
|
38
|
|
|
$rule = new GotoStatement(); |
|
39
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
40
|
|
|
$rule->apply($this->getMethod()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* testRuleAppliesToMethodWithGotoStatement |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testRuleAppliesToMethodWithGotoStatement() |
|
49
|
|
|
{ |
|
50
|
|
|
$rule = new GotoStatement(); |
|
51
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
52
|
|
|
$rule->apply($this->getMethod()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* testRuleNotAppliesToFunctionWithoutGotoStatement |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testRuleNotAppliesToFunctionWithoutGotoStatement() |
|
61
|
|
|
{ |
|
62
|
|
|
$rule = new GotoStatement(); |
|
63
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
64
|
|
|
$rule->apply($this->getFunction()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* testRuleAppliesToFunctionWithGotoStatement |
|
69
|
|
|
* |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testRuleAppliesToFunctionWithGotoStatement() |
|
73
|
|
|
{ |
|
74
|
|
|
$rule = new GotoStatement(); |
|
75
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
76
|
|
|
$rule->apply($this->getFunction()); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
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.