Skip to content

Commit 093ec1b

Browse files
committed
Added arrays to test cases
1 parent bb4a456 commit 093ec1b

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

src/Standards/Generic/Sniffs/ControlStructures/EnforceYodaConditionsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr)
4545
if (in_array(
4646
$tokens[$nextIndex]['code'],
4747
[
48-
T_CLOSE_SHORT_ARRAY,
48+
T_OPEN_SHORT_ARRAY,
4949
T_TRUE,
5050
T_FALSE,
5151
T_NULL,

src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,33 @@ if($value == null){}
3030
if(null === $value){}
3131
if(null == $value){}
3232

33+
if(
34+
$value
35+
===
36+
null
37+
){}
38+
if(
39+
null
40+
===
41+
$value
42+
){}
43+
3344
// check string comparison
3445
if($value === 'string'){}
3546
if($value == 'string'){}
3647
if('string' === $value){}
3748
if('string' == $value){}
3849

50+
if([] === $value){}
51+
if($value === [] ){}
52+
if([] == $value){}
53+
if($value == [] ){}
54+
55+
if($value === array()){}
56+
if($value == array()){}
57+
if(array() === $value){}
58+
if(array() == $value){}
59+
3960
// check string comparison
4061
$assigned = $value === 'string';
4162
$assigned = 'string' == $value;

src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public function getErrorList()
3434
19 => 1,
3535
30 => 1,
3636
31 => 1,
37-
36 => 1,
38-
37 => 1,
39-
41 => 1,
37+
40 => 1,
38+
47 => 1,
39+
48 => 1,
40+
50 => 1,
41+
52 => 1,
42+
57 => 1,
43+
58 => 1,
44+
62 => 1,
4045
];
4146

4247
}//end getErrorList()

src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.inc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,33 @@ if($value == null){}
3030
if(null === $value){}
3131
if(null == $value){}
3232

33+
if(
34+
$value
35+
===
36+
null
37+
){}
38+
if(
39+
null
40+
===
41+
$value
42+
){}
43+
3344
// check string comparison
3445
if($value === 'string'){}
3546
if($value == 'string'){}
3647
if('string' === $value){}
3748
if('string' == $value){}
3849

50+
if([] === $value){}
51+
if($value === [] ){}
52+
if([] == $value){}
53+
if($value == [] ){}
54+
55+
if($value === array()){}
56+
if($value == array()){}
57+
if(array() === $value){}
58+
if(array() == $value){}
59+
3960
// check string comparison
4061
$assigned = $value === 'string';
4162
$assigned = 'string' == $value;

src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ public function getErrorList()
3434
17 => 1,
3535
28 => 1,
3636
29 => 1,
37-
34 => 1,
3837
35 => 1,
39-
40 => 1,
38+
45 => 1,
39+
46 => 1,
40+
51 => 1,
41+
53 => 1,
42+
55 => 1,
43+
56 => 1,
44+
61 => 1,
4045
];
4146

4247
}//end getErrorList()

0 commit comments

Comments
 (0)