Completed
Push — master ( 695a68...adab54 )
by Juliette
11s
created

dataNoViolation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
/**
3
 * Forbidden call time pass by reference sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Forbidden call time pass by reference sniff test
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class ForbiddenCallTimePassByReferenceSniffTest 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/call_time_pass_by_reference.php';
19
20
    /**
21
     * Sniffed file
22
     *
23
     * @var PHP_CodeSniffer_File
24
     */
25
    protected $_sniffFile;
26
27
    /**
28
     * setUp
29
     *
30
     * @return void
31
     */
32
    public function setUp()
33
    {
34
        parent::setUp();
35
36
        $this->_sniffFile = $this->sniffFile(self::TEST_FILE);
37
    }
38
39
40
    /**
41
     * testForbiddenCallTimePassByReference
42
     *
43
     * @group forbiddenCallTimePassByReference
44
     *
45
     * @dataProvider dataForbiddenCallTimePassByReference
46
     *
47
     * @param int    $line  Line number where the error should occur.
48
     *
49
     * @return void
50
     */
51
    public function testForbiddenCallTimePassByReference($line)
52
    {
53
        $file = $this->sniffFile(self::TEST_FILE, '5.2');
54
        $this->assertNoViolation($file, $line);
55
56
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
57
        $this->assertError($file, $line, 'Using a call-time pass-by-reference is deprecated since PHP 5.3');
58
59
        $file = $this->sniffFile(self::TEST_FILE, '5.4');
60
        $this->assertError($file, $line, 'Using a call-time pass-by-reference is deprecated since PHP 5.3 and prohibited since PHP 5.4');
61
    }
62
63
    /**
64
     * dataForbiddenCallTimePassByReference
65
     *
66
     * @see testForbiddenCallTimePassByReference()
67
     *
68
     * @return array
69
     */
70 View Code Duplication
    public function dataForbiddenCallTimePassByReference() {
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...
71
        return array(
72
            array(10), // Bad: call time pass by reference.
73
            array(14), // Bad: call time pass by reference with multi-parameter call.
74
            array(17), // Bad: nested call time pass by reference.
75
            array(25), // Bad: call time pass by reference with space.
76
            array(44), // Bad: call time pass by reference.
77
            array(45), // Bad: call time pass by reference.
78
            array(49), // Bad: multiple call time pass by reference.
79
        );
80
    }
81
82
83
    /**
84
     * testNoViolation
85
     *
86
     * @group forbiddenCallTimePassByReference
87
     *
88
     * @dataProvider dataNoViolation
89
     *
90
     * @param int $line The line number.
91
     *
92
     * @return void
93
     */
94
    public function testNoViolation($line)
95
    {
96
        $this->assertNoViolation($this->_sniffFile, $line);
97
    }
98
99
    /**
100
     * Data provider.
101
     *
102
     * @see testNoViolation()
103
     *
104
     * @return array
105
     */
106 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...
107
    {
108
        return array(
109
            array(4), // OK: Declaring a parameter by reference.
110
            array(9), // OK: Call time passing without reference.
111
112
            // OK: Bitwise operations as parameter.
113
            array(20),
114
            array(21),
115
            array(22),
116
            array(23),
117
            array(24),
118
            array(39),
119
            array(40),
120
            //array(41), // Currently not yet covered.
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
122
            array(51), // OK: No variables.
123
            array(51), // OK: Outside scope of this sniff.
124
        );
125
    }
126
127
}
128
129