Skip to content

Commit

Permalink
WIP work
Browse files Browse the repository at this point in the history
  • Loading branch information
gmponos committed Nov 12, 2018
1 parent db6b2bb commit 82f63e0
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,32 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

$skipTokens = array_merge(
[
T_CLOSE_PARENTHESIS => T_CLOSE_PARENTHESIS,
T_OPEN_PARENTHESIS => T_OPEN_PARENTHESIS,
],
Tokens::$emptyTokens
);

$previousIndex = $phpcsFile->findPrevious($skipTokens, ($stackPtr - 1), null, true);
if ($previousIndex === false) {
return;
}

if (in_array(
$previousIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($previousIndex === false || in_array(
$tokens[$previousIndex]['code'],
[
T_VARIABLE,
T_STRING,
],
true
) === false
) === true
) {
$phpcsFile->addError(
'Usage of Yoda conditions is not allowed. Switch the expression order.',
$stackPtr,
'DisallowYodaCondition'
);
return;
}

if ($tokens[$previousIndex]['code'] === T_CLOSE_PARENTHESIS) {
$found = $phpcsFile->findPrevious([T_VARIABLE], ($previousIndex - 1), $tokens[$previousIndex]['parenthesis_opener']);
if ($found !== false) {
return;
}
}

$phpcsFile->addError(
'Usage of Yoda conditions is not allowed. Switch the expression order.',
$stackPtr,
'DisallowYodaCondition'
);

}//end process()


Expand Down

0 comments on commit 82f63e0

Please sign in to comment.