Save all coding standard paths back into PHP_CodeSniffer

@throws LogicException
@throws ProcessFailedException
@throws RuntimeException
12452
private function saveInstalledPaths()
    {
        // Check if we found installed paths to set.
        if (count($this->installedPaths) !== 0) {
            $paths = implode(',', $this->installedPaths);
            $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths);
            $configMessage = sprintf(
                'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>',
                self::PHPCS_CONFIG_KEY,
                $paths
            );
        } else {
            // Delete the installed paths if none were found.
            $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY);
            $configMessage = sprintf(
                'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>',
                self::PHPCS_CONFIG_KEY
            );
        }

        $this->io->write($configMessage);

        $this->processExecutor->execute(
            sprintf(
                'phpcs %s',
                implode(' ', $arguments)
            ),
            $configResult,
            $this->composer->getConfig()->get('bin-dir')
        );

        if ($this->io->isVerbose() && !empty($configResult)) {
            $this->io->write(sprintf('<info>%s</info>', $configResult));
        }
    }
944558
public function beforeCompile(): void
	{
		$builder = $this->getContainerBuilder();

		if ($builder->getByType(Application::class) === null) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', Application::class));
		}

		if ($builder->getByType(EventDispatcherInterface::class) === null) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', EventDispatcherInterface::class));
		}

		$dispatcher = $builder->getDefinition($builder->getByType(EventDispatcherInterface::class));

		$application = $builder->getDefinition($builder->getByType(Application::class));

		$application->addSetup('?->onStartup[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_STARTUP,
			new PhpLiteral(StartupEvent::class),
		]);

		$application->addSetup('?->onError[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_ERROR,
			new PhpLiteral(ErrorEvent::class),
		]);

		$application->addSetup('?->onPresenter[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_PRESENTER,
			new PhpLiteral(PresenterEvent::class),
		]);

		$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!property_exists($presenter, "onStartup")){return;} $presenter->onStartup[] = function() {?->dispatch(?, new ?(...func_get_args()));};}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_PRESENTER_STARTUP,
			new PhpLiteral(PresenterStartupEvent::class),
		]);

		$application->addSetup('?->onPresenter[] = function($application, $presenter) {if(!property_exists($presenter, "onShutdown")){return;} $presenter->onShutdown[] = function() {?->dispatch(?, new ?(...func_get_args()));};}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_PRESENTER_SHUTDOWN,
			new PhpLiteral(PresenterShutdownEvent::class),
		]);

		$application->addSetup('?->onRequest[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_REQUEST,
			new PhpLiteral(RequestEvent::class),
		]);

		$application->addSetup('?->onResponse[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_RESPONSE,
			new PhpLiteral(ResponseEvent::class),
		]);

		$application->addSetup('?->onShutdown[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_SHUTDOWN,
			new PhpLiteral(ShutdownEvent::class),
		]);
	}
1193376
public function beforeCompile()
	{
		$builder = $this->getContainerBuilder();

		if (!$builder->getByType(Application::class)) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', Application::class));
		}

		if (!$builder->getByType(EventDispatcher::class)) {
			throw new LogicException(sprintf('Service of type "%s" is needed. Please register it.', EventDispatcher::class));
		}

		$application = $builder->getDefinition($builder->getByType(Application::class));
		$dispatcher = $builder->getDefinition($builder->getByType(EventDispatcher::class));

		$application->addSetup('?->onStartup[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_STARTUP,
			new PhpLiteral(StartupEvent::class),
		]);
		$application->addSetup('?->onError[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_ERROR,
			new PhpLiteral(ErrorEvent::class),
		]);
		$application->addSetup('?->onPresenter[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_PRESENTER,
			new PhpLiteral(PresenterEvent::class),
		]);
		$application->addSetup('?->onRequest[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_REQUEST,
			new PhpLiteral(RequestEvent::class),
		]);
		$application->addSetup('?->onResponse[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_RESPONSE,
			new PhpLiteral(ResponseEvent::class),
		]);
		$application->addSetup('?->onShutdown[] = function() {?->dispatch(?, new ?(...func_get_args()));}', [
			'@self',
			$dispatcher,
			ApplicationEvents::ON_SHUTDOWN,
			new PhpLiteral(ShutdownEvent::class),
		]);
	}
310659
private function setCodeFile()
    {
        $this->findTemplate();
        $this->_codeFile = $this->getPhpCodeDestination() . $this->getFunctionName() . '.' . $this->getPhpCodeExtension();
    }
