Passed
Push — master ( 902a34...c826a7 )
by Kyle
53s queued 11s
created

CountInLoopExpressionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 62
loc 62
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRuleAppliesToAllTypesOfLoops() 6 6 1
A testRuleNotApplyToExpressionElsewhere() 6 6 1
A testRuleApplyToNestedLoops() 6 6 1
A testMutedRuleAtClassLevel() 6 6 1
A testMutedRuleAtMethodLevel() 6 6 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\Rule\Design;
19
20
use PHPMD\AbstractTest;
21
22
/**
23
 * Count In Loop Expression Test
24
 *
25
 * @author Kamil Szymanski <[email protected]>
26
 */
27 View Code Duplication
class CountInLoopExpressionTest extends AbstractTest
28
{
29
    /**
30
     * testRuleAppliesToAllTypesOfLoops
31
     *
32
     * @return void
33
     */
34
    public function testRuleAppliesToAllTypesOfLoops()
35
    {
36
        $rule = new CountInLoopExpression();
37
        $rule->setReport($this->getReportMock(3));
0 ignored issues
show
Bug introduced by
It seems like $this->getReportMock(3) targeting PHPMD\AbstractTest::getReportMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PHPMD\AbstractRule::setReport() does only seem to accept object<PHPMD\Report>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
38
        $rule->apply($this->getMethod());
39
    }
40
41
    /**
42
     * testRuleNotApplyToExpressionElsewhere
43
     *
44
     * @return void
45
     */
46
    public function testRuleNotApplyToExpressionElsewhere()
47
    {
48
        $rule = new CountInLoopExpression();
49
        $rule->setReport($this->getReportWithNoViolation());
50
        $rule->apply($this->getMethod());
51
    }
52
53
    /**
54
     * testRuleApplyToNestedLoops
55
     *
56
     * @return void
57
     */
58
    public function testRuleApplyToNestedLoops()
59
    {
60
        $rule = new CountInLoopExpression();
61
        $rule->setReport($this->getReportMock(8));
0 ignored issues
show
Bug introduced by
It seems like $this->getReportMock(8) targeting PHPMD\AbstractTest::getReportMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, PHPMD\AbstractRule::setReport() does only seem to accept object<PHPMD\Report>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
62
        $rule->apply($this->getFunction());
63
    }
64
65
    /**
66
     * testMutedRuleAtClassLevel
67
     *
68
     * @return void
69
     */
70
    public function testMutedRuleAtClassLevel()
71
    {
72
        $rule = new CountInLoopExpression();
73
        $rule->setReport($this->getReportWithNoViolation());
74
        $rule->apply($this->getClass());
75
    }
76
77
    /**
78
     * testMutedRuleAtMethodLevel
79
     *
80
     * @return void
81
     */
82
    public function testMutedRuleAtMethodLevel()
83
    {
84
        $rule = new CountInLoopExpression();
85
        $rule->setReport($this->getReportWithNoViolation());
86
        $rule->apply($this->getClass());
87
    }
88
}
89