@@ -15,50 +15,50 @@ |
||
| 15 | 15 | class FirebugConsoleSniff implements Sniff |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * A list of tokenizers this sniff supports. |
|
| 20 | - * |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - public $supportedTokenizers = ['JS']; |
|
| 18 | + /** |
|
| 19 | + * A list of tokenizers this sniff supports. |
|
| 20 | + * |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + public $supportedTokenizers = ['JS']; |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Returns an array of tokens this test wants to listen for. |
|
| 28 | - * |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function register() |
|
| 32 | - { |
|
| 33 | - return [ |
|
| 34 | - T_STRING, |
|
| 35 | - T_PROPERTY, |
|
| 36 | - T_LABEL, |
|
| 37 | - T_OBJECT, |
|
| 38 | - ]; |
|
| 26 | + /** |
|
| 27 | + * Returns an array of tokens this test wants to listen for. |
|
| 28 | + * |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function register() |
|
| 32 | + { |
|
| 33 | + return [ |
|
| 34 | + T_STRING, |
|
| 35 | + T_PROPERTY, |
|
| 36 | + T_LABEL, |
|
| 37 | + T_OBJECT, |
|
| 38 | + ]; |
|
| 39 | 39 | |
| 40 | - }//end register() |
|
| 40 | + }//end register() |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Processes this test, when one of its tokens is encountered. |
|
| 45 | - * |
|
| 46 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 47 | - * @param int $stackPtr The position of the current token |
|
| 48 | - * in the stack passed in $tokens. |
|
| 49 | - * |
|
| 50 | - * @return void |
|
| 51 | - */ |
|
| 52 | - public function process(File $phpcsFile, $stackPtr) |
|
| 53 | - { |
|
| 54 | - $tokens = $phpcsFile->getTokens(); |
|
| 43 | + /** |
|
| 44 | + * Processes this test, when one of its tokens is encountered. |
|
| 45 | + * |
|
| 46 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 47 | + * @param int $stackPtr The position of the current token |
|
| 48 | + * in the stack passed in $tokens. |
|
| 49 | + * |
|
| 50 | + * @return void |
|
| 51 | + */ |
|
| 52 | + public function process(File $phpcsFile, $stackPtr) |
|
| 53 | + { |
|
| 54 | + $tokens = $phpcsFile->getTokens(); |
|
| 55 | 55 | |
| 56 | - if (strtolower($tokens[$stackPtr]['content']) === 'console') { |
|
| 57 | - $error = 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable'; |
|
| 58 | - $phpcsFile->addError($error, $stackPtr, 'ConflictFound'); |
|
| 59 | - } |
|
| 56 | + if (strtolower($tokens[$stackPtr]['content']) === 'console') { |
|
| 57 | + $error = 'Variables, functions and labels must not be named "console"; name may conflict with Firebug internal variable'; |
|
| 58 | + $phpcsFile->addError($error, $stackPtr, 'ConflictFound'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - }//end process() |
|
| 61 | + }//end process() |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | }//end class |
@@ -16,126 +16,126 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns an array of tokens this test wants to listen for. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function register() |
|
| 25 | - { |
|
| 26 | - return [T_DOUBLE_COLON]; |
|
| 27 | - |
|
| 28 | - }//end register() |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Processes this sniff, when one of its tokens is encountered. |
|
| 33 | - * |
|
| 34 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | - * @param int $stackPtr The position of the current token in |
|
| 36 | - * the stack passed in $tokens. |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function process(File $phpcsFile, $stackPtr) |
|
| 41 | - { |
|
| 42 | - $tokens = $phpcsFile->getTokens(); |
|
| 43 | - |
|
| 44 | - // Check if this is a call to includeSystem, includeAsset or includeWidget. |
|
| 45 | - $methodName = strtolower($tokens[($stackPtr + 1)]['content']); |
|
| 46 | - if ($methodName === 'includesystem' |
|
| 47 | - || $methodName === 'includeasset' |
|
| 48 | - || $methodName === 'includewidget' |
|
| 49 | - ) { |
|
| 50 | - $systemName = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 3), null, true); |
|
| 51 | - if ($systemName === false || $tokens[$systemName]['code'] !== T_CONSTANT_ENCAPSED_STRING) { |
|
| 52 | - // Must be using a variable instead of a specific system name. |
|
| 53 | - // We can't accurately check that. |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $systemName = trim($tokens[$systemName]['content'], " '"); |
|
| 58 | - } else { |
|
| 59 | - return; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if ($methodName === 'includeasset') { |
|
| 63 | - $systemName .= 'assettype'; |
|
| 64 | - } else if ($methodName === 'includewidget') { |
|
| 65 | - $systemName .= 'widgettype'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $systemName = strtolower($systemName); |
|
| 69 | - |
|
| 70 | - // Now check if this system is used anywhere in this scope. |
|
| 71 | - $level = $tokens[$stackPtr]['level']; |
|
| 72 | - for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { |
|
| 73 | - if ($tokens[$i]['level'] < $level) { |
|
| 74 | - // We have gone out of scope. |
|
| 75 | - // If the original include was inside an IF statement that |
|
| 76 | - // is checking if the system exists, check the outer scope |
|
| 77 | - // as well. |
|
| 78 | - if ($tokens[$stackPtr]['level'] === $level) { |
|
| 79 | - // We are still in the base level, so this is the first |
|
| 80 | - // time we have got here. |
|
| 81 | - $conditions = array_keys($tokens[$stackPtr]['conditions']); |
|
| 82 | - if (empty($conditions) === false) { |
|
| 83 | - $cond = array_pop($conditions); |
|
| 84 | - if ($tokens[$cond]['code'] === T_IF) { |
|
| 85 | - $i = $tokens[$cond]['scope_closer']; |
|
| 86 | - $level--; |
|
| 87 | - continue; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - break; |
|
| 93 | - }//end if |
|
| 94 | - |
|
| 95 | - if ($tokens[$i]['code'] !== T_DOUBLE_COLON |
|
| 96 | - && $tokens[$i]['code'] !== T_EXTENDS |
|
| 97 | - && $tokens[$i]['code'] !== T_IMPLEMENTS |
|
| 98 | - ) { |
|
| 99 | - continue; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - switch ($tokens[$i]['code']) { |
|
| 103 | - case T_DOUBLE_COLON: |
|
| 104 | - $usedName = strtolower($tokens[($i - 1)]['content']); |
|
| 105 | - if ($usedName === $systemName) { |
|
| 106 | - // The included system was used, so it is fine. |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - break; |
|
| 110 | - case T_EXTENDS: |
|
| 111 | - $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1)); |
|
| 112 | - $className = strtolower($tokens[$classNameToken]['content']); |
|
| 113 | - if ($className === $systemName) { |
|
| 114 | - // The included system was used, so it is fine. |
|
| 115 | - return; |
|
| 116 | - } |
|
| 117 | - break; |
|
| 118 | - case T_IMPLEMENTS: |
|
| 119 | - $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1)); |
|
| 120 | - for ($x = ($i + 1); $x < $endImplements; $x++) { |
|
| 121 | - if ($tokens[$x]['code'] === T_STRING) { |
|
| 122 | - $className = strtolower($tokens[$x]['content']); |
|
| 123 | - if ($className === $systemName) { |
|
| 124 | - // The included system was used, so it is fine. |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - break; |
|
| 130 | - }//end switch |
|
| 131 | - }//end for |
|
| 132 | - |
|
| 133 | - // If we get to here, the system was not use. |
|
| 134 | - $error = 'Included system "%s" is never used'; |
|
| 135 | - $data = [$systemName]; |
|
| 136 | - $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
|
| 137 | - |
|
| 138 | - }//end process() |
|
| 19 | + /** |
|
| 20 | + * Returns an array of tokens this test wants to listen for. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function register() |
|
| 25 | + { |
|
| 26 | + return [T_DOUBLE_COLON]; |
|
| 27 | + |
|
| 28 | + }//end register() |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Processes this sniff, when one of its tokens is encountered. |
|
| 33 | + * |
|
| 34 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | + * @param int $stackPtr The position of the current token in |
|
| 36 | + * the stack passed in $tokens. |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function process(File $phpcsFile, $stackPtr) |
|
| 41 | + { |
|
| 42 | + $tokens = $phpcsFile->getTokens(); |
|
| 43 | + |
|
| 44 | + // Check if this is a call to includeSystem, includeAsset or includeWidget. |
|
| 45 | + $methodName = strtolower($tokens[($stackPtr + 1)]['content']); |
|
| 46 | + if ($methodName === 'includesystem' |
|
| 47 | + || $methodName === 'includeasset' |
|
| 48 | + || $methodName === 'includewidget' |
|
| 49 | + ) { |
|
| 50 | + $systemName = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 3), null, true); |
|
| 51 | + if ($systemName === false || $tokens[$systemName]['code'] !== T_CONSTANT_ENCAPSED_STRING) { |
|
| 52 | + // Must be using a variable instead of a specific system name. |
|
| 53 | + // We can't accurately check that. |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $systemName = trim($tokens[$systemName]['content'], " '"); |
|
| 58 | + } else { |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if ($methodName === 'includeasset') { |
|
| 63 | + $systemName .= 'assettype'; |
|
| 64 | + } else if ($methodName === 'includewidget') { |
|
| 65 | + $systemName .= 'widgettype'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $systemName = strtolower($systemName); |
|
| 69 | + |
|
| 70 | + // Now check if this system is used anywhere in this scope. |
|
| 71 | + $level = $tokens[$stackPtr]['level']; |
|
| 72 | + for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) { |
|
| 73 | + if ($tokens[$i]['level'] < $level) { |
|
| 74 | + // We have gone out of scope. |
|
| 75 | + // If the original include was inside an IF statement that |
|
| 76 | + // is checking if the system exists, check the outer scope |
|
| 77 | + // as well. |
|
| 78 | + if ($tokens[$stackPtr]['level'] === $level) { |
|
| 79 | + // We are still in the base level, so this is the first |
|
| 80 | + // time we have got here. |
|
| 81 | + $conditions = array_keys($tokens[$stackPtr]['conditions']); |
|
| 82 | + if (empty($conditions) === false) { |
|
| 83 | + $cond = array_pop($conditions); |
|
| 84 | + if ($tokens[$cond]['code'] === T_IF) { |
|
| 85 | + $i = $tokens[$cond]['scope_closer']; |
|
| 86 | + $level--; |
|
| 87 | + continue; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + break; |
|
| 93 | + }//end if |
|
| 94 | + |
|
| 95 | + if ($tokens[$i]['code'] !== T_DOUBLE_COLON |
|
| 96 | + && $tokens[$i]['code'] !== T_EXTENDS |
|
| 97 | + && $tokens[$i]['code'] !== T_IMPLEMENTS |
|
| 98 | + ) { |
|
| 99 | + continue; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + switch ($tokens[$i]['code']) { |
|
| 103 | + case T_DOUBLE_COLON: |
|
| 104 | + $usedName = strtolower($tokens[($i - 1)]['content']); |
|
| 105 | + if ($usedName === $systemName) { |
|
| 106 | + // The included system was used, so it is fine. |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + break; |
|
| 110 | + case T_EXTENDS: |
|
| 111 | + $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1)); |
|
| 112 | + $className = strtolower($tokens[$classNameToken]['content']); |
|
| 113 | + if ($className === $systemName) { |
|
| 114 | + // The included system was used, so it is fine. |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | + break; |
|
| 118 | + case T_IMPLEMENTS: |
|
| 119 | + $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1)); |
|
| 120 | + for ($x = ($i + 1); $x < $endImplements; $x++) { |
|
| 121 | + if ($tokens[$x]['code'] === T_STRING) { |
|
| 122 | + $className = strtolower($tokens[$x]['content']); |
|
| 123 | + if ($className === $systemName) { |
|
| 124 | + // The included system was used, so it is fine. |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + break; |
|
| 130 | + }//end switch |
|
| 131 | + }//end for |
|
| 132 | + |
|
| 133 | + // If we get to here, the system was not use. |
|
| 134 | + $error = 'Included system "%s" is never used'; |
|
| 135 | + $data = [$systemName]; |
|
| 136 | + $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
|
| 137 | + |
|
| 138 | + }//end process() |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | }//end class |
@@ -100,33 +100,33 @@ |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | switch ($tokens[$i]['code']) { |
| 103 | - case T_DOUBLE_COLON: |
|
| 104 | - $usedName = strtolower($tokens[($i - 1)]['content']); |
|
| 105 | - if ($usedName === $systemName) { |
|
| 106 | - // The included system was used, so it is fine. |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - break; |
|
| 110 | - case T_EXTENDS: |
|
| 111 | - $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1)); |
|
| 112 | - $className = strtolower($tokens[$classNameToken]['content']); |
|
| 113 | - if ($className === $systemName) { |
|
| 114 | - // The included system was used, so it is fine. |
|
| 115 | - return; |
|
| 116 | - } |
|
| 117 | - break; |
|
| 118 | - case T_IMPLEMENTS: |
|
| 119 | - $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1)); |
|
| 120 | - for ($x = ($i + 1); $x < $endImplements; $x++) { |
|
| 121 | - if ($tokens[$x]['code'] === T_STRING) { |
|
| 122 | - $className = strtolower($tokens[$x]['content']); |
|
| 123 | - if ($className === $systemName) { |
|
| 124 | - // The included system was used, so it is fine. |
|
| 125 | - return; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - break; |
|
| 103 | + case T_DOUBLE_COLON: |
|
| 104 | + $usedName = strtolower($tokens[($i - 1)]['content']); |
|
| 105 | + if ($usedName === $systemName) { |
|
| 106 | + // The included system was used, so it is fine. |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + break; |
|
| 110 | + case T_EXTENDS: |
|
| 111 | + $classNameToken = $phpcsFile->findNext(T_STRING, ($i + 1)); |
|
| 112 | + $className = strtolower($tokens[$classNameToken]['content']); |
|
| 113 | + if ($className === $systemName) { |
|
| 114 | + // The included system was used, so it is fine. |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | + break; |
|
| 118 | + case T_IMPLEMENTS: |
|
| 119 | + $endImplements = $phpcsFile->findNext([T_EXTENDS, T_OPEN_CURLY_BRACKET], ($i + 1)); |
|
| 120 | + for ($x = ($i + 1); $x < $endImplements; $x++) { |
|
| 121 | + if ($tokens[$x]['code'] === T_STRING) { |
|
| 122 | + $className = strtolower($tokens[$x]['content']); |
|
| 123 | + if ($className === $systemName) { |
|
| 124 | + // The included system was used, so it is fine. |
|
| 125 | + return; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + break; |
|
| 130 | 130 | }//end switch |
| 131 | 131 | }//end for |
| 132 | 132 | |
@@ -16,83 +16,83 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns an array of tokens this test wants to listen for. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function register() |
|
| 25 | - { |
|
| 26 | - return [T_DOUBLE_COLON]; |
|
| 27 | - |
|
| 28 | - }//end register() |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Processes this sniff, when one of its tokens is encountered. |
|
| 33 | - * |
|
| 34 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | - * @param int $stackPtr The position of the current token in |
|
| 36 | - * the stack passed in $tokens. |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function process(File $phpcsFile, $stackPtr) |
|
| 41 | - { |
|
| 42 | - $fileName = $phpcsFile->getFilename(); |
|
| 43 | - $matches = []; |
|
| 44 | - if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) { |
|
| 45 | - // Not an actions file. |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - $ownClass = $matches[2]; |
|
| 50 | - $tokens = $phpcsFile->getTokens(); |
|
| 51 | - |
|
| 52 | - $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true); |
|
| 53 | - $typeName = trim($tokens[$typeName]['content'], " '"); |
|
| 54 | - switch (strtolower($tokens[($stackPtr + 1)]['content'])) { |
|
| 55 | - case 'includesystem' : |
|
| 56 | - $included = strtolower($typeName); |
|
| 57 | - break; |
|
| 58 | - case 'includeasset' : |
|
| 59 | - $included = strtolower($typeName).'assettype'; |
|
| 60 | - break; |
|
| 61 | - case 'includewidget' : |
|
| 62 | - $included = strtolower($typeName).'widgettype'; |
|
| 63 | - break; |
|
| 64 | - default: |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - if ($included === strtolower($ownClass)) { |
|
| 69 | - $error = "You do not need to include \"%s\" from within the system's own actions file"; |
|
| 70 | - $data = [$ownClass]; |
|
| 71 | - $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - }//end process() |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Determines the included class name from given token. |
|
| 79 | - * |
|
| 80 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 81 | - * @param array $tokens The array of file tokens. |
|
| 82 | - * @param int $stackPtr The position in the tokens array of the |
|
| 83 | - * potentially included class. |
|
| 84 | - * |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - protected function getIncludedClassFromToken( |
|
| 88 | - $phpcsFile, |
|
| 89 | - array $tokens, |
|
| 90 | - $stackPtr |
|
| 91 | - ) { |
|
| 92 | - |
|
| 93 | - return false; |
|
| 94 | - |
|
| 95 | - }//end getIncludedClassFromToken() |
|
| 19 | + /** |
|
| 20 | + * Returns an array of tokens this test wants to listen for. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function register() |
|
| 25 | + { |
|
| 26 | + return [T_DOUBLE_COLON]; |
|
| 27 | + |
|
| 28 | + }//end register() |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Processes this sniff, when one of its tokens is encountered. |
|
| 33 | + * |
|
| 34 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | + * @param int $stackPtr The position of the current token in |
|
| 36 | + * the stack passed in $tokens. |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function process(File $phpcsFile, $stackPtr) |
|
| 41 | + { |
|
| 42 | + $fileName = $phpcsFile->getFilename(); |
|
| 43 | + $matches = []; |
|
| 44 | + if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) { |
|
| 45 | + // Not an actions file. |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + $ownClass = $matches[2]; |
|
| 50 | + $tokens = $phpcsFile->getTokens(); |
|
| 51 | + |
|
| 52 | + $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true); |
|
| 53 | + $typeName = trim($tokens[$typeName]['content'], " '"); |
|
| 54 | + switch (strtolower($tokens[($stackPtr + 1)]['content'])) { |
|
| 55 | + case 'includesystem' : |
|
| 56 | + $included = strtolower($typeName); |
|
| 57 | + break; |
|
| 58 | + case 'includeasset' : |
|
| 59 | + $included = strtolower($typeName).'assettype'; |
|
| 60 | + break; |
|
| 61 | + case 'includewidget' : |
|
| 62 | + $included = strtolower($typeName).'widgettype'; |
|
| 63 | + break; |
|
| 64 | + default: |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + if ($included === strtolower($ownClass)) { |
|
| 69 | + $error = "You do not need to include \"%s\" from within the system's own actions file"; |
|
| 70 | + $data = [$ownClass]; |
|
| 71 | + $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + }//end process() |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Determines the included class name from given token. |
|
| 79 | + * |
|
| 80 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found. |
|
| 81 | + * @param array $tokens The array of file tokens. |
|
| 82 | + * @param int $stackPtr The position in the tokens array of the |
|
| 83 | + * potentially included class. |
|
| 84 | + * |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + protected function getIncludedClassFromToken( |
|
| 88 | + $phpcsFile, |
|
| 89 | + array $tokens, |
|
| 90 | + $stackPtr |
|
| 91 | + ) { |
|
| 92 | + |
|
| 93 | + return false; |
|
| 94 | + |
|
| 95 | + }//end getIncludedClassFromToken() |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | }//end class |
@@ -52,17 +52,17 @@ |
||
| 52 | 52 | $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 2), null, false, true); |
| 53 | 53 | $typeName = trim($tokens[$typeName]['content'], " '"); |
| 54 | 54 | switch (strtolower($tokens[($stackPtr + 1)]['content'])) { |
| 55 | - case 'includesystem' : |
|
| 56 | - $included = strtolower($typeName); |
|
| 57 | - break; |
|
| 58 | - case 'includeasset' : |
|
| 59 | - $included = strtolower($typeName).'assettype'; |
|
| 60 | - break; |
|
| 61 | - case 'includewidget' : |
|
| 62 | - $included = strtolower($typeName).'widgettype'; |
|
| 63 | - break; |
|
| 64 | - default: |
|
| 65 | - return; |
|
| 55 | + case 'includesystem' : |
|
| 56 | + $included = strtolower($typeName); |
|
| 57 | + break; |
|
| 58 | + case 'includeasset' : |
|
| 59 | + $included = strtolower($typeName).'assettype'; |
|
| 60 | + break; |
|
| 61 | + case 'includewidget' : |
|
| 62 | + $included = strtolower($typeName).'widgettype'; |
|
| 63 | + break; |
|
| 64 | + default: |
|
| 65 | + return; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($included === strtolower($ownClass)) { |
@@ -15,67 +15,67 @@ |
||
| 15 | 15 | class AssignThisSniff implements Sniff |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * A list of tokenizers this sniff supports. |
|
| 20 | - * |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - public $supportedTokenizers = ['JS']; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Returns an array of tokens this test wants to listen for. |
|
| 28 | - * |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function register() |
|
| 32 | - { |
|
| 33 | - return [T_THIS]; |
|
| 34 | - |
|
| 35 | - }//end register() |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Processes this test, when one of its tokens is encountered. |
|
| 40 | - * |
|
| 41 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 42 | - * @param int $stackPtr The position of the current token |
|
| 43 | - * in the stack passed in $tokens. |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - public function process(File $phpcsFile, $stackPtr) |
|
| 48 | - { |
|
| 49 | - $tokens = $phpcsFile->getTokens(); |
|
| 50 | - |
|
| 51 | - // Ignore this.something and other uses of "this" that are not |
|
| 52 | - // direct assignments. |
|
| 53 | - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 54 | - if ($tokens[$next]['code'] !== T_SEMICOLON) { |
|
| 55 | - if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // Something must be assigned to "this". |
|
| 61 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
| 62 | - if ($tokens[$prev]['code'] !== T_EQUAL) { |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // A variable needs to be assigned to "this". |
|
| 67 | - $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true); |
|
| 68 | - if ($tokens[$prev]['code'] !== T_STRING) { |
|
| 69 | - return; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // We can only assign "this" to a var called "self". |
|
| 73 | - if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') { |
|
| 74 | - $error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"'; |
|
| 75 | - $phpcsFile->addError($error, $prev, 'NotSelf'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - }//end process() |
|
| 18 | + /** |
|
| 19 | + * A list of tokenizers this sniff supports. |
|
| 20 | + * |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + public $supportedTokenizers = ['JS']; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Returns an array of tokens this test wants to listen for. |
|
| 28 | + * |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function register() |
|
| 32 | + { |
|
| 33 | + return [T_THIS]; |
|
| 34 | + |
|
| 35 | + }//end register() |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Processes this test, when one of its tokens is encountered. |
|
| 40 | + * |
|
| 41 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 42 | + * @param int $stackPtr The position of the current token |
|
| 43 | + * in the stack passed in $tokens. |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + public function process(File $phpcsFile, $stackPtr) |
|
| 48 | + { |
|
| 49 | + $tokens = $phpcsFile->getTokens(); |
|
| 50 | + |
|
| 51 | + // Ignore this.something and other uses of "this" that are not |
|
| 52 | + // direct assignments. |
|
| 53 | + $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 54 | + if ($tokens[$next]['code'] !== T_SEMICOLON) { |
|
| 55 | + if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // Something must be assigned to "this". |
|
| 61 | + $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true); |
|
| 62 | + if ($tokens[$prev]['code'] !== T_EQUAL) { |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // A variable needs to be assigned to "this". |
|
| 67 | + $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($prev - 1), null, true); |
|
| 68 | + if ($tokens[$prev]['code'] !== T_STRING) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // We can only assign "this" to a var called "self". |
|
| 73 | + if ($tokens[$prev]['content'] !== 'self' && $tokens[$prev]['content'] !== '_self') { |
|
| 74 | + $error = 'Keyword "this" can only be assigned to a variable called "self" or "_self"'; |
|
| 75 | + $phpcsFile->addError($error, $prev, 'NotSelf'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + }//end process() |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | 81 | }//end class |
@@ -16,44 +16,44 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns an array of tokens this test wants to listen for. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public function register() |
|
| 25 | - { |
|
| 26 | - return [T_NEW]; |
|
| 27 | - |
|
| 28 | - }//end register() |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Processes this test, when one of its tokens is encountered. |
|
| 33 | - * |
|
| 34 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | - * @param int $stackPtr The position of the current token |
|
| 36 | - * in the stack passed in $tokens. |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function process(File $phpcsFile, $stackPtr) |
|
| 41 | - { |
|
| 42 | - $tokens = $phpcsFile->getTokens(); |
|
| 43 | - |
|
| 44 | - $className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 45 | - if ($tokens[$className]['code'] !== T_STRING) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') { |
|
| 50 | - $widgetType = substr($tokens[$className]['content'], 0, -10); |
|
| 51 | - $error = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead'; |
|
| 52 | - $data = [$widgetType]; |
|
| 53 | - $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - }//end process() |
|
| 19 | + /** |
|
| 20 | + * Returns an array of tokens this test wants to listen for. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public function register() |
|
| 25 | + { |
|
| 26 | + return [T_NEW]; |
|
| 27 | + |
|
| 28 | + }//end register() |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Processes this test, when one of its tokens is encountered. |
|
| 33 | + * |
|
| 34 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 35 | + * @param int $stackPtr The position of the current token |
|
| 36 | + * in the stack passed in $tokens. |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function process(File $phpcsFile, $stackPtr) |
|
| 41 | + { |
|
| 42 | + $tokens = $phpcsFile->getTokens(); |
|
| 43 | + |
|
| 44 | + $className = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
| 45 | + if ($tokens[$className]['code'] !== T_STRING) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') { |
|
| 50 | + $widgetType = substr($tokens[$className]['content'], 0, -10); |
|
| 51 | + $error = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead'; |
|
| 52 | + $data = [$widgetType]; |
|
| 53 | + $phpcsFile->addError($error, $stackPtr, 'Found', $data); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + }//end process() |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | }//end class |
@@ -19,66 +19,66 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Processes this test, when one of its tokens is encountered. |
|
| 24 | - * |
|
| 25 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 26 | - * @param int $stackPtr The position of the current token |
|
| 27 | - * in the stack passed in $tokens. |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function process(File $phpcsFile, $stackPtr) |
|
| 32 | - { |
|
| 33 | - parent::process($phpcsFile, $stackPtr); |
|
| 22 | + /** |
|
| 23 | + * Processes this test, when one of its tokens is encountered. |
|
| 24 | + * |
|
| 25 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
| 26 | + * @param int $stackPtr The position of the current token |
|
| 27 | + * in the stack passed in $tokens. |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function process(File $phpcsFile, $stackPtr) |
|
| 32 | + { |
|
| 33 | + parent::process($phpcsFile, $stackPtr); |
|
| 34 | 34 | |
| 35 | - $tokens = $phpcsFile->getTokens(); |
|
| 36 | - $find = Tokens::$methodPrefixes; |
|
| 37 | - $find[] = T_WHITESPACE; |
|
| 35 | + $tokens = $phpcsFile->getTokens(); |
|
| 36 | + $find = Tokens::$methodPrefixes; |
|
| 37 | + $find[] = T_WHITESPACE; |
|
| 38 | 38 | |
| 39 | - $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
| 40 | - if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { |
|
| 41 | - return; |
|
| 42 | - } |
|
| 39 | + $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true); |
|
| 40 | + if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) { |
|
| 41 | + return; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $commentStart = $tokens[$commentEnd]['comment_opener']; |
|
| 45 | - $hasApiTag = false; |
|
| 46 | - foreach ($tokens[$commentStart]['comment_tags'] as $tag) { |
|
| 47 | - if ($tokens[$tag]['content'] === '@api') { |
|
| 48 | - if ($hasApiTag === true) { |
|
| 49 | - // We've come across an API tag already, which means |
|
| 50 | - // we were not the first tag in the API list. |
|
| 51 | - $error = 'The @api tag must come first in the @api tag list in a function comment'; |
|
| 52 | - $phpcsFile->addError($error, $tag, 'ApiNotFirst'); |
|
| 53 | - } |
|
| 44 | + $commentStart = $tokens[$commentEnd]['comment_opener']; |
|
| 45 | + $hasApiTag = false; |
|
| 46 | + foreach ($tokens[$commentStart]['comment_tags'] as $tag) { |
|
| 47 | + if ($tokens[$tag]['content'] === '@api') { |
|
| 48 | + if ($hasApiTag === true) { |
|
| 49 | + // We've come across an API tag already, which means |
|
| 50 | + // we were not the first tag in the API list. |
|
| 51 | + $error = 'The @api tag must come first in the @api tag list in a function comment'; |
|
| 52 | + $phpcsFile->addError($error, $tag, 'ApiNotFirst'); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - $hasApiTag = true; |
|
| 55 | + $hasApiTag = true; |
|
| 56 | 56 | |
| 57 | - // There needs to be a blank line before the @api tag. |
|
| 58 | - $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1)); |
|
| 59 | - if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 2)) { |
|
| 60 | - $error = 'There must be one blank line before the @api tag in a function comment'; |
|
| 61 | - $phpcsFile->addError($error, $tag, 'ApiSpacing'); |
|
| 62 | - } |
|
| 63 | - } else if (substr($tokens[$tag]['content'], 0, 5) === '@api-') { |
|
| 64 | - $hasApiTag = true; |
|
| 57 | + // There needs to be a blank line before the @api tag. |
|
| 58 | + $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1)); |
|
| 59 | + if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 2)) { |
|
| 60 | + $error = 'There must be one blank line before the @api tag in a function comment'; |
|
| 61 | + $phpcsFile->addError($error, $tag, 'ApiSpacing'); |
|
| 62 | + } |
|
| 63 | + } else if (substr($tokens[$tag]['content'], 0, 5) === '@api-') { |
|
| 64 | + $hasApiTag = true; |
|
| 65 | 65 | |
| 66 | - $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1)); |
|
| 67 | - if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 1)) { |
|
| 68 | - $error = 'There must be no blank line before the @%s tag in a function comment'; |
|
| 69 | - $data = [$tokens[$tag]['content']]; |
|
| 70 | - $phpcsFile->addError($error, $tag, 'ApiTagSpacing', $data); |
|
| 71 | - } |
|
| 72 | - }//end if |
|
| 73 | - }//end foreach |
|
| 66 | + $prev = $phpcsFile->findPrevious([T_DOC_COMMENT_STRING, T_DOC_COMMENT_TAG], ($tag - 1)); |
|
| 67 | + if ($tokens[$prev]['line'] !== ($tokens[$tag]['line'] - 1)) { |
|
| 68 | + $error = 'There must be no blank line before the @%s tag in a function comment'; |
|
| 69 | + $data = [$tokens[$tag]['content']]; |
|
| 70 | + $phpcsFile->addError($error, $tag, 'ApiTagSpacing', $data); |
|
| 71 | + } |
|
| 72 | + }//end if |
|
| 73 | + }//end foreach |
|
| 74 | 74 | |
| 75 | - if ($hasApiTag === true && substr($tokens[$tag]['content'], 0, 4) !== '@api') { |
|
| 76 | - // API tags must be the last tags in a function comment. |
|
| 77 | - $error = 'The @api tags must be the last tags in a function comment'; |
|
| 78 | - $phpcsFile->addError($error, $commentEnd, 'ApiNotLast'); |
|
| 79 | - } |
|
| 75 | + if ($hasApiTag === true && substr($tokens[$tag]['content'], 0, 4) !== '@api') { |
|
| 76 | + // API tags must be the last tags in a function comment. |
|
| 77 | + $error = 'The @api tags must be the last tags in a function comment'; |
|
| 78 | + $phpcsFile->addError($error, $commentEnd, 'ApiNotLast'); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - }//end process() |
|
| 81 | + }//end process() |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | }//end class |
@@ -107,7 +107,7 @@ |
||
| 107 | 107 | * |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function addFile($path, $file=null) |
|
| 110 | + public function addFile($path, $file = null) |
|
| 111 | 111 | { |
| 112 | 112 | // No filtering is done for STDIN when the filename |
| 113 | 113 | // has not been specified. |
@@ -21,235 +21,235 @@ |
||
| 21 | 21 | class FileList implements \Iterator, \Countable |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A list of file paths that are included in the list. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - private $files = []; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * The number of files in the list. |
|
| 33 | - * |
|
| 34 | - * @var integer |
|
| 35 | - */ |
|
| 36 | - private $numFiles = 0; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * The config data for the run. |
|
| 40 | - * |
|
| 41 | - * @var \PHP_CodeSniffer\Config |
|
| 42 | - */ |
|
| 43 | - public $config = null; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * The ruleset used for the run. |
|
| 47 | - * |
|
| 48 | - * @var \PHP_CodeSniffer\Ruleset |
|
| 49 | - */ |
|
| 50 | - public $ruleset = null; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * An array of patterns to use for skipping files. |
|
| 54 | - * |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 57 | - protected $ignorePatterns = []; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Constructs a file list and loads in an array of file paths to process. |
|
| 62 | - * |
|
| 63 | - * @param \PHP_CodeSniffer\Config $config The config data for the run. |
|
| 64 | - * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run. |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function __construct(Config $config, Ruleset $ruleset) |
|
| 69 | - { |
|
| 70 | - $this->ruleset = $ruleset; |
|
| 71 | - $this->config = $config; |
|
| 72 | - |
|
| 73 | - $paths = $config->files; |
|
| 74 | - foreach ($paths as $path) { |
|
| 75 | - $isPharFile = Util\Common::isPharFile($path); |
|
| 76 | - if (is_dir($path) === true || $isPharFile === true) { |
|
| 77 | - if ($isPharFile === true) { |
|
| 78 | - $path = 'phar://'.$path; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $filterClass = $this->getFilterClass(); |
|
| 82 | - |
|
| 83 | - $di = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)); |
|
| 84 | - $filter = new $filterClass($di, $path, $config, $ruleset); |
|
| 85 | - $iterator = new \RecursiveIteratorIterator($filter); |
|
| 86 | - |
|
| 87 | - foreach ($iterator as $file) { |
|
| 88 | - $this->files[$file->getPathname()] = null; |
|
| 89 | - $this->numFiles++; |
|
| 90 | - } |
|
| 91 | - } else { |
|
| 92 | - $this->addFile($path); |
|
| 93 | - }//end if |
|
| 94 | - }//end foreach |
|
| 95 | - |
|
| 96 | - reset($this->files); |
|
| 97 | - |
|
| 98 | - }//end __construct() |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Add a file to the list. |
|
| 103 | - * |
|
| 104 | - * If a file object has already been created, it can be passed here. |
|
| 105 | - * If it is left NULL, it will be created when accessed. |
|
| 106 | - * |
|
| 107 | - * @param string $path The path to the file being added. |
|
| 108 | - * @param \PHP_CodeSniffer\Files\File $file The file being added. |
|
| 109 | - * |
|
| 110 | - * @return void |
|
| 111 | - */ |
|
| 112 | - public function addFile($path, $file=null) |
|
| 113 | - { |
|
| 114 | - // No filtering is done for STDIN when the filename |
|
| 115 | - // has not been specified. |
|
| 116 | - if ($path === 'STDIN') { |
|
| 117 | - $this->files[$path] = $file; |
|
| 118 | - $this->numFiles++; |
|
| 119 | - return; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $filterClass = $this->getFilterClass(); |
|
| 123 | - |
|
| 124 | - $di = new \RecursiveArrayIterator([$path]); |
|
| 125 | - $filter = new $filterClass($di, $path, $this->config, $this->ruleset); |
|
| 126 | - $iterator = new \RecursiveIteratorIterator($filter); |
|
| 127 | - |
|
| 128 | - foreach ($iterator as $path) { |
|
| 129 | - $this->files[$path] = $file; |
|
| 130 | - $this->numFiles++; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - }//end addFile() |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get the class name of the filter being used for the run. |
|
| 138 | - * |
|
| 139 | - * @return string |
|
| 140 | - * @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the specified filter could not be found. |
|
| 141 | - */ |
|
| 142 | - private function getFilterClass() |
|
| 143 | - { |
|
| 144 | - $filterType = $this->config->filter; |
|
| 145 | - |
|
| 146 | - if ($filterType === null) { |
|
| 147 | - $filterClass = '\PHP_CodeSniffer\Filters\Filter'; |
|
| 148 | - } else { |
|
| 149 | - if (strpos($filterType, '.') !== false) { |
|
| 150 | - // This is a path to a custom filter class. |
|
| 151 | - $filename = realpath($filterType); |
|
| 152 | - if ($filename === false) { |
|
| 153 | - $error = "ERROR: Custom filter \"$filterType\" not found".PHP_EOL; |
|
| 154 | - throw new DeepExitException($error, 3); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $filterClass = Autoload::loadFile($filename); |
|
| 158 | - } else { |
|
| 159 | - $filterClass = '\PHP_CodeSniffer\Filters\\'.$filterType; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $filterClass; |
|
| 164 | - |
|
| 165 | - }//end getFilterClass() |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Rewind the iterator to the first file. |
|
| 170 | - * |
|
| 171 | - * @return void |
|
| 172 | - */ |
|
| 173 | - #[ReturnTypeWillChange] |
|
| 174 | - public function rewind() |
|
| 175 | - { |
|
| 176 | - reset($this->files); |
|
| 177 | - |
|
| 178 | - }//end rewind() |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the file that is currently being processed. |
|
| 183 | - * |
|
| 184 | - * @return \PHP_CodeSniffer\Files\File |
|
| 185 | - */ |
|
| 186 | - #[ReturnTypeWillChange] |
|
| 187 | - public function current() |
|
| 188 | - { |
|
| 189 | - $path = key($this->files); |
|
| 190 | - if (isset($this->files[$path]) === false) { |
|
| 191 | - $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $this->files[$path]; |
|
| 195 | - |
|
| 196 | - }//end current() |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Return the file path of the current file being processed. |
|
| 201 | - * |
|
| 202 | - * @return void |
|
| 203 | - */ |
|
| 204 | - #[ReturnTypeWillChange] |
|
| 205 | - public function key() |
|
| 206 | - { |
|
| 207 | - return key($this->files); |
|
| 208 | - |
|
| 209 | - }//end key() |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Move forward to the next file. |
|
| 214 | - * |
|
| 215 | - * @return void |
|
| 216 | - */ |
|
| 217 | - #[ReturnTypeWillChange] |
|
| 218 | - public function next() |
|
| 219 | - { |
|
| 220 | - next($this->files); |
|
| 221 | - |
|
| 222 | - }//end next() |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Checks if current position is valid. |
|
| 227 | - * |
|
| 228 | - * @return boolean |
|
| 229 | - */ |
|
| 230 | - #[ReturnTypeWillChange] |
|
| 231 | - public function valid() |
|
| 232 | - { |
|
| 233 | - if (current($this->files) === false) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return true; |
|
| 238 | - |
|
| 239 | - }//end valid() |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Return the number of files in the list. |
|
| 244 | - * |
|
| 245 | - * @return integer |
|
| 246 | - */ |
|
| 247 | - #[ReturnTypeWillChange] |
|
| 248 | - public function count() |
|
| 249 | - { |
|
| 250 | - return $this->numFiles; |
|
| 251 | - |
|
| 252 | - }//end count() |
|
| 24 | + /** |
|
| 25 | + * A list of file paths that are included in the list. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + private $files = []; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * The number of files in the list. |
|
| 33 | + * |
|
| 34 | + * @var integer |
|
| 35 | + */ |
|
| 36 | + private $numFiles = 0; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * The config data for the run. |
|
| 40 | + * |
|
| 41 | + * @var \PHP_CodeSniffer\Config |
|
| 42 | + */ |
|
| 43 | + public $config = null; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * The ruleset used for the run. |
|
| 47 | + * |
|
| 48 | + * @var \PHP_CodeSniffer\Ruleset |
|
| 49 | + */ |
|
| 50 | + public $ruleset = null; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * An array of patterns to use for skipping files. |
|
| 54 | + * |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | + protected $ignorePatterns = []; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Constructs a file list and loads in an array of file paths to process. |
|
| 62 | + * |
|
| 63 | + * @param \PHP_CodeSniffer\Config $config The config data for the run. |
|
| 64 | + * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run. |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function __construct(Config $config, Ruleset $ruleset) |
|
| 69 | + { |
|
| 70 | + $this->ruleset = $ruleset; |
|
| 71 | + $this->config = $config; |
|
| 72 | + |
|
| 73 | + $paths = $config->files; |
|
| 74 | + foreach ($paths as $path) { |
|
| 75 | + $isPharFile = Util\Common::isPharFile($path); |
|
| 76 | + if (is_dir($path) === true || $isPharFile === true) { |
|
| 77 | + if ($isPharFile === true) { |
|
| 78 | + $path = 'phar://'.$path; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $filterClass = $this->getFilterClass(); |
|
| 82 | + |
|
| 83 | + $di = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS)); |
|
| 84 | + $filter = new $filterClass($di, $path, $config, $ruleset); |
|
| 85 | + $iterator = new \RecursiveIteratorIterator($filter); |
|
| 86 | + |
|
| 87 | + foreach ($iterator as $file) { |
|
| 88 | + $this->files[$file->getPathname()] = null; |
|
| 89 | + $this->numFiles++; |
|
| 90 | + } |
|
| 91 | + } else { |
|
| 92 | + $this->addFile($path); |
|
| 93 | + }//end if |
|
| 94 | + }//end foreach |
|
| 95 | + |
|
| 96 | + reset($this->files); |
|
| 97 | + |
|
| 98 | + }//end __construct() |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Add a file to the list. |
|
| 103 | + * |
|
| 104 | + * If a file object has already been created, it can be passed here. |
|
| 105 | + * If it is left NULL, it will be created when accessed. |
|
| 106 | + * |
|
| 107 | + * @param string $path The path to the file being added. |
|
| 108 | + * @param \PHP_CodeSniffer\Files\File $file The file being added. |
|
| 109 | + * |
|
| 110 | + * @return void |
|
| 111 | + */ |
|
| 112 | + public function addFile($path, $file=null) |
|
| 113 | + { |
|
| 114 | + // No filtering is done for STDIN when the filename |
|
| 115 | + // has not been specified. |
|
| 116 | + if ($path === 'STDIN') { |
|
| 117 | + $this->files[$path] = $file; |
|
| 118 | + $this->numFiles++; |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $filterClass = $this->getFilterClass(); |
|
| 123 | + |
|
| 124 | + $di = new \RecursiveArrayIterator([$path]); |
|
| 125 | + $filter = new $filterClass($di, $path, $this->config, $this->ruleset); |
|
| 126 | + $iterator = new \RecursiveIteratorIterator($filter); |
|
| 127 | + |
|
| 128 | + foreach ($iterator as $path) { |
|
| 129 | + $this->files[$path] = $file; |
|
| 130 | + $this->numFiles++; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + }//end addFile() |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get the class name of the filter being used for the run. |
|
| 138 | + * |
|
| 139 | + * @return string |
|
| 140 | + * @throws \PHP_CodeSniffer\Exceptions\DeepExitException If the specified filter could not be found. |
|
| 141 | + */ |
|
| 142 | + private function getFilterClass() |
|
| 143 | + { |
|
| 144 | + $filterType = $this->config->filter; |
|
| 145 | + |
|
| 146 | + if ($filterType === null) { |
|
| 147 | + $filterClass = '\PHP_CodeSniffer\Filters\Filter'; |
|
| 148 | + } else { |
|
| 149 | + if (strpos($filterType, '.') !== false) { |
|
| 150 | + // This is a path to a custom filter class. |
|
| 151 | + $filename = realpath($filterType); |
|
| 152 | + if ($filename === false) { |
|
| 153 | + $error = "ERROR: Custom filter \"$filterType\" not found".PHP_EOL; |
|
| 154 | + throw new DeepExitException($error, 3); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $filterClass = Autoload::loadFile($filename); |
|
| 158 | + } else { |
|
| 159 | + $filterClass = '\PHP_CodeSniffer\Filters\\'.$filterType; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return $filterClass; |
|
| 164 | + |
|
| 165 | + }//end getFilterClass() |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Rewind the iterator to the first file. |
|
| 170 | + * |
|
| 171 | + * @return void |
|
| 172 | + */ |
|
| 173 | + #[ReturnTypeWillChange] |
|
| 174 | + public function rewind() |
|
| 175 | + { |
|
| 176 | + reset($this->files); |
|
| 177 | + |
|
| 178 | + }//end rewind() |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the file that is currently being processed. |
|
| 183 | + * |
|
| 184 | + * @return \PHP_CodeSniffer\Files\File |
|
| 185 | + */ |
|
| 186 | + #[ReturnTypeWillChange] |
|
| 187 | + public function current() |
|
| 188 | + { |
|
| 189 | + $path = key($this->files); |
|
| 190 | + if (isset($this->files[$path]) === false) { |
|
| 191 | + $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $this->files[$path]; |
|
| 195 | + |
|
| 196 | + }//end current() |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Return the file path of the current file being processed. |
|
| 201 | + * |
|
| 202 | + * @return void |
|
| 203 | + */ |
|
| 204 | + #[ReturnTypeWillChange] |
|
| 205 | + public function key() |
|
| 206 | + { |
|
| 207 | + return key($this->files); |
|
| 208 | + |
|
| 209 | + }//end key() |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Move forward to the next file. |
|
| 214 | + * |
|
| 215 | + * @return void |
|
| 216 | + */ |
|
| 217 | + #[ReturnTypeWillChange] |
|
| 218 | + public function next() |
|
| 219 | + { |
|
| 220 | + next($this->files); |
|
| 221 | + |
|
| 222 | + }//end next() |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Checks if current position is valid. |
|
| 227 | + * |
|
| 228 | + * @return boolean |
|
| 229 | + */ |
|
| 230 | + #[ReturnTypeWillChange] |
|
| 231 | + public function valid() |
|
| 232 | + { |
|
| 233 | + if (current($this->files) === false) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return true; |
|
| 238 | + |
|
| 239 | + }//end valid() |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Return the number of files in the list. |
|
| 244 | + * |
|
| 245 | + * @return integer |
|
| 246 | + */ |
|
| 247 | + #[ReturnTypeWillChange] |
|
| 248 | + public function count() |
|
| 249 | + { |
|
| 250 | + return $this->numFiles; |
|
| 251 | + |
|
| 252 | + }//end count() |
|
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | }//end class |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | do { |
| 51 | 51 | $modified[$path] = true; |
| 52 | 52 | $path = dirname($path); |
| 53 | - } while ($path !== $basedir); |
|
| 53 | + }while ($path !== $basedir); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | return $modified; |
@@ -15,52 +15,52 @@ |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Get a list of blacklisted file paths. |
|
| 20 | - * |
|
| 21 | - * @return array |
|
| 22 | - */ |
|
| 23 | - protected function getBlacklist() |
|
| 24 | - { |
|
| 25 | - return []; |
|
| 26 | - |
|
| 27 | - }//end getBlacklist() |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Get a list of whitelisted file paths. |
|
| 32 | - * |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - protected function getWhitelist() |
|
| 36 | - { |
|
| 37 | - $modified = []; |
|
| 38 | - |
|
| 39 | - $cmd = 'git ls-files -o -m --exclude-standard -- '.escapeshellarg($this->basedir); |
|
| 40 | - $output = []; |
|
| 41 | - exec($cmd, $output); |
|
| 42 | - |
|
| 43 | - $basedir = $this->basedir; |
|
| 44 | - if (is_dir($basedir) === false) { |
|
| 45 | - $basedir = dirname($basedir); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - foreach ($output as $path) { |
|
| 49 | - $path = Util\Common::realpath($path); |
|
| 50 | - |
|
| 51 | - if ($path === false) { |
|
| 52 | - continue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - do { |
|
| 56 | - $modified[$path] = true; |
|
| 57 | - $path = dirname($path); |
|
| 58 | - } while ($path !== $basedir); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $modified; |
|
| 62 | - |
|
| 63 | - }//end getWhitelist() |
|
| 18 | + /** |
|
| 19 | + * Get a list of blacklisted file paths. |
|
| 20 | + * |
|
| 21 | + * @return array |
|
| 22 | + */ |
|
| 23 | + protected function getBlacklist() |
|
| 24 | + { |
|
| 25 | + return []; |
|
| 26 | + |
|
| 27 | + }//end getBlacklist() |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Get a list of whitelisted file paths. |
|
| 32 | + * |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + protected function getWhitelist() |
|
| 36 | + { |
|
| 37 | + $modified = []; |
|
| 38 | + |
|
| 39 | + $cmd = 'git ls-files -o -m --exclude-standard -- '.escapeshellarg($this->basedir); |
|
| 40 | + $output = []; |
|
| 41 | + exec($cmd, $output); |
|
| 42 | + |
|
| 43 | + $basedir = $this->basedir; |
|
| 44 | + if (is_dir($basedir) === false) { |
|
| 45 | + $basedir = dirname($basedir); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + foreach ($output as $path) { |
|
| 49 | + $path = Util\Common::realpath($path); |
|
| 50 | + |
|
| 51 | + if ($path === false) { |
|
| 52 | + continue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + do { |
|
| 56 | + $modified[$path] = true; |
|
| 57 | + $path = dirname($path); |
|
| 58 | + } while ($path !== $basedir); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $modified; |
|
| 62 | + |
|
| 63 | + }//end getWhitelist() |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | 66 | }//end class |
@@ -16,93 +16,93 @@ |
||
| 16 | 16 | abstract class ExactMatch extends Filter |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * A list of files to exclude. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - private $blacklist = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * A list of files to include. |
|
| 28 | - * |
|
| 29 | - * If the whitelist is empty, only files in the blacklist will be excluded. |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - private $whitelist = null; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Check whether the current element of the iterator is acceptable. |
|
| 38 | - * |
|
| 39 | - * If a file is both blacklisted and whitelisted, it will be deemed unacceptable. |
|
| 40 | - * |
|
| 41 | - * @return bool |
|
| 42 | - */ |
|
| 43 | - public function accept() |
|
| 44 | - { |
|
| 45 | - if (parent::accept() === false) { |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - if ($this->blacklist === null) { |
|
| 50 | - $this->blacklist = $this->getblacklist(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($this->whitelist === null) { |
|
| 54 | - $this->whitelist = $this->getwhitelist(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $filePath = Util\Common::realpath($this->current()); |
|
| 58 | - |
|
| 59 | - // If file is both blacklisted and whitelisted, the blacklist takes precedence. |
|
| 60 | - if (isset($this->blacklist[$filePath]) === true) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (empty($this->whitelist) === true && empty($this->blacklist) === false) { |
|
| 65 | - // We are only checking a blacklist, so everything else should be whitelisted. |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return isset($this->whitelist[$filePath]); |
|
| 70 | - |
|
| 71 | - }//end accept() |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Returns an iterator for the current entry. |
|
| 76 | - * |
|
| 77 | - * Ensures that the blacklist and whitelist are preserved so they don't have |
|
| 78 | - * to be generated each time. |
|
| 79 | - * |
|
| 80 | - * @return \RecursiveIterator |
|
| 81 | - */ |
|
| 82 | - public function getChildren() |
|
| 83 | - { |
|
| 84 | - $children = parent::getChildren(); |
|
| 85 | - $children->blacklist = $this->blacklist; |
|
| 86 | - $children->whitelist = $this->whitelist; |
|
| 87 | - return $children; |
|
| 88 | - |
|
| 89 | - }//end getChildren() |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Get a list of blacklisted file paths. |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - abstract protected function getBlacklist(); |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Get a list of whitelisted file paths. |
|
| 102 | - * |
|
| 103 | - * @return array |
|
| 104 | - */ |
|
| 105 | - abstract protected function getWhitelist(); |
|
| 19 | + /** |
|
| 20 | + * A list of files to exclude. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + private $blacklist = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * A list of files to include. |
|
| 28 | + * |
|
| 29 | + * If the whitelist is empty, only files in the blacklist will be excluded. |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + private $whitelist = null; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Check whether the current element of the iterator is acceptable. |
|
| 38 | + * |
|
| 39 | + * If a file is both blacklisted and whitelisted, it will be deemed unacceptable. |
|
| 40 | + * |
|
| 41 | + * @return bool |
|
| 42 | + */ |
|
| 43 | + public function accept() |
|
| 44 | + { |
|
| 45 | + if (parent::accept() === false) { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + if ($this->blacklist === null) { |
|
| 50 | + $this->blacklist = $this->getblacklist(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($this->whitelist === null) { |
|
| 54 | + $this->whitelist = $this->getwhitelist(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $filePath = Util\Common::realpath($this->current()); |
|
| 58 | + |
|
| 59 | + // If file is both blacklisted and whitelisted, the blacklist takes precedence. |
|
| 60 | + if (isset($this->blacklist[$filePath]) === true) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (empty($this->whitelist) === true && empty($this->blacklist) === false) { |
|
| 65 | + // We are only checking a blacklist, so everything else should be whitelisted. |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return isset($this->whitelist[$filePath]); |
|
| 70 | + |
|
| 71 | + }//end accept() |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Returns an iterator for the current entry. |
|
| 76 | + * |
|
| 77 | + * Ensures that the blacklist and whitelist are preserved so they don't have |
|
| 78 | + * to be generated each time. |
|
| 79 | + * |
|
| 80 | + * @return \RecursiveIterator |
|
| 81 | + */ |
|
| 82 | + public function getChildren() |
|
| 83 | + { |
|
| 84 | + $children = parent::getChildren(); |
|
| 85 | + $children->blacklist = $this->blacklist; |
|
| 86 | + $children->whitelist = $this->whitelist; |
|
| 87 | + return $children; |
|
| 88 | + |
|
| 89 | + }//end getChildren() |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Get a list of blacklisted file paths. |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + abstract protected function getBlacklist(); |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Get a list of whitelisted file paths. |
|
| 102 | + * |
|
| 103 | + * @return array |
|
| 104 | + */ |
|
| 105 | + abstract protected function getWhitelist(); |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | }//end class |