1045628
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('5.4')) {
            $tokens = $phpcsFile->getTokens();

            // Skip tokens that are the names of functions or classes
            // within their definitions. For example: function myFunction...
            // "myFunction" is T_STRING but we should skip because it is not a
            // function or method *call*.
            $functionName = $stackPtr;
            $findTokens   = array_merge(
                PHP_CodeSniffer_Tokens::$emptyTokens,
                array(T_BITWISE_AND)
            );

            $functionKeyword = $phpcsFile->findPrevious(
                $findTokens,
                ($stackPtr - 1),
                null,
                true
            );

            if ($tokens[$functionKeyword]['code'] === T_FUNCTION
                || $tokens[$functionKeyword]['code'] === T_CLASS
            ) {
                return;
            }

            // If the next non-whitespace token after the function or method call
            // is not an opening parenthesis then it cant really be a *call*.
            $openBracket = $phpcsFile->findNext(
                PHP_CodeSniffer_Tokens::$emptyTokens,
                ($functionName + 1),
                null,
                true
            );

            if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
                return;
            }

            $closeBracket = $tokens[$openBracket]['parenthesis_closer'];

            $nextSeparator = $openBracket;
            while (($nextSeparator = $phpcsFile->findNext(T_VARIABLE, ($nextSeparator + 1), $closeBracket)) !== false) {
                // Make sure the variable belongs directly to this function call
                // and is not inside a nested function call or array.
                $brackets    = $tokens[$nextSeparator]['nested_parenthesis'];
                $lastBracket = array_pop($brackets);
                if ($lastBracket !== $closeBracket) {
                    continue;
                }

                // Checking this: $value = my_function(...[*]$arg...).
                $tokenBefore = $phpcsFile->findPrevious(
                    PHP_CodeSniffer_Tokens::$emptyTokens,
                    ($nextSeparator - 1),
                    null,
                    true
                );

                if ($tokens[$tokenBefore]['code'] === T_BITWISE_AND) {
                    // Checking this: $value = my_function(...[*]&$arg...).
                    $tokenBefore = $phpcsFile->findPrevious(
                        PHP_CodeSniffer_Tokens::$emptyTokens,
                        ($tokenBefore - 1),
                        null,
                        true
                    );

                    // We have to exclude all uses of T_BITWISE_AND that are not
                    // references. We use a blacklist approach as we prefer false
                    // positives to not identifying a pass-by-reference call at all.
                    // The blacklist may not yet be complete.
                    switch ($tokens[$tokenBefore]['code']) {
                    case T_LNUMBER:
                    case T_VARIABLE:
                    case T_CLOSE_SQUARE_BRACKET:
                    case T_CLOSE_PARENTHESIS:
                        // In these cases T_BITWISE_AND represents
                        // the bitwise and operator.
                        continue;

                    // Unfortunately the tokenizer fails to recognize global constants,
                    // class-constants and -attributes. Any of these are returned is
                    // treated as T_STRING.
                    // So we step back another token and check if it is a class
                    // operator (-> or ::), which means we have a false positive.
                    // Global constants still remain uncovered.
                    case T_STRING:
                        $tokenBeforePlus = $phpcsFile->findPrevious(
                            PHP_CodeSniffer_Tokens::$emptyTokens,
                            ($tokenBefore - 1),
                            null,
                            true
                        );
                        if( T_DOUBLE_COLON === $tokens[$tokenBeforePlus]['code'] ||
                            T_OBJECT_OPERATOR === $tokens[$tokenBeforePlus]['code']
                        ) {
                            continue;
                        }

                    default:
                        // T_BITWISE_AND represents a pass-by-reference.
                        $error = 'Using a call-time pass-by-reference is prohibited since php 5.4';
                        $phpcsFile->addError($error, $tokenBefore, 'NotAllowed');
                        break;
                    }
                }//end if
            }//end while
        }
    }
335252
private function saveEncoding()
    {
        if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
            return;
        }

        $iniDirective = 'mbstring' . '.func_overload'; // deprecated in PHP 7.2

        if (ini_get($iniDirective) & 2) {
            $this->encoding = mb_internal_encoding();

            mb_internal_encoding('iso-8859-1');
        }
    }
