MethodOneTryCatchTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 2
c 2
b 0
f 2
lcom 1
cbo 2
dl 27
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRuleWithoutTry() 8 8 1
A testMethodOneTryCatchRule() 9 9 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\Functional\CleanCode;
4
5
use MS\PHPMD\Tests\Functional\AbstractProcessTest;
6
7
/**
8
 * Class MethodOneTryCatchTest
9
 *
10
 * @package MS\PHPMD\Tests\Functional\CleanCode
11
 */
12 View Code Duplication
class MethodOneTryCatchTest extends AbstractProcessTest
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...
13
{
14
    /**
15
     * @covers MS\PHPMD\Rule\CleanCode\MethodOneTryCatch
16
     */
17
    public function testMethodOneTryCatchRule()
18
    {
19
        $output = $this
20
            ->runPhpmd('Utility/TryThings.php', 'cleancode.xml')
21
            ->getOutput();
22
23
        $this->assertContains('Utility/TryThings.php:39	This method contains more than one try statement. Swap out the try statement in an extra method. It increase the readability.', $output);
24
        $this->assertContains('Utility/TryThings.php:53	This method contains more than one try statement. Swap out the try statement in an extra method. It increase the readability.', $output);
25
    }
26
27
    /**
28
     * @covers MS\PHPMD\Rule\CleanCode\MethodOneTryCatch
29
     */
30
    public function testRuleWithoutTry()
31
    {
32
        $output = $this
33
            ->runPhpmd('Entity.php', 'cleancode.xml')
34
            ->getOutput();
35
36
        $this->assertEmpty(trim($output));
37
    }
38
}
39