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\PEAR\Sniffs\Functions; use PHP_CodeSniffer\File..
Decoded Output download
<?php
namespace PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; class FunctionCallSignatureSniff implements Sniff { public $supportedTokenizers = array("PHP", "JS"); public $indent = 4; public $allowMultipleArguments = true; public $requiredSpacesAfterOpen = 0; public $requiredSpacesBeforeClose = 0; public function register() { $tokens = Tokens::$functionNameTokens; $tokens[] = T_VARIABLE; $tokens[] = T_CLOSE_CURLY_BRACKET; $tokens[] = T_CLOSE_SQUARE_BRACKET; $tokens[] = T_CLOSE_PARENTHESIS; return $tokens; } public function process(File $phpcsFile, $stackPtr) { $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]["code"] === T_CLOSE_CURLY_BRACKET && isset($tokens[$stackPtr]["scope_condition"]) === true) { return; } $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); if ($tokens[$openBracket]["code"] !== T_OPEN_PARENTHESIS) { return; } if (isset($tokens[$openBracket]["parenthesis_closer"]) === false) { return; } $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious($search, $stackPtr - 1, null, true); if ($tokens[$previous]["code"] === T_FUNCTION) { return; } $closeBracket = $tokens[$openBracket]["parenthesis_closer"]; if ($stackPtr + 1 !== $openBracket) { $error = "Space before opening parenthesis of function call prohibited"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "SpaceBeforeOpenBracket"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($i = $stackPtr + 1; $i < $openBracket; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->replaceToken($openBracket, "("); $phpcsFile->fixer->endChangeset(); } } $next = $phpcsFile->findNext(T_WHITESPACE, $closeBracket + 1, null, true); if ($tokens[$next]["code"] === T_SEMICOLON) { if (isset(Tokens::$emptyTokens[$tokens[$closeBracket + 1]["code"]]) === true) { $error = "Space after closing parenthesis of function call prohibited"; $fix = $phpcsFile->addFixableError($error, $closeBracket, "SpaceAfterCloseBracket"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($i = $closeBracket + 1; $i < $next; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->replaceToken($closeBracket, ")"); $phpcsFile->fixer->endChangeset(); } } } if ($this->isMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens) === true) { $this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); } else { $this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); } } public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $closeBracket = $tokens[$openBracket]["parenthesis_closer"]; if ($tokens[$openBracket]["line"] !== $tokens[$closeBracket]["line"]) { return true; } return false; } public function processSingleLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $closer = $tokens[$openBracket]["parenthesis_closer"]; if ($openBracket === $closer - 1) { return; } $next = $phpcsFile->findNext(T_WHITESPACE, $openBracket + 1, $closer, true); if ($next === false) { $requiredSpacesAfterOpen = 0; $requiredSpacesBeforeClose = 0; } else { $requiredSpacesAfterOpen = $this->requiredSpacesAfterOpen; $requiredSpacesBeforeClose = $this->requiredSpacesBeforeClose; } if ($requiredSpacesAfterOpen === 0 && $tokens[$openBracket + 1]["code"] === T_WHITESPACE) { $error = "Space after opening parenthesis of function call prohibited"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "SpaceAfterOpenBracket"); if ($fix === true) { $phpcsFile->fixer->replaceToken($openBracket + 1, ''); } } else { if ($requiredSpacesAfterOpen > 0) { $spaceAfterOpen = 0; if ($tokens[$openBracket + 1]["code"] === T_WHITESPACE) { $spaceAfterOpen = $tokens[$openBracket + 1]["length"]; } if ($spaceAfterOpen !== $requiredSpacesAfterOpen) { $error = "Expected %s spaces after opening parenthesis; %s found"; $data = array($requiredSpacesAfterOpen, $spaceAfterOpen); $fix = $phpcsFile->addFixableError($error, $stackPtr, "SpaceAfterOpenBracket", $data); if ($fix === true) { $padding = str_repeat(" ", $requiredSpacesAfterOpen); if ($spaceAfterOpen === 0) { $phpcsFile->fixer->addContent($openBracket, $padding); } else { $phpcsFile->fixer->replaceToken($openBracket + 1, $padding); } } } } } $spaceBeforeClose = 0; $prev = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, $openBracket, true); if ($tokens[$prev]["code"] === T_END_HEREDOC || $tokens[$prev]["code"] === T_END_NOWDOC) { return; } if ($tokens[$prev]["line"] !== $tokens[$closer]["line"]) { $spaceBeforeClose = "newline"; } else { if ($tokens[$closer - 1]["code"] === T_WHITESPACE) { $spaceBeforeClose = $tokens[$closer - 1]["length"]; } } if ($spaceBeforeClose !== $requiredSpacesBeforeClose) { $error = "Expected %s spaces before closing parenthesis; %s found"; $data = array($requiredSpacesBeforeClose, $spaceBeforeClose); $fix = $phpcsFile->addFixableError($error, $closer, "SpaceBeforeCloseBracket", $data); if ($fix === true) { $padding = str_repeat(" ", $requiredSpacesBeforeClose); if ($spaceBeforeClose === 0) { $phpcsFile->fixer->addContentBefore($closer, $padding); } else { if ($spaceBeforeClose === "newline") { $phpcsFile->fixer->beginChangeset(); $closingContent = ")"; $next = $phpcsFile->findNext(T_WHITESPACE, $closer + 1, null, true); if ($tokens[$next]["code"] === T_SEMICOLON) { $closingContent .= ";"; for ($i = $closer + 1; $i <= $next; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } } $prev = $closer - 1; while (isset(Tokens::$emptyTokens[$tokens[$prev]["code"]]) === true) { if ($tokens[$prev]["code"] === T_COMMENT && strpos($tokens[$prev]["content"], "*/") !== false) { break; } $prev--; } $phpcsFile->fixer->addContent($prev, $padding . $closingContent); $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, null, true); for ($i = $prevNonWhitespace + 1; $i <= $closer; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } else { $phpcsFile->fixer->replaceToken($closer - 1, $padding); } } } } } public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); if ($tokens[$first]["code"] === T_CONSTANT_ENCAPSED_STRING && $tokens[$first - 1]["code"] === T_CONSTANT_ENCAPSED_STRING) { $prev = $phpcsFile->findPrevious(T_CONSTANT_ENCAPSED_STRING, $first - 2, null, true); $first = $phpcsFile->findFirstOnLine(Tokens::$emptyTokens, $prev, true); if ($first === false) { $first = $prev + 1; } } $foundFunctionIndent = 0; if ($first !== false) { if ($tokens[$first]["code"] === T_INLINE_HTML || $tokens[$first]["code"] === T_CONSTANT_ENCAPSED_STRING && $tokens[$first - 1]["code"] === T_CONSTANT_ENCAPSED_STRING) { $trimmed = ltrim($tokens[$first]["content"]); if ($trimmed === '') { $foundFunctionIndent = strlen($tokens[$first]["content"]); } else { $foundFunctionIndent = strlen($tokens[$first]["content"]) - strlen($trimmed); } } else { $foundFunctionIndent = $tokens[$first]["column"] - 1; } } $functionIndent = (int) (floor($foundFunctionIndent / $this->indent) * $this->indent); $adjustment = 0; if ($foundFunctionIndent !== $functionIndent) { $error = "Opening statement of multi-line function call not indented correctly; expected %s spaces but found %s"; $data = array($functionIndent, $foundFunctionIndent); $fix = $phpcsFile->addFixableError($error, $first, "OpeningIndent", $data); if ($fix === true) { $adjustment = $functionIndent - $foundFunctionIndent; $padding = str_repeat(" ", $functionIndent); if ($foundFunctionIndent === 0) { $phpcsFile->fixer->addContentBefore($first, $padding); } else { if ($tokens[$first]["code"] === T_INLINE_HTML) { $newContent = $padding . ltrim($tokens[$first]["content"]); $phpcsFile->fixer->replaceToken($first, $newContent); } else { $phpcsFile->fixer->replaceToken($first - 1, $padding); } } } } $next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true); if ($tokens[$next]["line"] === $tokens[$openBracket]["line"]) { $error = "Opening parenthesis of a multi-line function call must be the last content on the line"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "ContentAfterOpenBracket"); if ($fix === true) { $phpcsFile->fixer->addContent($openBracket, $phpcsFile->eolChar . str_repeat(" ", $foundFunctionIndent + $this->indent)); } } $closeBracket = $tokens[$openBracket]["parenthesis_closer"]; $prev = $phpcsFile->findPrevious(T_WHITESPACE, $closeBracket - 1, null, true); if ($tokens[$prev]["line"] === $tokens[$closeBracket]["line"]) { $error = "Closing parenthesis of a multi-line function call must be on a line by itself"; $fix = $phpcsFile->addFixableError($error, $closeBracket, "CloseBracketLine"); if ($fix === true) { $phpcsFile->fixer->addContentBefore($closeBracket, $phpcsFile->eolChar . str_repeat(" ", $foundFunctionIndent + $this->indent)); } } $lastLine = $tokens[$openBracket]["line"] - 1; $argStart = null; $argEnd = null; $i = $phpcsFile->findNext(T_WHITESPACE, $openBracket + 1, null, true); if ($tokens[$i]["line"] > $tokens[$openBracket]["line"] + 1) { $error = "The first argument in a multi-line function call must be on the line after the opening parenthesis"; $fix = $phpcsFile->addFixableError($error, $i, "FirstArgumentPosition"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($x = $openBracket + 1; $x < $i; $x++) { if ($tokens[$x]["line"] === $tokens[$openBracket]["line"]) { continue; } if ($tokens[$x]["line"] === $tokens[$i]["line"]) { break; } $phpcsFile->fixer->replaceToken($x, ''); } $phpcsFile->fixer->endChangeset(); } } $i = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true); if ($tokens[$i - 1]["code"] === T_WHITESPACE && $tokens[$i - 1]["line"] === $tokens[$i]["line"]) { $i--; } for ($i; $i < $closeBracket; $i++) { if ($i > $argStart && $i < $argEnd) { $inArg = true; } else { $inArg = false; } if ($tokens[$i]["line"] !== $lastLine) { $lastLine = $tokens[$i]["line"]; if (isset(Tokens::$heredocTokens[$tokens[$i]["code"]]) === true) { continue; } if (isset(Tokens::$stringTokens[$tokens[$i]["code"]]) === true && $tokens[$i]["code"] === $tokens[$i - 1]["code"]) { continue; } if ($tokens[$i]["code"] === T_INLINE_HTML) { continue; } if ($tokens[$i]["line"] !== $tokens[$openBracket]["line"]) { if ($tokens[$i]["code"] === T_WHITESPACE) { $nextCode = $phpcsFile->findNext(T_WHITESPACE, $i + 1, $closeBracket + 1, true); if ($tokens[$nextCode]["line"] !== $lastLine) { if ($inArg === false) { $error = "Empty lines are not allowed in multi-line function calls"; $fix = $phpcsFile->addFixableError($error, $i, "EmptyLine"); if ($fix === true) { $phpcsFile->fixer->replaceToken($i, ''); } } continue; } } else { $nextCode = $i; } if ($tokens[$nextCode]["line"] === $tokens[$closeBracket]["line"]) { $inArg = false; $expectedIndent = $foundFunctionIndent + $adjustment; } else { $expectedIndent = $foundFunctionIndent + $this->indent + $adjustment; } if ($tokens[$i]["code"] !== T_WHITESPACE && $tokens[$i]["code"] !== T_DOC_COMMENT_WHITESPACE) { if ($tokens[$i]["code"] === T_COMMENT && $tokens[$i - 1]["code"] === T_COMMENT) { $trimmedLength = strlen(ltrim($tokens[$i]["content"])); if ($trimmedLength === 0) { continue; } $foundIndent = strlen($tokens[$i]["content"]) - $trimmedLength; } else { $foundIndent = 0; } } else { $foundIndent = $tokens[$i]["length"]; } if ($foundIndent < $expectedIndent || $inArg === false && $expectedIndent !== $foundIndent) { $error = "Multi-line function call not indented correctly; expected %s spaces but found %s"; $data = array($expectedIndent, $foundIndent); $fix = $phpcsFile->addFixableError($error, $i, "Indent", $data); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); $padding = str_repeat(" ", $expectedIndent); if ($foundIndent === 0) { $phpcsFile->fixer->addContentBefore($i, $padding); if (isset($tokens[$i]["scope_opener"]) === true) { $phpcsFile->fixer->changeCodeBlockIndent($i, $tokens[$i]["scope_closer"], $expectedIndent); } } else { if ($tokens[$i]["code"] === T_COMMENT) { $comment = $padding . ltrim($tokens[$i]["content"]); $phpcsFile->fixer->replaceToken($i, $comment); } else { $phpcsFile->fixer->replaceToken($i, $padding); } if (isset($tokens[$i + 1]["scope_opener"]) === true) { $phpcsFile->fixer->changeCodeBlockIndent($i + 1, $tokens[$i + 1]["scope_closer"], $expectedIndent - $foundIndent); } } $phpcsFile->fixer->endChangeset(); } } } else { $nextCode = $i; } if ($inArg === false) { $argStart = $nextCode; $argEnd = $phpcsFile->findEndOfStatement($nextCode, array(T_COLON)); } } if ($inArg === false && $tokens[$i]["code"] === T_COMMA) { $next = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, $closeBracket, true); if ($next === false) { continue; } if ($this->allowMultipleArguments === false) { if ($tokens[$i]["line"] === $tokens[$next]["line"]) { $error = "Only one argument is allowed per line in a multi-line function call"; $fix = $phpcsFile->addFixableError($error, $next, "MultipleArguments"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($x = $next - 1; $x > $i; $x--) { if ($tokens[$x]["code"] !== T_WHITESPACE) { break; } $phpcsFile->fixer->replaceToken($x, ''); } $phpcsFile->fixer->addContentBefore($next, $phpcsFile->eolChar . str_repeat(" ", $foundFunctionIndent + $this->indent)); $phpcsFile->fixer->endChangeset(); } } } $argStart = $next; $argEnd = $phpcsFile->findEndOfStatement($next, array(T_COLON)); } } } } ?>
Did this file decode correctly?
Original Code
<?php
namespace PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Util\Tokens; class FunctionCallSignatureSniff implements Sniff { public $supportedTokenizers = array("\120\110\120", "\x4a\x53"); public $indent = 4; public $allowMultipleArguments = true; public $requiredSpacesAfterOpen = 0; public $requiredSpacesBeforeClose = 0; public function register() { $tokens = Tokens::$functionNameTokens; $tokens[] = T_VARIABLE; $tokens[] = T_CLOSE_CURLY_BRACKET; $tokens[] = T_CLOSE_SQUARE_BRACKET; $tokens[] = T_CLOSE_PARENTHESIS; return $tokens; } public function process(File $phpcsFile, $stackPtr) { $this->requiredSpacesAfterOpen = (int) $this->requiredSpacesAfterOpen; $this->requiredSpacesBeforeClose = (int) $this->requiredSpacesBeforeClose; $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]["\143\157\x64\x65"] === T_CLOSE_CURLY_BRACKET && isset($tokens[$stackPtr]["\x73\143\x6f\160\145\137\x63\x6f\156\144\151\164\x69\157\x6e"]) === true) { return; } $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); if ($tokens[$openBracket]["\x63\157\144\x65"] !== T_OPEN_PARENTHESIS) { return; } if (isset($tokens[$openBracket]["\x70\x61\162\145\x6e\x74\150\145\163\x69\163\x5f\x63\x6c\157\x73\145\162"]) === false) { return; } $search = Tokens::$emptyTokens; $search[] = T_BITWISE_AND; $previous = $phpcsFile->findPrevious($search, $stackPtr - 1, null, true); if ($tokens[$previous]["\143\x6f\144\145"] === T_FUNCTION) { return; } $closeBracket = $tokens[$openBracket]["\160\141\162\145\x6e\164\x68\x65\x73\x69\x73\137\x63\154\x6f\x73\x65\162"]; if ($stackPtr + 1 !== $openBracket) { $error = "\x53\160\x61\x63\145\40\x62\145\146\157\162\x65\40\157\x70\145\x6e\x69\x6e\x67\x20\x70\x61\x72\x65\x6e\x74\x68\145\x73\x69\x73\40\157\x66\x20\x66\165\156\143\x74\151\x6f\156\40\143\x61\x6c\x6c\x20\x70\x72\x6f\x68\151\x62\x69\x74\145\144"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "\x53\x70\141\x63\145\102\x65\x66\x6f\x72\145\117\x70\x65\x6e\x42\162\x61\x63\153\145\164"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($i = $stackPtr + 1; $i < $openBracket; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->replaceToken($openBracket, "\50"); $phpcsFile->fixer->endChangeset(); } } $next = $phpcsFile->findNext(T_WHITESPACE, $closeBracket + 1, null, true); if ($tokens[$next]["\x63\x6f\x64\x65"] === T_SEMICOLON) { if (isset(Tokens::$emptyTokens[$tokens[$closeBracket + 1]["\x63\157\x64\145"]]) === true) { $error = "\x53\160\x61\143\145\x20\x61\x66\x74\145\162\40\x63\154\x6f\x73\x69\156\x67\x20\160\141\x72\x65\156\x74\x68\145\x73\x69\x73\x20\157\146\40\x66\x75\156\x63\164\x69\157\156\40\143\x61\154\x6c\x20\160\162\x6f\x68\x69\142\x69\x74\x65\144"; $fix = $phpcsFile->addFixableError($error, $closeBracket, "\123\x70\141\143\x65\x41\146\x74\x65\162\x43\x6c\x6f\163\x65\x42\x72\141\143\x6b\x65\x74"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($i = $closeBracket + 1; $i < $next; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->replaceToken($closeBracket, "\x29"); $phpcsFile->fixer->endChangeset(); } } } if ($this->isMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens) === true) { $this->processMultiLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); } else { $this->processSingleLineCall($phpcsFile, $stackPtr, $openBracket, $tokens); } } public function isMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $closeBracket = $tokens[$openBracket]["\x70\x61\162\x65\156\x74\150\x65\163\x69\163\137\143\154\x6f\163\145\x72"]; if ($tokens[$openBracket]["\x6c\x69\156\x65"] !== $tokens[$closeBracket]["\154\x69\x6e\x65"]) { return true; } return false; } public function processSingleLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $closer = $tokens[$openBracket]["\x70\141\x72\145\156\164\x68\145\163\x69\x73\137\x63\154\157\163\145\162"]; if ($openBracket === $closer - 1) { return; } $next = $phpcsFile->findNext(T_WHITESPACE, $openBracket + 1, $closer, true); if ($next === false) { $requiredSpacesAfterOpen = 0; $requiredSpacesBeforeClose = 0; } else { $requiredSpacesAfterOpen = $this->requiredSpacesAfterOpen; $requiredSpacesBeforeClose = $this->requiredSpacesBeforeClose; } if ($requiredSpacesAfterOpen === 0 && $tokens[$openBracket + 1]["\x63\x6f\144\145"] === T_WHITESPACE) { $error = "\x53\x70\141\143\145\x20\x61\146\x74\145\162\40\x6f\x70\x65\156\x69\156\x67\40\x70\x61\x72\145\156\x74\x68\x65\x73\x69\x73\40\x6f\146\40\x66\x75\156\x63\164\x69\157\156\x20\143\x61\x6c\x6c\40\x70\x72\x6f\150\151\x62\151\x74\x65\144"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "\123\160\x61\143\145\101\146\164\145\162\117\160\x65\156\x42\162\141\143\x6b\145\x74"); if ($fix === true) { $phpcsFile->fixer->replaceToken($openBracket + 1, ''); } } else { if ($requiredSpacesAfterOpen > 0) { $spaceAfterOpen = 0; if ($tokens[$openBracket + 1]["\143\157\144\145"] === T_WHITESPACE) { $spaceAfterOpen = $tokens[$openBracket + 1]["\x6c\145\156\147\x74\x68"]; } if ($spaceAfterOpen !== $requiredSpacesAfterOpen) { $error = "\x45\x78\160\145\x63\x74\145\x64\x20\x25\163\40\163\160\141\143\145\163\x20\x61\x66\x74\x65\162\40\x6f\x70\145\156\151\x6e\x67\40\160\x61\162\x65\156\x74\150\x65\x73\x69\163\73\x20\x25\x73\40\x66\x6f\x75\156\144"; $data = array($requiredSpacesAfterOpen, $spaceAfterOpen); $fix = $phpcsFile->addFixableError($error, $stackPtr, "\x53\x70\141\x63\145\x41\x66\164\145\x72\117\x70\145\156\x42\162\141\143\153\x65\x74", $data); if ($fix === true) { $padding = str_repeat("\x20", $requiredSpacesAfterOpen); if ($spaceAfterOpen === 0) { $phpcsFile->fixer->addContent($openBracket, $padding); } else { $phpcsFile->fixer->replaceToken($openBracket + 1, $padding); } } } } } $spaceBeforeClose = 0; $prev = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, $openBracket, true); if ($tokens[$prev]["\x63\x6f\144\x65"] === T_END_HEREDOC || $tokens[$prev]["\x63\157\x64\145"] === T_END_NOWDOC) { return; } if ($tokens[$prev]["\x6c\151\x6e\x65"] !== $tokens[$closer]["\154\x69\x6e\145"]) { $spaceBeforeClose = "\156\145\167\154\x69\x6e\145"; } else { if ($tokens[$closer - 1]["\x63\x6f\x64\x65"] === T_WHITESPACE) { $spaceBeforeClose = $tokens[$closer - 1]["\154\145\156\147\x74\150"]; } } if ($spaceBeforeClose !== $requiredSpacesBeforeClose) { $error = "\x45\x78\x70\x65\143\x74\x65\x64\40\45\163\40\x73\160\141\143\145\x73\40\142\145\146\x6f\x72\x65\x20\x63\154\157\x73\151\156\x67\x20\x70\141\162\145\156\164\x68\x65\x73\x69\163\x3b\40\x25\x73\40\146\157\165\x6e\144"; $data = array($requiredSpacesBeforeClose, $spaceBeforeClose); $fix = $phpcsFile->addFixableError($error, $closer, "\123\x70\141\143\x65\102\x65\x66\x6f\x72\x65\x43\x6c\x6f\163\145\x42\x72\141\x63\153\145\164", $data); if ($fix === true) { $padding = str_repeat("\x20", $requiredSpacesBeforeClose); if ($spaceBeforeClose === 0) { $phpcsFile->fixer->addContentBefore($closer, $padding); } else { if ($spaceBeforeClose === "\156\x65\x77\x6c\151\x6e\x65") { $phpcsFile->fixer->beginChangeset(); $closingContent = "\51"; $next = $phpcsFile->findNext(T_WHITESPACE, $closer + 1, null, true); if ($tokens[$next]["\143\157\x64\145"] === T_SEMICOLON) { $closingContent .= "\x3b"; for ($i = $closer + 1; $i <= $next; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } } $prev = $closer - 1; while (isset(Tokens::$emptyTokens[$tokens[$prev]["\143\157\x64\145"]]) === true) { if ($tokens[$prev]["\143\x6f\x64\145"] === T_COMMENT && strpos($tokens[$prev]["\x63\157\156\x74\x65\156\164"], "\x2a\x2f") !== false) { break; } $prev--; } $phpcsFile->fixer->addContent($prev, $padding . $closingContent); $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, $closer - 1, null, true); for ($i = $prevNonWhitespace + 1; $i <= $closer; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } $phpcsFile->fixer->endChangeset(); } else { $phpcsFile->fixer->replaceToken($closer - 1, $padding); } } } } } public function processMultiLineCall(File $phpcsFile, $stackPtr, $openBracket, $tokens) { $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true); if ($tokens[$first]["\143\157\144\145"] === T_CONSTANT_ENCAPSED_STRING && $tokens[$first - 1]["\143\x6f\x64\145"] === T_CONSTANT_ENCAPSED_STRING) { $prev = $phpcsFile->findPrevious(T_CONSTANT_ENCAPSED_STRING, $first - 2, null, true); $first = $phpcsFile->findFirstOnLine(Tokens::$emptyTokens, $prev, true); if ($first === false) { $first = $prev + 1; } } $foundFunctionIndent = 0; if ($first !== false) { if ($tokens[$first]["\143\x6f\144\x65"] === T_INLINE_HTML || $tokens[$first]["\x63\157\x64\145"] === T_CONSTANT_ENCAPSED_STRING && $tokens[$first - 1]["\143\x6f\x64\145"] === T_CONSTANT_ENCAPSED_STRING) { $trimmed = ltrim($tokens[$first]["\143\x6f\x6e\x74\145\156\x74"]); if ($trimmed === '') { $foundFunctionIndent = strlen($tokens[$first]["\x63\x6f\156\164\x65\156\x74"]); } else { $foundFunctionIndent = strlen($tokens[$first]["\x63\x6f\156\x74\x65\156\164"]) - strlen($trimmed); } } else { $foundFunctionIndent = $tokens[$first]["\143\x6f\154\165\155\156"] - 1; } } $functionIndent = (int) (floor($foundFunctionIndent / $this->indent) * $this->indent); $adjustment = 0; if ($foundFunctionIndent !== $functionIndent) { $error = "\x4f\160\145\x6e\151\x6e\147\40\163\x74\141\x74\x65\x6d\145\x6e\164\x20\x6f\x66\40\x6d\165\x6c\164\x69\55\x6c\151\x6e\x65\40\x66\165\156\x63\164\151\x6f\156\x20\x63\141\154\x6c\x20\x6e\157\164\x20\151\x6e\x64\x65\156\164\x65\144\x20\x63\157\x72\162\145\x63\x74\x6c\x79\x3b\x20\145\x78\160\x65\143\x74\145\x64\40\x25\163\x20\163\160\141\x63\x65\163\40\142\x75\x74\x20\146\157\x75\x6e\144\40\45\163"; $data = array($functionIndent, $foundFunctionIndent); $fix = $phpcsFile->addFixableError($error, $first, "\x4f\x70\x65\x6e\151\x6e\x67\x49\156\144\145\156\164", $data); if ($fix === true) { $adjustment = $functionIndent - $foundFunctionIndent; $padding = str_repeat("\40", $functionIndent); if ($foundFunctionIndent === 0) { $phpcsFile->fixer->addContentBefore($first, $padding); } else { if ($tokens[$first]["\x63\x6f\x64\145"] === T_INLINE_HTML) { $newContent = $padding . ltrim($tokens[$first]["\143\157\x6e\164\x65\156\164"]); $phpcsFile->fixer->replaceToken($first, $newContent); } else { $phpcsFile->fixer->replaceToken($first - 1, $padding); } } } } $next = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true); if ($tokens[$next]["\154\151\x6e\145"] === $tokens[$openBracket]["\x6c\x69\x6e\145"]) { $error = "\117\160\145\156\151\x6e\x67\40\160\141\162\145\x6e\164\150\x65\x73\x69\x73\x20\157\x66\40\141\x20\x6d\x75\x6c\164\151\x2d\154\151\x6e\145\x20\146\x75\156\143\x74\x69\157\156\40\143\x61\154\x6c\x20\155\165\163\x74\x20\142\x65\x20\x74\x68\145\40\x6c\141\x73\x74\x20\x63\157\156\164\145\156\164\40\x6f\x6e\x20\x74\x68\x65\40\154\x69\x6e\145"; $fix = $phpcsFile->addFixableError($error, $stackPtr, "\x43\157\156\x74\145\156\164\x41\x66\164\145\x72\x4f\x70\x65\x6e\x42\162\x61\x63\x6b\x65\x74"); if ($fix === true) { $phpcsFile->fixer->addContent($openBracket, $phpcsFile->eolChar . str_repeat("\40", $foundFunctionIndent + $this->indent)); } } $closeBracket = $tokens[$openBracket]["\x70\x61\x72\x65\x6e\164\150\x65\163\151\x73\x5f\143\154\x6f\x73\x65\x72"]; $prev = $phpcsFile->findPrevious(T_WHITESPACE, $closeBracket - 1, null, true); if ($tokens[$prev]["\154\151\156\x65"] === $tokens[$closeBracket]["\154\x69\x6e\x65"]) { $error = "\103\154\x6f\163\x69\156\x67\x20\x70\x61\x72\x65\x6e\x74\150\145\163\151\163\x20\157\146\40\x61\x20\155\x75\x6c\164\151\55\154\151\x6e\x65\40\146\165\x6e\143\x74\151\157\x6e\x20\143\141\x6c\154\x20\155\x75\x73\164\x20\142\x65\x20\157\x6e\40\x61\x20\x6c\151\x6e\145\x20\142\x79\40\x69\164\163\145\154\x66"; $fix = $phpcsFile->addFixableError($error, $closeBracket, "\103\154\157\x73\145\102\162\x61\x63\x6b\x65\164\x4c\151\156\x65"); if ($fix === true) { $phpcsFile->fixer->addContentBefore($closeBracket, $phpcsFile->eolChar . str_repeat("\40", $foundFunctionIndent + $this->indent)); } } $lastLine = $tokens[$openBracket]["\154\151\156\x65"] - 1; $argStart = null; $argEnd = null; $i = $phpcsFile->findNext(T_WHITESPACE, $openBracket + 1, null, true); if ($tokens[$i]["\x6c\x69\x6e\x65"] > $tokens[$openBracket]["\x6c\151\x6e\x65"] + 1) { $error = "\x54\x68\145\40\x66\151\162\x73\164\40\141\162\x67\x75\x6d\x65\x6e\164\x20\x69\x6e\40\141\40\155\165\x6c\x74\151\x2d\x6c\x69\156\x65\x20\146\165\x6e\x63\x74\x69\157\x6e\40\x63\141\x6c\154\x20\x6d\x75\163\164\x20\x62\145\x20\x6f\156\40\164\x68\x65\x20\x6c\151\156\x65\40\141\x66\164\x65\162\40\164\x68\x65\40\157\x70\145\156\151\x6e\147\x20\160\141\x72\145\156\164\x68\x65\163\x69\163"; $fix = $phpcsFile->addFixableError($error, $i, "\106\x69\x72\163\x74\x41\x72\147\165\155\x65\156\164\120\x6f\163\x69\164\x69\157\x6e"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($x = $openBracket + 1; $x < $i; $x++) { if ($tokens[$x]["\x6c\x69\x6e\145"] === $tokens[$openBracket]["\x6c\151\x6e\x65"]) { continue; } if ($tokens[$x]["\154\151\x6e\145"] === $tokens[$i]["\x6c\x69\156\145"]) { break; } $phpcsFile->fixer->replaceToken($x, ''); } $phpcsFile->fixer->endChangeset(); } } $i = $phpcsFile->findNext(Tokens::$emptyTokens, $openBracket + 1, null, true); if ($tokens[$i - 1]["\x63\x6f\144\x65"] === T_WHITESPACE && $tokens[$i - 1]["\154\151\x6e\145"] === $tokens[$i]["\x6c\151\156\145"]) { $i--; } for ($i; $i < $closeBracket; $i++) { if ($i > $argStart && $i < $argEnd) { $inArg = true; } else { $inArg = false; } if ($tokens[$i]["\154\151\x6e\x65"] !== $lastLine) { $lastLine = $tokens[$i]["\154\151\156\145"]; if (isset(Tokens::$heredocTokens[$tokens[$i]["\x63\157\144\x65"]]) === true) { continue; } if (isset(Tokens::$stringTokens[$tokens[$i]["\143\x6f\x64\x65"]]) === true && $tokens[$i]["\x63\x6f\x64\145"] === $tokens[$i - 1]["\143\x6f\144\x65"]) { continue; } if ($tokens[$i]["\143\x6f\144\145"] === T_INLINE_HTML) { continue; } if ($tokens[$i]["\x6c\x69\x6e\145"] !== $tokens[$openBracket]["\154\x69\156\145"]) { if ($tokens[$i]["\143\157\x64\x65"] === T_WHITESPACE) { $nextCode = $phpcsFile->findNext(T_WHITESPACE, $i + 1, $closeBracket + 1, true); if ($tokens[$nextCode]["\154\x69\156\145"] !== $lastLine) { if ($inArg === false) { $error = "\105\155\160\164\171\x20\154\151\x6e\x65\x73\x20\141\x72\x65\40\x6e\157\x74\40\141\154\154\x6f\x77\x65\x64\x20\x69\156\40\x6d\x75\x6c\164\151\x2d\x6c\x69\x6e\x65\x20\146\x75\156\x63\164\x69\157\156\x20\x63\x61\x6c\x6c\163"; $fix = $phpcsFile->addFixableError($error, $i, "\x45\x6d\160\x74\x79\114\x69\x6e\x65"); if ($fix === true) { $phpcsFile->fixer->replaceToken($i, ''); } } continue; } } else { $nextCode = $i; } if ($tokens[$nextCode]["\x6c\151\x6e\145"] === $tokens[$closeBracket]["\154\x69\x6e\x65"]) { $inArg = false; $expectedIndent = $foundFunctionIndent + $adjustment; } else { $expectedIndent = $foundFunctionIndent + $this->indent + $adjustment; } if ($tokens[$i]["\143\157\144\145"] !== T_WHITESPACE && $tokens[$i]["\143\157\x64\x65"] !== T_DOC_COMMENT_WHITESPACE) { if ($tokens[$i]["\143\x6f\x64\145"] === T_COMMENT && $tokens[$i - 1]["\143\x6f\x64\145"] === T_COMMENT) { $trimmedLength = strlen(ltrim($tokens[$i]["\x63\157\156\x74\x65\x6e\164"])); if ($trimmedLength === 0) { continue; } $foundIndent = strlen($tokens[$i]["\x63\x6f\156\x74\145\156\x74"]) - $trimmedLength; } else { $foundIndent = 0; } } else { $foundIndent = $tokens[$i]["\154\145\156\147\x74\150"]; } if ($foundIndent < $expectedIndent || $inArg === false && $expectedIndent !== $foundIndent) { $error = "\115\x75\154\164\151\x2d\154\151\x6e\x65\x20\146\165\156\x63\x74\151\157\156\x20\143\x61\154\154\x20\x6e\x6f\x74\40\151\156\x64\x65\x6e\x74\x65\x64\40\x63\x6f\162\x72\x65\x63\x74\x6c\x79\x3b\40\x65\x78\160\x65\x63\164\145\x64\40\x25\x73\40\163\x70\141\143\145\163\x20\142\x75\x74\40\x66\157\x75\156\144\40\x25\163"; $data = array($expectedIndent, $foundIndent); $fix = $phpcsFile->addFixableError($error, $i, "\111\156\x64\145\x6e\164", $data); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); $padding = str_repeat("\40", $expectedIndent); if ($foundIndent === 0) { $phpcsFile->fixer->addContentBefore($i, $padding); if (isset($tokens[$i]["\x73\143\x6f\160\145\137\157\x70\x65\x6e\145\x72"]) === true) { $phpcsFile->fixer->changeCodeBlockIndent($i, $tokens[$i]["\163\143\x6f\x70\x65\137\143\x6c\x6f\163\145\162"], $expectedIndent); } } else { if ($tokens[$i]["\x63\x6f\144\145"] === T_COMMENT) { $comment = $padding . ltrim($tokens[$i]["\143\157\156\x74\145\x6e\x74"]); $phpcsFile->fixer->replaceToken($i, $comment); } else { $phpcsFile->fixer->replaceToken($i, $padding); } if (isset($tokens[$i + 1]["\163\x63\x6f\x70\x65\137\157\160\x65\x6e\145\162"]) === true) { $phpcsFile->fixer->changeCodeBlockIndent($i + 1, $tokens[$i + 1]["\163\143\x6f\160\145\137\143\x6c\x6f\163\x65\x72"], $expectedIndent - $foundIndent); } } $phpcsFile->fixer->endChangeset(); } } } else { $nextCode = $i; } if ($inArg === false) { $argStart = $nextCode; $argEnd = $phpcsFile->findEndOfStatement($nextCode, array(T_COLON)); } } if ($inArg === false && $tokens[$i]["\143\x6f\x64\x65"] === T_COMMA) { $next = $phpcsFile->findNext(Tokens::$emptyTokens, $i + 1, $closeBracket, true); if ($next === false) { continue; } if ($this->allowMultipleArguments === false) { if ($tokens[$i]["\154\151\156\145"] === $tokens[$next]["\x6c\x69\x6e\145"]) { $error = "\x4f\x6e\x6c\171\x20\x6f\x6e\x65\x20\141\162\x67\x75\x6d\145\156\164\40\x69\163\x20\x61\154\154\x6f\x77\145\144\x20\x70\145\162\x20\154\151\156\x65\x20\151\x6e\40\141\40\155\165\154\164\x69\x2d\154\x69\x6e\x65\x20\146\x75\x6e\x63\164\151\x6f\x6e\x20\x63\141\x6c\x6c"; $fix = $phpcsFile->addFixableError($error, $next, "\x4d\165\154\x74\x69\160\154\145\x41\162\x67\x75\155\x65\x6e\164\163"); if ($fix === true) { $phpcsFile->fixer->beginChangeset(); for ($x = $next - 1; $x > $i; $x--) { if ($tokens[$x]["\x63\x6f\144\x65"] !== T_WHITESPACE) { break; } $phpcsFile->fixer->replaceToken($x, ''); } $phpcsFile->fixer->addContentBefore($next, $phpcsFile->eolChar . str_repeat("\x20", $foundFunctionIndent + $this->indent)); $phpcsFile->fixer->endChangeset(); } } } $argStart = $next; $argEnd = $phpcsFile->findEndOfStatement($next, array(T_COLON)); } } } }
Function Calls
None |
Stats
MD5 | ae598e71bedb7ae7feebbe233bcc1802 |
Eval Count | 0 |
Decode Time | 165 ms |