683634
public function writeRoutineFunctionWithoutLob(): void
  {
    $wrapperArgs = $this->getWrapperArgs();
    $methodName  = $this->nameMangler->getMethodName($this->routine['routine_name']);
    $returnType  = $this->getReturnTypeDeclaration();

    $this->codeStore->appendSeparator();
    $this->generatePhpDoc();
    $this->codeStore->append('public static function '.$methodName.'('.$wrapperArgs.')'.$returnType);
    $this->codeStore->append('{');

    $this->writeResultHandler();
    $this->codeStore->append('}');
    $this->codeStore->append('');
  }
109820
protected function initialize()
    {
        if ('input' !== $this->node->nodeName) {
            throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $this->node->nodeName));
        }

        if ('file' !== strtolower($this->node->getAttribute('type'))) {
            throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type')));
        }

        $this->setValue(null);
    }
400960
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $operator = $tokens[$stackPtr]['content'];
        $previousToken = $tokens[$stackPtr - 1];
        $nextToken = $tokens[$stackPtr + 1];

        $previousSpaces = $previousToken['code'] === T_WHITESPACE ? strlen($previousToken['content']) : 0;
        $nextSpaces = $nextToken['code'] === T_WHITESPACE ? strlen($nextToken['content']) : 0;

        $previousNonEmpty = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
        $previousSplitsLine = $tokens[$previousNonEmpty]['line'] !== $tokens[$stackPtr]['line'];

        $nextNonEmpty = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
        $nextSplitsLine = $tokens[$nextNonEmpty]['line'] !== $tokens[$stackPtr]['line'];

        if (DWS_Helpers_Operator::isUnary($phpcsFile, $stackPtr)) {
            if (
                !$previousSplitsLine &&
                $previousSpaces !== 1 &&
                !in_array($tokens[$previousNonEmpty]['code'], [T_OPEN_PARENTHESIS, T_OPEN_SQUARE_BRACKET, T_OPEN_SHORT_ARRAY])
            ) {
                $phpcsFile->addError('Expected 1 space before "%s"; %s found', $stackPtr, 'SpacingBefore', [$operator, $previousSpaces]);
            }

            if ($nextSpaces !== 0) {
                $phpcsFile->addError('Expected 0 spaces after "%s"; %s found', $stackPtr, 'SpacingAfterUnary', [$operator, $nextSpaces]);
            }
        } else {
            if ($tokens[$stackPtr]['code'] === T_INLINE_ELSE && $tokens[$previousNonEmpty]['code'] === T_INLINE_THEN) {
                if ($previousSpaces !== 0) {
                    $phpcsFile->addError('Expected 0 spaces inside "?:"; %s found', $stackPtr, 'SpacingInTernary', [$previousSpaces]);
                }
            } elseif (!$previousSplitsLine && $previousSpaces !== 1) {
                $phpcsFile->addError('Expected 1 space before "%s"; %s found', $stackPtr, 'SpacingBefore', [$operator, $previousSpaces]);
            }

            $isTernaryShortcut = $tokens[$stackPtr]['code'] === T_INLINE_THEN && $tokens[$nextNonEmpty]['code'] === T_INLINE_ELSE;
            if (!$isTernaryShortcut && !$nextSplitsLine && $nextSpaces !== 1) {
                $phpcsFile->addError('Expected 1 space after "%s"; %s found', $stackPtr, 'SpacingAfter', [$operator, $nextSpaces]);
            }
        }
    }
974762
function save()
    {
        if (!$this->blnChanged) {
            return;
        }
        $flags = JSON_PRETTY_PRINT;
        $strContent = json_encode($this->options, $flags);

        file_put_contents(__CODEGEN_OPTION_FILE__, $strContent);
        $this->blnChanged = false;
    }
