Completed
Pull Request — master (#230)
by Juliette
03:24
created

DeprecatedNewReferenceSniffTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 22.64 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 12
loc 53
rs 10
c 0
b 0
f 0

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 new reference sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Deprecated new reference sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class DeprecatedNewReferenceSniffTest extends BaseSniffTest
17
{
18
    const TEST_FILE = 'sniff-examples/deprecated_new_reference.php';
19
20
    /**
21
     * testDeprecatedNewReference
22
     *
23
     * @dataProvider dataDeprecatedNewReference
24
     *
25
     * @param int $line The line number.
26
     *
27
     * @return void
28
     */
29
    public function testDeprecatedNewReference($line)
30
    {
31
        $file = $this->sniffFile(self::TEST_FILE, '5.2');
32
        $this->assertNoViolation($file, $line);
33
34
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
35
        $this->assertWarning($file, $line, 'Assigning the return value of new by reference is deprecated in PHP 5.3');
36
37
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
38
        $this->assertError($file, $line, 'Assigning the return value of new by reference is deprecated in PHP 5.3 and forbidden in PHP 7.0');
39
40
    }
41
42
    /**
43
     * Data provider.
44
     *
45
     * @see testDeprecatedNewReference()
46
     *
47
     * @return array
48
     */
49
    public function dataDeprecatedNewReference()
50
    {
51
        return array(
52
            array(9),
53
            array(10),
54
        );
55
    }
56
57
    /**
58
     * testNoReference
59
     *
60
     * @return void
61
     */
62
    public function testNoReference()
63
    {
64
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
65
        $this->assertNoViolation($file, 8);
66
    }
67
68
}
69