Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Operators; use PHP_CodeSniffer\Fil..

Decoded Output download

<?php
 namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Operators; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; class ComparisonOperatorUsageSniff implements Sniff { public $supportedTokenizers = array("PHP", "JS"); private static $validOps = array(T_IS_IDENTICAL => true, T_IS_NOT_IDENTICAL => true, T_LESS_THAN => true, T_GREATER_THAN => true, T_IS_GREATER_OR_EQUAL => true, T_IS_SMALLER_OR_EQUAL => true, T_INSTANCEOF => true); private static $invalidOps = array("PHP" => array(T_IS_EQUAL => "===", T_IS_NOT_EQUAL => "!==", T_BOOLEAN_NOT => "=== FALSE"), "JS" => array(T_IS_EQUAL => "===", T_IS_NOT_EQUAL => "!==")); public function register() { return array(T_IF, T_ELSEIF, T_INLINE_THEN, T_WHILE, T_FOR); } public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $tokenizer = $phpcsFile->tokenizerType; if ($tokens[$stackPtr]["code"] === T_INLINE_THEN) { $end = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true); if ($tokens[$end]["code"] !== T_CLOSE_PARENTHESIS) { for ($i = $end - 1; $i >= 0; $i--) { if ($tokens[$i]["code"] === T_SEMICOLON) { break; } else { if ($tokens[$i]["code"] === T_OPEN_TAG) { break; } else { if ($tokens[$i]["code"] === T_CLOSE_CURLY_BRACKET) { if (isset($tokens[$i]["scope_opener"]) === true) { break; } } else { if ($tokens[$i]["code"] === T_OPEN_CURLY_BRACKET) { if (isset($tokens[$i]["scope_closer"]) === true) { break; } } else { if ($tokens[$i]["code"] === T_OPEN_PARENTHESIS) { if (isset($tokens[$i]["parenthesis_closer"]) === true && $tokens[$i]["parenthesis_closer"] >= $stackPtr) { break; } } } } } } } $start = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, null, true); } else { if (isset($tokens[$end]["parenthesis_opener"]) === false) { return; } $start = $tokens[$end]["parenthesis_opener"]; } } else { if ($tokens[$stackPtr]["code"] === T_FOR) { if (isset($tokens[$stackPtr]["parenthesis_opener"]) === false) { return; } $openingBracket = $tokens[$stackPtr]["parenthesis_opener"]; $closingBracket = $tokens[$stackPtr]["parenthesis_closer"]; $start = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket); $end = $phpcsFile->findNext(T_SEMICOLON, $start + 1, $closingBracket); if ($start === false || $end === false) { return; } } else { if (isset($tokens[$stackPtr]["parenthesis_opener"]) === false) { return; } $start = $tokens[$stackPtr]["parenthesis_opener"]; $end = $tokens[$stackPtr]["parenthesis_closer"]; } } $requiredOps = 0; $foundOps = 0; $foundBooleans = 0; $lastNonEmpty = $start; for ($i = $start; $i <= $end; $i++) { $type = $tokens[$i]["code"]; if (isset(self::$invalidOps[$tokenizer][$type]) === true) { $error = "Operator %s prohibited; use %s instead"; $data = array($tokens[$i]["content"], self::$invalidOps[$tokenizer][$type]); $phpcsFile->addError($error, $i, "NotAllowed", $data); $foundOps++; } else { if (isset(self::$validOps[$type]) === true) { $foundOps++; } } if ($type === T_OPEN_PARENTHESIS && isset($tokens[$i]["parenthesis_closer"]) === true && isset(Tokens::$functionNameTokens[$tokens[$lastNonEmpty]["code"]]) === true) { $i = $tokens[$i]["parenthesis_closer"]; $lastNonEmpty = $i; continue; } if ($tokens[$i]["code"] === T_TRUE || $tokens[$i]["code"] === T_FALSE) { $foundBooleans++; } if ($phpcsFile->tokenizerType !== "JS" && ($tokens[$i]["code"] === T_BOOLEAN_AND || $tokens[$i]["code"] === T_BOOLEAN_OR)) { $requiredOps++; if ($foundOps > $requiredOps) { $foundOps = $requiredOps; } if ($requiredOps !== $foundOps) { $error = "Implicit true comparisons prohibited; use === TRUE instead"; $phpcsFile->addError($error, $stackPtr, "ImplicitTrue"); $foundOps++; } } if (isset(Tokens::$emptyTokens[$type]) === false) { $lastNonEmpty = $i; } } $requiredOps++; if ($phpcsFile->tokenizerType !== "JS" && $foundOps < $requiredOps && $requiredOps !== $foundBooleans) { $error = "Implicit true comparisons prohibited; use === TRUE instead"; $phpcsFile->addError($error, $stackPtr, "ImplicitTrue"); } } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Operators; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; class ComparisonOperatorUsageSniff implements Sniff { public $supportedTokenizers = array("\x50\x48\120", "\x4a\x53"); private static $validOps = array(T_IS_IDENTICAL => true, T_IS_NOT_IDENTICAL => true, T_LESS_THAN => true, T_GREATER_THAN => true, T_IS_GREATER_OR_EQUAL => true, T_IS_SMALLER_OR_EQUAL => true, T_INSTANCEOF => true); private static $invalidOps = array("\x50\x48\120" => array(T_IS_EQUAL => "\75\x3d\75", T_IS_NOT_EQUAL => "\x21\75\75", T_BOOLEAN_NOT => "\75\x3d\x3d\x20\x46\x41\x4c\123\105"), "\112\x53" => array(T_IS_EQUAL => "\x3d\x3d\75", T_IS_NOT_EQUAL => "\x21\x3d\x3d")); public function register() { return array(T_IF, T_ELSEIF, T_INLINE_THEN, T_WHILE, T_FOR); } public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $tokenizer = $phpcsFile->tokenizerType; if ($tokens[$stackPtr]["\143\157\x64\x65"] === T_INLINE_THEN) { $end = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true); if ($tokens[$end]["\143\x6f\144\145"] !== T_CLOSE_PARENTHESIS) { for ($i = $end - 1; $i >= 0; $i--) { if ($tokens[$i]["\143\x6f\x64\x65"] === T_SEMICOLON) { break; } else { if ($tokens[$i]["\x63\x6f\x64\145"] === T_OPEN_TAG) { break; } else { if ($tokens[$i]["\143\x6f\144\x65"] === T_CLOSE_CURLY_BRACKET) { if (isset($tokens[$i]["\x73\143\x6f\160\145\x5f\x6f\x70\x65\156\145\162"]) === true) { break; } } else { if ($tokens[$i]["\143\x6f\144\x65"] === T_OPEN_CURLY_BRACKET) { if (isset($tokens[$i]["\x73\x63\x6f\160\x65\x5f\x63\154\x6f\163\x65\x72"]) === true) { break; } } else { if ($tokens[$i]["\143\x6f\144\145"] === T_OPEN_PARENTHESIS) { if (isset($tokens[$i]["\160\x61\x72\145\156\x74\x68\145\x73\151\163\x5f\x63\x6c\157\x73\x65\x72"]) === true && $tokens[$i]["\160\141\162\145\156\164\x68\145\x73\151\163\137\143\x6c\x6f\x73\145\x72"] >= $stackPtr) { break; } } } } } } } $start = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, null, true); } else { if (isset($tokens[$end]["\x70\x61\162\x65\x6e\164\150\x65\x73\x69\x73\x5f\157\x70\x65\156\x65\162"]) === false) { return; } $start = $tokens[$end]["\x70\141\x72\x65\156\x74\150\x65\163\151\163\137\x6f\160\145\x6e\x65\x72"]; } } else { if ($tokens[$stackPtr]["\x63\157\x64\145"] === T_FOR) { if (isset($tokens[$stackPtr]["\x70\141\162\x65\156\164\x68\x65\x73\151\163\137\x6f\160\145\156\145\x72"]) === false) { return; } $openingBracket = $tokens[$stackPtr]["\160\x61\x72\x65\x6e\x74\150\x65\163\151\163\x5f\x6f\x70\x65\156\145\162"]; $closingBracket = $tokens[$stackPtr]["\160\x61\x72\x65\x6e\164\x68\145\163\151\163\x5f\143\x6c\157\x73\x65\x72"]; $start = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket); $end = $phpcsFile->findNext(T_SEMICOLON, $start + 1, $closingBracket); if ($start === false || $end === false) { return; } } else { if (isset($tokens[$stackPtr]["\x70\141\162\x65\x6e\x74\150\145\x73\151\163\137\157\x70\x65\156\145\162"]) === false) { return; } $start = $tokens[$stackPtr]["\x70\141\x72\x65\x6e\164\x68\145\x73\151\163\x5f\157\160\x65\x6e\145\162"]; $end = $tokens[$stackPtr]["\x70\141\162\145\156\x74\150\145\163\151\163\137\x63\x6c\157\163\x65\x72"]; } } $requiredOps = 0; $foundOps = 0; $foundBooleans = 0; $lastNonEmpty = $start; for ($i = $start; $i <= $end; $i++) { $type = $tokens[$i]["\143\x6f\x64\x65"]; if (isset(self::$invalidOps[$tokenizer][$type]) === true) { $error = "\x4f\x70\145\x72\141\164\157\x72\40\45\x73\40\x70\162\x6f\150\151\x62\151\x74\145\144\73\40\165\x73\145\x20\x25\163\x20\151\x6e\163\x74\x65\141\x64"; $data = array($tokens[$i]["\143\x6f\x6e\x74\x65\156\x74"], self::$invalidOps[$tokenizer][$type]); $phpcsFile->addError($error, $i, "\x4e\x6f\x74\101\x6c\x6c\157\167\145\144", $data); $foundOps++; } else { if (isset(self::$validOps[$type]) === true) { $foundOps++; } } if ($type === T_OPEN_PARENTHESIS && isset($tokens[$i]["\160\x61\x72\145\x6e\164\x68\x65\x73\x69\163\x5f\x63\154\x6f\x73\x65\x72"]) === true && isset(Tokens::$functionNameTokens[$tokens[$lastNonEmpty]["\143\x6f\x64\145"]]) === true) { $i = $tokens[$i]["\160\141\162\145\156\164\150\x65\163\x69\x73\137\x63\154\x6f\163\x65\162"]; $lastNonEmpty = $i; continue; } if ($tokens[$i]["\143\x6f\144\145"] === T_TRUE || $tokens[$i]["\143\x6f\144\145"] === T_FALSE) { $foundBooleans++; } if ($phpcsFile->tokenizerType !== "\x4a\123" && ($tokens[$i]["\143\x6f\144\145"] === T_BOOLEAN_AND || $tokens[$i]["\143\x6f\x64\145"] === T_BOOLEAN_OR)) { $requiredOps++; if ($foundOps > $requiredOps) { $foundOps = $requiredOps; } if ($requiredOps !== $foundOps) { $error = "\111\155\160\x6c\x69\143\151\164\40\164\x72\165\145\40\x63\x6f\155\160\141\x72\151\x73\x6f\x6e\163\x20\160\162\x6f\x68\x69\x62\151\x74\x65\x64\73\x20\165\x73\145\40\x3d\75\75\x20\124\122\x55\105\x20\x69\156\163\x74\x65\x61\x64"; $phpcsFile->addError($error, $stackPtr, "\111\155\160\154\151\x63\x69\x74\x54\x72\165\x65"); $foundOps++; } } if (isset(Tokens::$emptyTokens[$type]) === false) { $lastNonEmpty = $i; } } $requiredOps++; if ($phpcsFile->tokenizerType !== "\112\x53" && $foundOps < $requiredOps && $requiredOps !== $foundBooleans) { $error = "\111\x6d\160\154\x69\143\151\x74\x20\164\162\165\145\x20\143\x6f\155\160\141\162\151\163\x6f\156\x73\x20\x70\x72\x6f\x68\x69\x62\x69\164\145\144\x3b\x20\165\163\145\x20\75\75\x3d\40\124\122\x55\105\x20\151\x6e\x73\164\145\141\144"; $phpcsFile->addError($error, $stackPtr, "\x49\x6d\160\x6c\151\x63\x69\164\x54\x72\165\145"); } } }

Function Calls

None

Variables

None

Stats

MD5 3405064a80ece4924b4a40432d6d7638
Eval Count 0
Decode Time 100 ms