From 093ec1b7b6d305b09bae8c927c550d8b4bcd3e61 Mon Sep 17 00:00:00 2001 From: George Mponos Date: Tue, 16 Oct 2018 00:20:08 +0300 Subject: [PATCH] Added arrays to test cases --- .../EnforceYodaConditionsSniff.php | 2 +- .../DisallowYodaConditionsUnitTest.inc | 21 +++++++++++++++++++ .../DisallowYodaConditionsUnitTest.php | 11 +++++++--- .../EnforceYodaConditionsUnitTest.inc | 21 +++++++++++++++++++ .../EnforceYodaConditionsUnitTest.php | 9 ++++++-- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/Standards/Generic/Sniffs/ControlStructures/EnforceYodaConditionsSniff.php b/src/Standards/Generic/Sniffs/ControlStructures/EnforceYodaConditionsSniff.php index 80a7703548..86123914f8 100644 --- a/src/Standards/Generic/Sniffs/ControlStructures/EnforceYodaConditionsSniff.php +++ b/src/Standards/Generic/Sniffs/ControlStructures/EnforceYodaConditionsSniff.php @@ -45,7 +45,7 @@ public function process(File $phpcsFile, $stackPtr) if (in_array( $tokens[$nextIndex]['code'], [ - T_CLOSE_SHORT_ARRAY, + T_OPEN_SHORT_ARRAY, T_TRUE, T_FALSE, T_NULL, diff --git a/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc b/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc index cb1b489b98..961d0df2ef 100644 --- a/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc +++ b/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.inc @@ -30,12 +30,33 @@ if($value == null){} if(null === $value){} if(null == $value){} +if( + $value + === + null +){} +if( + null + === + $value +){} + // check string comparison if($value === 'string'){} if($value == 'string'){} if('string' === $value){} if('string' == $value){} +if([] === $value){} +if($value === [] ){} +if([] == $value){} +if($value == [] ){} + +if($value === array()){} +if($value == array()){} +if(array() === $value){} +if(array() == $value){} + // check string comparison $assigned = $value === 'string'; $assigned = 'string' == $value; \ No newline at end of file diff --git a/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.php b/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.php index ec48958b2b..49547a81fd 100644 --- a/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.php +++ b/src/Standards/Generic/Tests/ControlStructures/DisallowYodaConditionsUnitTest.php @@ -34,9 +34,14 @@ public function getErrorList() 19 => 1, 30 => 1, 31 => 1, - 36 => 1, - 37 => 1, - 41 => 1, + 40 => 1, + 47 => 1, + 48 => 1, + 50 => 1, + 52 => 1, + 57 => 1, + 58 => 1, + 62 => 1, ]; }//end getErrorList() diff --git a/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.inc b/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.inc index cb1b489b98..4bb55ece8e 100644 --- a/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.inc +++ b/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.inc @@ -30,12 +30,33 @@ if($value == null){} if(null === $value){} if(null == $value){} +if( + $value + === + null +){} +if( + null + === + $value +){} + // check string comparison if($value === 'string'){} if($value == 'string'){} if('string' === $value){} if('string' == $value){} +if([] === $value){} +if($value === [] ){} +if([] == $value){} +if($value == [] ){} + +if($value === array()){} +if($value == array()){} +if(array() === $value){} +if(array() == $value){} + // check string comparison $assigned = $value === 'string'; $assigned = 'string' == $value; \ No newline at end of file diff --git a/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.php b/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.php index 4874d470f8..1f9e18afa8 100644 --- a/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.php +++ b/src/Standards/Generic/Tests/ControlStructures/EnforceYodaConditionsUnitTest.php @@ -34,9 +34,14 @@ public function getErrorList() 17 => 1, 28 => 1, 29 => 1, - 34 => 1, 35 => 1, - 40 => 1, + 45 => 1, + 46 => 1, + 51 => 1, + 53 => 1, + 55 => 1, + 56 => 1, + 61 => 1, ]; }//end getErrorList()