|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* New constructs sniff test file |
|
4
|
|
|
* |
|
5
|
|
|
* @package PHPCompatibility |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* New constructs sniff tests |
|
11
|
|
|
* |
|
12
|
|
|
* @uses BaseSniffTest |
|
13
|
|
|
* @package PHPCompatibility |
|
14
|
|
|
* @author Jansen Price <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class NewConstructsSniffTest extends BaseSniffTest |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* testNamespaceSeparator |
|
20
|
|
|
* |
|
21
|
|
|
* @return void |
|
22
|
|
|
*/ |
|
23
|
|
|
public function testNamespaceSeparator() |
|
24
|
|
|
{ |
|
25
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.2'); |
|
26
|
|
|
$this->assertError($file, 3, 'the \ operator (for namespaces) is not present in PHP version 5.2 or earlier'); |
|
27
|
|
|
|
|
28
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.3'); |
|
29
|
|
|
$this->assertNoViolation($file, 3); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* testPow |
|
34
|
|
|
* |
|
35
|
|
|
* @requires PHP 5.6 |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testPow() |
|
39
|
|
|
{ |
|
40
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.5'); |
|
41
|
|
|
$this->assertError($file, 5, "power operator (**) is not present in PHP version 5.5 or earlier"); |
|
42
|
|
|
|
|
43
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.6'); |
|
44
|
|
|
$this->assertNoViolation($file, 5); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* testPowEquals |
|
49
|
|
|
* |
|
50
|
|
|
* @requires PHP 5.6 |
|
51
|
|
|
* @return void |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testPowEquals() |
|
54
|
|
|
{ |
|
55
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.5'); |
|
56
|
|
|
$this->assertError($file, 6, "power assignment operator (**=) is not present in PHP version 5.5 or earlier"); |
|
57
|
|
|
|
|
58
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.6'); |
|
59
|
|
|
$this->assertNoViolation($file, 6); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* testSpaceship |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testSpaceship() |
|
68
|
|
|
{ |
|
69
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.6'); |
|
70
|
|
|
$this->assertError($file, 12, "spaceship operator (<=>) is not present in PHP version 5.6 or earlier"); |
|
71
|
|
|
|
|
72
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '7.0'); |
|
73
|
|
|
$this->assertNoViolation($file, 12); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Coalescing operator |
|
78
|
|
|
* |
|
79
|
|
|
* @return void |
|
80
|
|
|
*/ |
|
81
|
|
View Code Duplication |
public function testCoalescing() |
|
|
|
|
|
|
82
|
|
|
{ |
|
83
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '5.6'); |
|
84
|
|
|
$this->assertError($file, 8, "null coalescing operator (??) is not present in PHP version 5.6 or earlier"); |
|
85
|
|
|
$this->assertError($file, 10, "null coalescing operator (??) is not present in PHP version 5.6 or earlier"); |
|
86
|
|
|
|
|
87
|
|
|
$file = $this->sniffFile('sniff-examples/new_constructs.php', '7.0'); |
|
88
|
|
|
$this->assertNoViolation($file, 8); |
|
89
|
|
|
$this->assertNoViolation($file, 10); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
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.