Passed
Branch master (cd2b9b)
by Scott
03:31
created

PhpmdDiffFilterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 89.47 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testValid() 12 12 1
A testNoValidLines() 19 19 2
A testNoValidLinesStrict() 20 20 2

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
namespace exussum12\CoverageChecker\tests;
3
4
use PHPUnit\Framework\TestCase;
5
use Exception;
6
7
class PhpmdDiffFilterTest extends TestCase
8
{
9
10 View Code Duplication
    public function testValid()
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...
Coding Style introduced by
testValid uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
11
    {
12
        $GLOBALS['argv'] = [
13
            'phpunitDiffFilter',
14
            __DIR__ . '/fixtures/change.txt',
15
            __DIR__ . '/fixtures/phpmd.xml'
16
        ];
17
        ob_start();
18
        require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
19
        $output = ob_get_clean();
20
        $this->assertContains('100.00%', $output);
21
    }
22
23 View Code Duplication
    public function testNoValidLines()
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...
Coding Style introduced by
testNoValidLines uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
24
    {
25
        $GLOBALS['argv'] = [
26
            'phpunitDiffFilter',
27
            __DIR__ . '/fixtures/change.txt',
28
            __DIR__ . '/fixtures/phpmd-change.xml',
29
        ];
30
        try {
31
            ob_start();
32
            require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
33
        } catch (Exception $e) {
34
            $output = ob_get_clean();
35
            $this->assertEquals(2, $e->getCode());
36
            $this->assertContains('0.00%', $output);
37
            return;
38
        }
39
        $this->fail("no exception thrown");
40
41
    }
42
43 View Code Duplication
    public function testNoValidLinesStrict()
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...
Coding Style introduced by
testNoValidLinesStrict uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
44
    {
45
        $GLOBALS['argv'] = [
46
            'phpunitDiffFilter',
47
            __DIR__ . '/fixtures/change.txt',
48
            __DIR__ . '/fixtures/phpmd-change.xml',
49
            '--strict',
50
        ];
51
        try {
52
            ob_start();
53
            require(__DIR__ . "/../src/runners/phpmdDiffFilter.php");
54
        } catch (Exception $e) {
55
            $output = ob_get_clean();
56
            $this->assertEquals(2, $e->getCode());
57
            $this->assertContains('0%', $output);
58
            return;
59
        }
60
61
        $this->fail("no exception thrown");
62
    }
63
}
64