Completed
Push — master ( 01d73e...c6357c )
by Juliette
03:01
created

MbstringReplaceEModifierSniffTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 13.75 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 11
loc 80
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMbstringEModifier() 0 11 1
A dataMbstringEModifier() 0 8 1
A testNoViolation() 0 5 1
A dataNoViolation() 11 11 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
 * Deprecated Mbstring regex replace e modifier sniff test file.
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Deprecated Mbstring regex replace e modifier test file.
11
 *
12
 * @uses    BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author  Juliette Reinders Folmer <[email protected]>
15
 */
16
class MbstringReplaceEModifierSniffTest extends BaseSniffTest
17
{
18
    const TEST_FILE = 'sniff-examples/mbstring_replace_e_modifier.php';
19
20
    /**
21
     * testMbstringEModifier
22
     *
23
     * @group mbstringEModifier
24
     *
25
     * @dataProvider dataMbstringEModifier
26
     *
27
     * @param int $line The line number.
28
     *
29
     * @return void
30
     */
31
    public function testMbstringEModifier($line)
32
    {
33
        $file = $this->sniffFile(self::TEST_FILE, '5.4');
34
        $this->assertNoViolation($file, $line);
35
36
        $file = $this->sniffFile(self::TEST_FILE, '5.3-7.1');
37
        $this->assertError($file, $line, 'The Mbstring regex "e" modifier is deprecated since PHP 7.1.');
38
39
        $file = $this->sniffFile(self::TEST_FILE, '7.1');
40
        $this->assertError($file, $line, 'The Mbstring regex "e" modifier is deprecated since PHP 7.1. Use mb_ereg_replace_callback() instead (PHP 5.4.1+).');
41
    }
42
43
    /**
44
     * Data provider.
45
     *
46
     * @see testMbstringEModifier()
47
     *
48
     * @return array
49
     */
50
    public function dataMbstringEModifier()
51
    {
52
        return array(
53
            array(14),
54
            array(15),
55
            array(16),
56
        );
57
    }
58
59
60
    /**
61
     * testNoViolation
62
     *
63
     * @group mbstringEModifier
64
     *
65
     * @dataProvider dataNoViolation
66
     *
67
     * @param int $line The line number.
68
     *
69
     * @return void
70
     */
71
    public function testNoViolation($line)
72
    {
73
        $file = $this->sniffFile(self::TEST_FILE, '7.1');
74
        $this->assertNoViolation($file, $line);
75
    }
76
77
    /**
78
     * Data provider.
79
     *
80
     * @see testNoViolation()
81
     *
82
     * @return array
83
     */
84 View Code Duplication
    public function dataNoViolation()
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...
85
    {
86
        return array(
87
            array(4),
88
            array(5),
89
            array(6),
90
            array(9),
91
            array(10),
92
            array(11),
93
        );
94
    }
95
}
96