BlankLineBeforeElseBlockFixerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 136
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testFix() 4 4 1
B provideFixCases() 80 80 1
A shouldHaveAFixerDefinition() 24 24 1
A shouldHaveTheRightPriority() 4 4 1
A createFixer() 4 4 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
/*
4
 * This file is part of PHP CS Fixer.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *     Dariusz Rumiński <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Addiks\MorePhpCsFixers\Tests\Unit\Whitespace;
14
15
use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
16
use Addiks\MorePhpCsFixers\Whitespace\BlankLineBeforeElseBlockFixer;
17
use PhpCsFixer\FixerDefinition\FixerDefinition;
18
use PhpCsFixer\FixerDefinition\CodeSample;
19
20
/**
21
 * @internal
22
 */
23 View Code Duplication
final class BlankLineBeforeElseBlockFixerTest extends AbstractFixerTestCase
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...
24
{
25
    /**
26
     * @param string      $expected
27
     * @param null|string $input
28
     *
29
     * @dataProvider provideFixCases
30
     */
31
    public function testFix($expected, $input = null)
32
    {
33
        $this->doTest($expected, $input);
34
    }
35
36
    public function provideFixCases()
37
    {
38
        return [
39
            [
40
                '<?php
41
if ($a) {
42
    foo();
43
44
} elseif ($b) {
45
    bar();
46
47
} else {
48
    baz();
49
}',
50
            ],
51
            [
52
                '<?php
53
if ($a) {
54
    foo();
55
56
} elseif ($b) {
57
    bar();
58
59
} else {
60
    baz();
61
}',
62
                '<?php
63
if ($a) {
64
    foo();
65
} elseif ($b) {
66
    bar();
67
} else {
68
    baz();
69
}',
70
            ],
71
            [
72
                '<?php
73
    if ($a) {
74
        foo();
75
76
    } elseif ($b) {
77
        bar();
78
79
    } else {
80
        baz();
81
    }',
82
                '<?php
83
    if ($a) {
84
        foo();
85
    } elseif ($b) {
86
        bar();
87
    } else {
88
        baz();
89
    }',
90
            ],
91
            [
92
                '<?php
93
if ($a) {
94
    foo();
95
96
/* Lorem ipsum */} elseif ($b) {
97
    bar();
98
99
} else {
100
    baz();
101
}',
102
                '<?php
103
if ($a) {
104
    foo();
105
/* Lorem ipsum */} elseif ($b) {
106
    bar();
107
} else {
108
    baz();
109
}',
110
            ],
111
            [
112
                '<?php if ($a) {foo();} elseif ($b) {bar();} else {baz();}',
113
            ],
114
        ];
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function shouldHaveAFixerDefinition()
121
    {
122
        $this->assertEquals(
123
            new FixerDefinition(
124
                'An empty line feed must precede any else or elseif codeblock.',
125
                [
126
                    new CodeSample(
127
                        '<?php
128
if ($a) {
129
    foo();
130
131
} elseif ($b) {
132
    bar();
133
134
} else {
135
    baz();
136
}
137
'
138
                    ),
139
                ]
140
            ),
141
            $this->createFixer()->getDefinition()
142
        );
143
    }
144
145
    /**
146
     * @test
147
     */
148
    public function shouldHaveTheRightPriority()
149
    {
150
        $this->assertEquals(-26, $this->createFixer()->getPriority());
151
    }
152
153
    protected function createFixer()
154
    {
155
        return new BlankLineBeforeElseBlockFixer();
156
    }
157
158
}
159