Completed
Push — master ( 81b91c...01d73e )
by Juliette
9s
created

NewFunctionArrayDereferencingSniffTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testArrayDereferencing() 8 8 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
 * New function array dereferencing sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New function array dereferencing sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class NewFunctionArrayDereferencingSniffTest 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...
17
{
18
    const TEST_FILE = 'sniff-examples/new_function_array_dereferencing.php';
19
20
    /**
21
     * testArrayDereferencing
22
     *
23
     * @group functionArrayDereferencing
24
     *
25
     * @return void
26
     */
27 View Code Duplication
    public function testArrayDereferencing()
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...
28
    {
29
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
30
        $this->assertError($file, 3, 'Function array dereferencing is not present in PHP version 5.3 or earlier');
31
32
        $file = $this->sniffFile(self::TEST_FILE, '5.4');
33
        $this->assertNoViolation($file, 3);
34
    }
35
36
37
    /**
38
     * testNoViolation
39
     *
40
     * @group functionArrayDereferencing
41
     *
42
     * @dataProvider dataNoViolation
43
     *
44
     * @param int $line Line number with valid code.
45
     *
46
     * @return void
47
     */
48
    public function testNoViolation($line)
49
    {
50
        $file = $this->sniffFile(self::TEST_FILE);
51
        $this->assertNoViolation($file, $line);
52
    }
53
54
    /**
55
     * dataNoViolation
56
     *
57
     * @see testNoViolation()
58
     *
59
     * @return array
60
     */
61
    public function dataNoViolation() {
62
        return array(
63
            array(5),
64
            array(6),
65
        );
66
    }
67
}
68