| Source for file IncludingFileSniff.phpDocumentation is available at IncludingFileSniff.php 
 * Ensure include_once is used in conditional situations and require_once is used elsewhere. * Also checks that brackets do not surround the file being included. * @author    Greg Sherwood <gsherwood@squiz.net> * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600) * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licencenamespace PHP_CodeSniffer\Standards\PEAR\Sniffs\Files;use PHP_CodeSniffer\Sniffs\Sniff;use PHP_CodeSniffer\Files\File;use PHP_CodeSniffer\Util\Tokens;class IncludingFileSniff implements Sniff     * Returns an array of tokens this test wants to listen for.    public function register()     * Processes this test, when one of its tokens is encountered.     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.     * @param int                         $stackPtr  The position of the current token in the     *                                                stack passed in $tokens.    public function process( File $phpcsFile, $stackPtr)        $tokens = $phpcsFile-> getTokens() ;        $nextToken = $phpcsFile-> findNext( Tokens::$emptyTokens, ($stackPtr + 1), null, true) ;            $error = '"%s" is a statement not a function; no parentheses are required' ;            $data  = array($tokens[$stackPtr]['content']) ;            $fix   = $phpcsFile-> addFixableError($error, $stackPtr, 'BracketsNotRequired', $data) ;                $phpcsFile->fixer-> beginChangeset() ;                $phpcsFile->fixer-> replaceToken($tokens[$nextToken]['parenthesis_closer'], '') ;                if ($tokens[($nextToken - 1)]['code'] !== T_WHITESPACE) {                    $phpcsFile->fixer-> replaceToken($nextToken, ' ') ;                    $phpcsFile->fixer-> replaceToken($nextToken, '') ;                $phpcsFile->fixer-> endChangeset() ;        if (count($tokens[$stackPtr]['conditions']) !== 0) {        // Check to see if this including statement is within the parenthesis        // of a condition. If that's the case then we need to process it as being        // within a condition, as they are checking the return value.        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $left => $right) {                if (isset($tokens[$left]['parenthesis_owner']) === true) {        // Check to see if they are assigning the return value of this        // including call. If they are then they are probably checking it, so        $previous = $phpcsFile-> findPrevious( Tokens::$emptyTokens, ($stackPtr - 1), null, true) ;        if (isset( Tokens::$assignmentTokens[$tokens[$previous]['code']]) === true) {            // The have assigned the return value to it, so its conditional.        $tokenCode = $tokens[$stackPtr]['code'] ;        if ($inCondition === true) {            // We are inside a conditional statement. We need an include_once.            if ($tokenCode === T_REQUIRE_ONCE) {                $error  = 'File is being conditionally included; ' ;                $error .= 'use "include_once" instead' ;                $fix    = $phpcsFile-> addFixableError($error, $stackPtr, 'UseIncludeOnce') ;                    $phpcsFile->fixer-> replaceToken($stackPtr, 'include_once') ;            } else if ($tokenCode === T_REQUIRE) {                $error  = 'File is being conditionally included; ' ;                $error .= 'use "include" instead' ;                $fix    = $phpcsFile-> addFixableError($error, $stackPtr, 'UseInclude') ;                    $phpcsFile->fixer-> replaceToken($stackPtr, 'include') ;            // We are unconditionally including, we need a require_once.            if ($tokenCode === T_INCLUDE_ONCE) {                $error  = 'File is being unconditionally included; ' ;                $error .= 'use "require_once" instead' ;                $fix    = $phpcsFile-> addFixableError($error, $stackPtr, 'UseRequireOnce') ;                    $phpcsFile->fixer-> replaceToken($stackPtr, 'require_once') ;            } else if ($tokenCode === T_INCLUDE) {                $error  = 'File is being unconditionally included; ' ;                $error .= 'use "require" instead' ;                $fix    = $phpcsFile-> addFixableError($error, $stackPtr, 'UseRequire') ;                    $phpcsFile->fixer-> replaceToken($stackPtr, 'require') ;
		    
 
		    Documentation generated on Mon, 11 Mar 2019 15:27:33 -0400 by phpDocumentor 1.4.4 . PEAR Logo Copyright ©  PHP Group 2004.
	       |