961690
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Check decrement / increment.
		if ($tokens[$stackPtr]['code'] === T_DEC || $tokens[$stackPtr]['code'] === T_INC)
		{
            $modifyLeft = substr($tokens[($stackPtr - 1)]['content'], 0, 1) === '$' ||
                          $tokens[($stackPtr + 1)]['content'] === ';';

			if ($modifyLeft === true && $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE)
			{
                $error = 'There must not be a single space before a unary operator statement';
                $phpcsFile->addError($error, $stackPtr, 'IncDecLeft');
                return;
            }

			if ($modifyLeft === false && !in_array(substr($tokens[($stackPtr + 1)]['content'], 0, 1), array('$', ',')))
			{
                $error = 'A unary operator statement must not be followed by a single space';
                $phpcsFile->addError($error, $stackPtr, 'IncDecRight');
                return;
            }
        }

        // Check "!" operator.
		if ($tokens[$stackPtr]['code'] === T_BOOLEAN_NOT && $tokens[$stackPtr + 1]['code'] === T_WHITESPACE)
		{
            $error = 'A unary operator statement must not be followed by a space';
            $phpcsFile->addError($error, $stackPtr, 'BooleanNot');
            return;
        }

        // Find the last syntax item to determine if this is an unary operator.
        $lastSyntaxItem = $phpcsFile->findPrevious(
            array(T_WHITESPACE),
            $stackPtr - 1,
            ($tokens[$stackPtr]['column']) * -1,
            true,
            null,
            true
        );
        $operatorSuffixAllowed = in_array(
            $tokens[$lastSyntaxItem]['code'],
            array(
             T_LNUMBER,
             T_DNUMBER,
             T_CLOSE_PARENTHESIS,
             T_CLOSE_CURLY_BRACKET,
             T_CLOSE_SQUARE_BRACKET,
             T_VARIABLE,
             T_STRING,
            )
        );

        // Check plus / minus value assignments or comparisons.
		if ($tokens[$stackPtr]['code'] === T_MINUS || $tokens[$stackPtr]['code'] === T_PLUS)
		{
            if ($operatorSuffixAllowed === false
                && $tokens[($stackPtr + 1)]['code'] === T_WHITESPACE
			)
			{
                $error = 'A unary operator statement must not be followed by a space';
                $phpcsFile->addError($error, $stackPtr);
            }
        }

    }
38457
public function process(PHP_CodeSniffer_File $phpcs_file, $stack_ptr) {
    $tokens = $phpcs_file->getTokens();

    if (isset($tokens[$stack_ptr]['scope_closer']) === FALSE) {
      // Probably an interface method.
      return;
    }

    $close_brace = $tokens[$stack_ptr]['scope_closer'];
    $prev_content = $phpcs_file->findPrevious(T_WHITESPACE, ($close_brace - 1), NULL, TRUE);

    // Special case for empty JS functions.
    if ($phpcs_file->tokenizerType === 'JS' && $prev_content === $tokens[$stack_ptr]['scope_opener']) {
      // In this case, the opening and closing brace must be
      // right next to each other.
      if ($tokens[$stack_ptr]['scope_closer'] !== ($tokens[$stack_ptr]['scope_opener'] + 1)) {
        $error = 'The opening and closing braces of empty functions must be directly next to each other; e.g., function () {}';
        $phpcs_file->addError($error, $close_brace, 'SpacingBetween');
      }

      return;
    }

    $brace_line = $tokens[$close_brace]['line'];
    $prev_line = $tokens[$prev_content]['line'];

    $found = ($brace_line - $prev_line - 1);
    if ($phpcs_file->hasCondition($stack_ptr, T_FUNCTION) === TRUE || isset($tokens[$stack_ptr]['nested_parenthesis']) === TRUE) {
      // Nested function.
      if ($found < 0) {
        $error = 'Closing brace of nested function must be on a new line';
        $phpcs_file->addError($error, $close_brace, 'ContentBeforeClose');
      }
      else {
        if ($found > 0) {
          $error = 'Expected 0 blank lines before closing brace of nested function; %s found';
          $data = array($found);
          $phpcs_file->addError($error, $close_brace, 'SpacingBeforeNestedClose', $data);
        }
      }
    }
    else {
      if ($found !== 0) {
        $error = 'Expected 0 blank line before closing function brace; %s found';
        $data = array($found);
        $phpcs_file->addError($error, $close_brace, 'SpacingBeforeClose', $data);
      }
    }
  }
767866
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // We are only interested in the first token in a multi-line string.
        if ($tokens[$stackPtr]['code'] === $tokens[$stackPtr - 1]['code']) {
            return;
        }

        $workingString = $tokens[$stackPtr]['content'];
        for ($i = $stackPtr + 1; $tokens[$i]['code'] === $tokens[$stackPtr]['code']; ++$i) {
            $workingString .= $tokens[$i]['content'];
        }

        // The use of variables in double quoted strings is allowed.
        if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING) {
            $openBraces = 0;
            foreach (token_get_all("<?php {$workingString}") as $token) {
                if (is_array($token) === true) {
                    if ($token[0] == T_CURLY_OPEN) {
                        ++$openBraces;
                    } elseif ($token[0] == T_VARIABLE && $openBraces < 1) {
                        $phpcsFile->addError(
                            "String {$workingString} has a variable embedded without being delimited by braces",
                            $stackPtr,
                            'ContainsNonDelimitedVariable',
                            [$token[1]]
                        );
                    }
                } elseif ($token == '}') {
                    --$openBraces;
                }
            }
        }
    }
