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

PhpcsDiffFilterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 82.76 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testValid() 12 12 1
A testStrictMode() 12 12 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
namespace exussum12\CoverageChecker\tests;
3
4
use PHPUnit\Framework\TestCase;
5
6
class PhpcsDiffFilterTest extends TestCase
7
{
8
9 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...
10
    {
11
        $GLOBALS['argv'] = [
12
            'phpunitDiffFilter',
13
            __DIR__ . '/fixtures/change.txt',
14
            __DIR__ . '/fixtures/phpcs.json'
15
        ];
16
        ob_start();
17
        require(__DIR__ . "/../src/runners/phpcsDiffFilter.php");
18
        $output = ob_get_clean();
19
        $this->assertContains('100.00%', $output);
20
    }
21
22 View Code Duplication
    public function testStrictMode()
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
testStrictMode 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...
23
    {
24
        $GLOBALS['argv'] = [
25
            'phpunitDiffFilter',
26
            __DIR__ . '/fixtures/change.txt',
27
            __DIR__ . '/fixtures/phpcsstrict.json'
28
        ];
29
        ob_start();
30
        require(__DIR__ . "/../src/runners/phpcsDiffFilter.php");
31
        $output = ob_get_clean();
32
        $this->assertContains('100.00%', $output);
33
    }
34
}
35