Completed
Push — master ( 8571e4...1f0247 )
by Juliette
9s
created

ConstantArraysUsingDefineSniffTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 1
dl 8
loc 72
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstantArraysUsingDefine() 8 8 1
A dataConstantArraysUsingDefine() 0 7 1
A testNoViolation() 0 5 1
A dataNoViolation() 0 6 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
 * Constant arrays using define in PHP 7.0 sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Constant arrays using define in PHP 7.0 sniff test file
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class ConstantArraysUsingDefineSniffTest  extends BaseSniffTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
17
{
18
    const TEST_FILE = 'sniff-examples/constant_arrays_using_define.php';
19
20
    /**
21
     * Verify that checking for a specific version works
22
     *
23
     * @group constantArraysUsingDefine
24
     *
25
     * @dataProvider dataConstantArraysUsingDefine
26
     *
27
     * @param int $line The line number.
28
     *
29
     * @return void
30
     */
31 View Code Duplication
    public function testConstantArraysUsingDefine($line)
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...
32
    {
33
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
34
        $this->assertNoViolation($file, $line);
35
36
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
37
        $this->assertError($file, $line, 'Constant arrays using define are not allowed in PHP 5.6 or earlier');
38
    }
39
40
    /**
41
     * Data provider dataConstantArraysUsingDefine.
42
     *
43
     * @see testConstantArraysUsingDefine()
44
     *
45
     * @return array
46
     */
47
    public function dataConstantArraysUsingDefine()
48
    {
49
        return array(
50
            array(3),
51
            array(9),
52
        );
53
    }
54
55
56
    /**
57
     * testNoViolation
58
     *
59
     * @group constantArraysUsingDefine
60
     *
61
     * @dataProvider dataNoViolation
62
     *
63
     * @param int $line The line number.
64
     *
65
     * @return void
66
     */
67
    public function testNoViolation($line)
68
    {
69
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
70
        $this->assertNoViolation($file, $line);
71
    }
72
73
    /**
74
     * Data provider.
75
     *
76
     * @see testNoViolation()
77
     *
78
     * @return array
79
     */
80
    public function dataNoViolation()
81
    {
82
        return array(
83
            array(15),
84
        );
85
    }
86
87
}
88