1077896
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
	{
		$tokens    = $phpcsFile->getTokens();
		$nextToken = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);

		if ($tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS && $tokens[($stackPtr)]['code'] !== T_ECHO)
		{
			$error = '"%s" is a statement not a function; no parentheses are required';
			$data  = array($tokens[$stackPtr]['content']);
			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'BracketsNotRequired', $data);

			if ($fix === true)
			{
				$end      = $phpcsFile->findEndOfStatement($nextToken);
				$ignore   = PHP_CodeSniffer_Tokens::$emptyTokens;
				$ignore[] = T_SEMICOLON;
				$closer   = $phpcsFile->findPrevious($ignore, ($end - 1), null, true);

				$phpcsFile->fixer->beginChangeset();
				$phpcsFile->fixer->replaceToken($nextToken, '');

				if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE)
				{
					$phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
				}

				if ($tokens[$closer]['code'] === T_CLOSE_PARENTHESIS)
				{
					$phpcsFile->fixer->replaceToken($closer, '');
				}

				$phpcsFile->fixer->addContent($stackPtr, ' ');
				$phpcsFile->fixer->endChangeset();
			}
		}

		if ($tokens[($stackPtr)]['code'] === T_ECHO
			&& $tokens[$nextToken]['code'] === T_OPEN_PARENTHESIS
			&& $tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE
		)
		{
			$error = 'There must be one space between the "%s" statement and the opening parenthesis';
			$data  = array($tokens[$stackPtr]['content']);
			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterEcho', $data);

			if ($fix === true)
			{
				$this->requiredSpacesBeforeOpen = 1;
				$padding = str_repeat(' ', $this->requiredSpacesBeforeOpen);
				$phpcsFile->fixer->addContent($stackPtr, $padding);
			}
		}
	}
349677
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $ignore = array(
                T_DOUBLE_COLON,
                T_OBJECT_OPERATOR,
                T_FUNCTION,
                T_CONST,
        );

        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
            // Not a call to a PHP function.
            return;
        }

        $function = strtolower($tokens[$stackPtr]['content']);
        $pattern  = null;

        if ($this->patternMatch === true) {
            $count   = 0;
            $pattern = preg_replace(
                    $this->forbiddenFunctionNames,
                    $this->forbiddenFunctionsNames,
                    $function,
                    1,
                    $count
            );

            if ($count === 0) {
                return;
            }

            // Remove the pattern delimiters and modifier.
            $pattern = substr($pattern, 1, -2);
        } else {
            if (in_array($function, $this->forbiddenFunctionNames) === false) {
                return;
            }
        }

        $this->addError($phpcsFile, $stackPtr, $function, $pattern);

    }
