EntityConstantsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 19.51 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 5
dl 8
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testApplyNoEntity() 8 8 1
A testApplyEntityHasConstants() 0 9 1
A getRule() 0 8 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
namespace MS\PHPMD\Tests\Unit\Symfony2;
4
5
use MS\PHPMD\Rule\Symfony2\EntityConstants;
6
use MS\PHPMD\Tests\Unit\AbstractApplyTest;
7
8
/**
9
 * Class EntityConstantsTest
10
 *
11
 * @package MS\PHPMD\Tests\Unit\Symfony2
12
 */
13
class EntityConstantsTest extends AbstractApplyTest
14
{
15
    /**
16
     * @covers MS\PHPMD\Rule\Symfony2\EntityConstants
17
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
18
     */
19 View Code Duplication
    public function testApplyNoEntity()
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...
20
    {
21
        $node = \Mockery::mock('PHPMD\Node\ClassNode');
22
        $node->shouldReceive('getDocComment')->andReturn('');
23
        $node->shouldReceive('isAbstract')->andReturn(false);
24
25
        $this->assertRule($node, 0);
26
    }
27
28
    /**
29
     * @covers MS\PHPMD\Rule\Symfony2\EntityConstants
30
     * @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule
31
     */
32
    public function testApplyEntityHasConstants()
33
    {
34
        $node = \Mockery::mock('PHPMD\Node\ClassNode');
35
        $node->shouldReceive('getDocComment')->andReturn('* @isEntity');
36
        $node->shouldReceive('getConstants')->andReturn([1]);
37
        $node->shouldReceive('getName')->andReturn('Entity');
38
39
        $this->assertRule($node, 1);
40
    }
41
42
    /**
43
     * @return EntityConstants
44
     */
45
    protected function getRule()
46
    {
47
        $rule = new EntityConstants();
48
        $rule->addProperty('entityRegex', '(\*\s*@\S*Entity)i');
49
        $rule->addProperty('classIsEntityRegex', '(\*\s*@isEntity)i');
50
51
        return $rule;
52
    }
53
}
54