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

LoadPhpcsReportTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 61.22 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 30
loc 49
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanMakeClass() 15 15 1
A testRejectsInvalidData() 0 4 1
A testCorrectMissingFile() 0 6 1
A testStrictMode() 15 15 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
use exussum12\CoverageChecker\PhpCsLoader;
6
use exussum12\CoverageChecker\PhpCsLoaderStrict;
7
8
class LoadPhpcsReportTest extends TestCase
9
{
10 View Code Duplication
    public function testCanMakeClass()
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...
11
    {
12
        $phpcs = new PhpCsLoader(__DIR__ . '/fixtures/phpcs.json');
13
        $invalidLines = $phpcs->getLines();
14
        $expected = [
15
            '/full/path/to/file/src/XMLReport.php' => [
16
                11 => ['Opening brace should be on the line after the declaration; found 1 blank line(s)'],
17
                12 => ['Line indented incorrectly; expected at least 8 spaces, found 4'],
18
            ],
19
        ];
20
21
        $this->assertEquals($expected, $invalidLines);
22
        $this->assertFalse($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 11));
23
        $this->assertTrue($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 10));
24
    }
25
26
    /**
27
     * @expectedException \InvalidArgumentException
28
     */
29
    public function testRejectsInvalidData()
30
    {
31
        new PhpCsLoader(__DIR__ . '/fixtures/change.txt');
32
    }
33
34
    public function testCorrectMissingFile()
35
    {
36
        $phpcs = new PhpCsLoader(__DIR__ . '/fixtures/phpcs.json');
37
38
        $this->assertTrue($phpcs->handleNotFoundFile());
39
    }
40
41 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...
42
    {
43
        $phpcs = new PhpCsLoaderStrict(__DIR__ . '/fixtures/phpcsstrict.json');
44
        $invalidLines = $phpcs->getLines();
45
        $expected = [
46
            '/full/path/to/file/src/XMLReport.php' => [
47
                11 => ['Opening brace should be on the line after the declaration; found 1 blank line(s)'],
48
                12 => ['Line indented incorrectly; expected at least 8 spaces, found 4'],
49
            ],
50
        ];
51
52
        $this->assertEquals($expected, $invalidLines);
53
        $this->assertFalse($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 11));
54
        $this->assertTrue($phpcs->isValidLine('/full/path/to/file/src/XMLReport.php', 10));
55
    }
56
}
57