450547
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];

        // Skip broken function declarations.
        if (isset($token['scope_opener']) === false || isset($token['parenthesis_opener']) === false) {
            return;
        }

        $params = array();
        foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
            $params[$param['name']] = $stackPtr;
        }

        $next = ++$token['scope_opener'];
        $end  = --$token['scope_closer'];

        $foundContent = false;
        $validTokens  = array(
                         T_HEREDOC              => T_HEREDOC,
                         T_END_HEREDOC          => T_END_HEREDOC,
                         T_DOUBLE_QUOTED_STRING => T_DOUBLE_QUOTED_STRING,
                        );
        $validTokens += PHP_CodeSniffer_Tokens::$emptyTokens;

        for (; $next <= $end; ++$next) {
            $token = $tokens[$next];
            $code  = $token['code'];

            // Ignorable tokens.
            if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$code])) {
                continue;
            }

            if ($foundContent === false) {
                // A throw statement as the first content indicates an interface method.
                if ($code === T_THROW) {
                    return;
                }

                // A return statement as the first content indicates an interface method.
                if ($code === T_RETURN) {
                    $tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($next + 1), null, true);
                    if ($tmp === false) {
                        return;
                    }

                    // There is a return.
                    if ($tokens[$tmp]['code'] === T_SEMICOLON) {
                        return;
                    }

                    $tmp = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($tmp + 1), null, true);
                    if ($tmp !== false && $tokens[$tmp]['code'] === T_SEMICOLON) {
                        // There is a return <token>.
                        return;
                    }
                }//end if
            }//end if

            $foundContent = true;

			if ($code === T_STRING && strncmp('func_get_arg', $token['content'], 12) === 0) {
				return;
			} else if ($code === T_VARIABLE && isset($params[$token['content']]) === true) {
                unset($params[$token['content']]);
            } else if ($code === T_DOLLAR) {
                $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
                if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) {
                    $nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true);
                    if ($tokens[$nextToken]['code'] === T_STRING) {
                        $varContent = '$'.$tokens[$nextToken]['content'];
                        if (isset($params[$varContent]) === true) {
                            unset($params[$varContent]);
                        }
                    }
                }
            } else if ($code === T_DOUBLE_QUOTED_STRING
                || $code === T_START_HEREDOC
                || $code === T_START_NOWDOC
            ) {
	            // Tokenize strings that can contain variables.
                // Make sure the string is re-joined if it occurs over multiple lines.
                $content = $token['content'];
                for ($i = ($next + 1); $i <= $end; $i++) {
                    if (isset($validTokens[$tokens[$i]['code']]) === true) {
                        $content .= $tokens[$i]['content'];
                        $next++;
                    } else {
                        break;
                    }
                }

                $stringTokens = token_get_all(sprintf('<?php %s;?>', $content));
                foreach ($stringTokens as $stringPtr => $stringToken) {
                    if (is_array($stringToken) === false) {
                        continue;
                    }

                    $varContent = '';
                    if ($stringToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
                        $varContent = '$'.$stringTokens[($stringPtr + 1)][1];
                    } else if ($stringToken[0] === T_VARIABLE) {
                        $varContent = $stringToken[1];
                    }

                    if ($varContent !== '' && isset($params[$varContent]) === true) {
                        unset($params[$varContent]);
                    }
                }
            }
        }//end for

        if ($foundContent === true && count($params) > 0) {
            foreach ($params as $paramName => $position) {
                $error = 'The method parameter %s is never used';
                $data  = array($paramName);
                $phpcsFile->addWarning($error, $position, 'Found', $data);
            }
        }

    }
560119
public function prepare()
    {
        // clear just in case settings changed and cache is out of date
        $this->externalMacroTemplatesCache = array();

        // find the template source file and update function name
        $this->setCodeFile();

        if (!function_exists($this->getFunctionName())) {
            // parse template if php generated code does not exists or template
            // source file modified since last generation or force reparse is set
            if ($this->getForceReparse() || !file_exists($this->getCodePath())) {

                // i'm not sure where that belongs, but not in normal path of execution
                // because some sites have _a lot_ of files in temp
                if ($this->getCachePurgeFrequency() && mt_rand()%$this->getCachePurgeFrequency() == 0) {
                    $this->cleanUpGarbage();
                }

                $result = $this->parse();

                if (!file_put_contents($this->getCodePath(), $result)) {
                    throw new PHPTAL_IOException('Unable to open '.$this->getCodePath().' for writing');
                }

                // the awesome thing about eval() is that parse errors don't stop PHP.
                // when PHP dies during eval, fatal error is printed and
                // can be captured with output buffering
                ob_start();
                try {
                    eval("?>\n".$result);
                }
                catch(ParseError $parseError) {
                    ob_end_clean();
                    throw new PHPTAL_TemplateException(
                        'Parse error: ' . $parseError->getMessage(),
                        $this->getCodePath(),
                        $parseError->getLine(),
                        $parseError
                    );
                }
                catch(Exception $e) {
                    ob_end_clean();
                    throw $e;
                }

                if (!function_exists($this->getFunctionName())) {
                    $msg = str_replace('eval()\'d code', $this->getCodePath(), ob_get_clean());

                    // greedy .* ensures last match
                    if (preg_match('/.*on line (\d+)$/m', $msg, $m)) $line=$m[1]; else $line=0;
                    throw new PHPTAL_TemplateException(trim($msg), $this->getCodePath(), $line);
                }
                ob_end_clean();

            } else {
                // eval trick is used only on first run,
                // just in case it causes any problems with opcode accelerators
                require $this->getCodePath();
            }
        }

        $this->_prepared = true;
        return $this;
    }