Completed
Push — master ( d2992a...8fe16f )
by Michał
06:47
created

ParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 163
Duplicated Lines 18.4 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateParserForNotExistingFile() 0 4 1
A testCreateParserForNoneAccessibleFile() 0 4 1
A testCreateParser() 15 15 1
A testCreateParserWithDirSkipping() 0 19 1
A testCreateParserWithDirSkippingForNoneExistingDir() 15 15 1
B infoList() 0 90 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 CloverReporterTest;
4
5
use PHPUnit\Framework\TestCase;
6
use CloverReporter\Parser;
7
8
class ParserTest extends TestCase
9
{
10
    use \CloverReporterTest\Helper;
11
12
    /**
13
     * @expectedException \InvalidArgumentException
14
     */
15
    public function testCreateParserForNotExistingFile()
16
    {
17
        new Parser('plik', ['skip-dir' => '']);
18
    }
19
20
    /**
21
     * @expectedException \InvalidArgumentException
22
     */
23
    public function testCreateParserForNoneAccessibleFile()
24
    {
25
        new Parser('tests/reports/no_accessible.xml', ['skip-dir' => '']);
26
    }
27
28 View Code Duplication
    public function testCreateParser()
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...
29
    {
30
        $parser = new Parser(
31
            $this->reportPaths['base'] . 'clover_log.xml',
32
            [
33
                'skip-dir' => '',
34
                'show-coverage' => false,
35
            ]
36
        );
37
38
        $this->assertEquals(
39
            $this->infoList(),
40
            $parser->getInfoList()
41
        );
42
    }
43
44
    public function testCreateParserWithDirSkipping()
45
    {
46
        $parser = new Parser(
47
            $this->reportPaths['base'] . 'clover_log.xml',
48
            [
49
                'skip-dir' => 'src',
50
                'show-coverage' => false,
51
            ]
52
        );
53
54
        $this->assertEquals(
55
            [
56
                'files' => [
57
                    'package' => 'SimpleLog\Message',
58
                ],
59
            ],
60
            $parser->getInfoList()
61
        );
62
    }
63
64 View Code Duplication
    public function testCreateParserWithDirSkippingForNoneExistingDir()
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...
65
    {
66
        $parser = new Parser(
67
            $this->reportPaths['base'] . 'clover_log.xml',
68
            [
69
                'skip-dir' => 'foo',
70
                'show-coverage' => false,
71
            ]
72
        );
73
74
        $this->assertEquals(
75
            $this->infoList(),
76
            $parser->getInfoList()
77
        );
78
    }
79
80
    protected function infoList()
81
    {
82
        return [
83
            'files' => [
84
                'package' => 'SimpleLog\Message',
85
                [
86
                    'path' => '{$path}log/src/Log.php',
87
                    'package' => 'SimpleLog',
88
                    'namespace' => 'Log',
89
                    'percent' => 84.210526315789465,
90
                    'info' => [
91
                            45  => '9',
92
                            47  => '9',
93
                            49  => '9',
94
                            50  => '9',
95
                            52  => '9',
96
                            53  => '9',
97
                            54  => '9',
98
                            63  => '8',
99
                            65  => '8',
100
                            74  => '10',
101
                            76  => '10',
102
                            77  => '1',
103
                            80  => '9',
104
                            81  => '9',
105
                            82  => '8',
106
                            84  => '8',
107
                            85  => '8',
108
                            90  => '10',
109
                            92  => '10',
110
                            93  => '0',
111
                            94  => '0',
112
                            97  => '10',
113
                            98  => '10',
114
                            104 => '9',
115
                            106 => '9',
116
                            107 => '0',
117
                            108 => '0',
118
                            111 => '9',
119
                            112 => '9',
120
                            122 => '3',
121
                            124 => '3',
122
                            125 => '3',
123
                            134 => '3',
124
                            136 => '3',
125
                            137 => '1',
126
                            140 => '3',
127
                            146 => '1',
128
                            148 => '1',
129
                        ],
130
                ],
131
                [
132
                    'path' => '{$path}log/src/LogStatic.php',
133
                    'package' => 'SimpleLog',
134
                    'namespace' => 'LogStatic',
135
                    'percent' => 100,
136
                    'info' => [
137
                            21 => '1',
138
                            23 => '1',
139
                            24 => '1',
140
                            35 => '1',
141
                            37 => '1',
142
                            38 => '1',
143
                            48 => '2',
144
                            50 => '2',
145
                            51 => '2',
146
                            60 => '2',
147
                            62 => '2',
148
                            63 => '2',
149
                            71 => '2',
150
                            73 => '2',
151
                            74 => '1',
152
                            76 => '2',
153
                        ],
154
                ],
155
                [
156
                    'path' => '{$path}log/src/DefaultJsonMessage.php',
157
                    'package' => 'SimpleLog\Message',
158
                    'namespace' => 'DefaultJsonMessage',
159
                    'percent' => 0,
160
                    'info' => [
161
                            18 => '0',
162
                            21 => '0',
163
                            26 => '0',
164
                            28 => '0',
165
                        ],
166
                ],
167
            ],
168
        ];
169
    }
170
}
171