@@ -15,46 +15,46 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @return array<int, int> |
|
25 | - */ |
|
26 | - public function getErrorList() |
|
27 | - { |
|
28 | - return [ |
|
29 | - 9 => 1, |
|
30 | - 14 => 1, |
|
31 | - 24 => 1, |
|
32 | - 27 => 1, |
|
33 | - 28 => 1, |
|
34 | - 31 => 1, |
|
35 | - 36 => 1, |
|
36 | - 41 => 1, |
|
37 | - 61 => 1, |
|
38 | - 70 => 1, |
|
39 | - 89 => 1, |
|
40 | - ]; |
|
41 | - |
|
42 | - }//end getErrorList() |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns the lines where warnings should occur. |
|
47 | - * |
|
48 | - * The key of the array should represent the line number and the value |
|
49 | - * should represent the number of warnings that should occur on that line. |
|
50 | - * |
|
51 | - * @return array<int, int> |
|
52 | - */ |
|
53 | - public function getWarningList() |
|
54 | - { |
|
55 | - return []; |
|
56 | - |
|
57 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @return array<int, int> |
|
25 | + */ |
|
26 | + public function getErrorList() |
|
27 | + { |
|
28 | + return [ |
|
29 | + 9 => 1, |
|
30 | + 14 => 1, |
|
31 | + 24 => 1, |
|
32 | + 27 => 1, |
|
33 | + 28 => 1, |
|
34 | + 31 => 1, |
|
35 | + 36 => 1, |
|
36 | + 41 => 1, |
|
37 | + 61 => 1, |
|
38 | + 70 => 1, |
|
39 | + 89 => 1, |
|
40 | + ]; |
|
41 | + |
|
42 | + }//end getErrorList() |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns the lines where warnings should occur. |
|
47 | + * |
|
48 | + * The key of the array should represent the line number and the value |
|
49 | + * should represent the number of warnings that should occur on that line. |
|
50 | + * |
|
51 | + * @return array<int, int> |
|
52 | + */ |
|
53 | + public function getWarningList() |
|
54 | + { |
|
55 | + return []; |
|
56 | + |
|
57 | + }//end getWarningList() |
|
58 | 58 | |
59 | 59 | |
60 | 60 | }//end class |
@@ -15,41 +15,41 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @return array<int, int> |
|
25 | - */ |
|
26 | - public function getErrorList() |
|
27 | - { |
|
28 | - return [ |
|
29 | - 2 => 1, |
|
30 | - 5 => 1, |
|
31 | - 8 => 1, |
|
32 | - 24 => 1, |
|
33 | - 34 => 1, |
|
34 | - 54 => 1, |
|
35 | - ]; |
|
36 | - |
|
37 | - }//end getErrorList() |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Returns the lines where warnings should occur. |
|
42 | - * |
|
43 | - * The key of the array should represent the line number and the value |
|
44 | - * should represent the number of warnings that should occur on that line. |
|
45 | - * |
|
46 | - * @return array<int, int> |
|
47 | - */ |
|
48 | - public function getWarningList() |
|
49 | - { |
|
50 | - return []; |
|
51 | - |
|
52 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @return array<int, int> |
|
25 | + */ |
|
26 | + public function getErrorList() |
|
27 | + { |
|
28 | + return [ |
|
29 | + 2 => 1, |
|
30 | + 5 => 1, |
|
31 | + 8 => 1, |
|
32 | + 24 => 1, |
|
33 | + 34 => 1, |
|
34 | + 54 => 1, |
|
35 | + ]; |
|
36 | + |
|
37 | + }//end getErrorList() |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Returns the lines where warnings should occur. |
|
42 | + * |
|
43 | + * The key of the array should represent the line number and the value |
|
44 | + * should represent the number of warnings that should occur on that line. |
|
45 | + * |
|
46 | + * @return array<int, int> |
|
47 | + */ |
|
48 | + public function getWarningList() |
|
49 | + { |
|
50 | + return []; |
|
51 | + |
|
52 | + }//end getWarningList() |
|
53 | 53 | |
54 | 54 | |
55 | 55 | }//end class |
@@ -15,44 +15,44 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @param string $testFile The name of the file being tested. |
|
25 | - * |
|
26 | - * @return array<int, int> |
|
27 | - */ |
|
28 | - public function getErrorList($testFile='AssignThisUnitTest.js') |
|
29 | - { |
|
30 | - if ($testFile !== 'AssignThisUnitTest.js') { |
|
31 | - return []; |
|
32 | - } |
|
33 | - |
|
34 | - return [ |
|
35 | - 7 => 1, |
|
36 | - 11 => 1, |
|
37 | - 16 => 1, |
|
38 | - ]; |
|
39 | - |
|
40 | - }//end getErrorList() |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Returns the lines where warnings should occur. |
|
45 | - * |
|
46 | - * The key of the array should represent the line number and the value |
|
47 | - * should represent the number of warnings that should occur on that line. |
|
48 | - * |
|
49 | - * @return array<int, int> |
|
50 | - */ |
|
51 | - public function getWarningList() |
|
52 | - { |
|
53 | - return []; |
|
54 | - |
|
55 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @param string $testFile The name of the file being tested. |
|
25 | + * |
|
26 | + * @return array<int, int> |
|
27 | + */ |
|
28 | + public function getErrorList($testFile='AssignThisUnitTest.js') |
|
29 | + { |
|
30 | + if ($testFile !== 'AssignThisUnitTest.js') { |
|
31 | + return []; |
|
32 | + } |
|
33 | + |
|
34 | + return [ |
|
35 | + 7 => 1, |
|
36 | + 11 => 1, |
|
37 | + 16 => 1, |
|
38 | + ]; |
|
39 | + |
|
40 | + }//end getErrorList() |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Returns the lines where warnings should occur. |
|
45 | + * |
|
46 | + * The key of the array should represent the line number and the value |
|
47 | + * should represent the number of warnings that should occur on that line. |
|
48 | + * |
|
49 | + * @return array<int, int> |
|
50 | + */ |
|
51 | + public function getWarningList() |
|
52 | + { |
|
53 | + return []; |
|
54 | + |
|
55 | + }//end getWarningList() |
|
56 | 56 | |
57 | 57 | |
58 | 58 | }//end class |
@@ -25,7 +25,7 @@ |
||
25 | 25 | * |
26 | 26 | * @return array<int, int> |
27 | 27 | */ |
28 | - public function getErrorList($testFile='AssignThisUnitTest.js') |
|
28 | + public function getErrorList($testFile = 'AssignThisUnitTest.js') |
|
29 | 29 | { |
30 | 30 | if ($testFile !== 'AssignThisUnitTest.js') { |
31 | 31 | return []; |
@@ -15,34 +15,34 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @return array<int, int> |
|
25 | - */ |
|
26 | - public function getErrorList() |
|
27 | - { |
|
28 | - return [4 => 1]; |
|
29 | - |
|
30 | - }//end getErrorList() |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Returns the lines where warnings should occur. |
|
35 | - * |
|
36 | - * The key of the array should represent the line number and the value |
|
37 | - * should represent the number of warnings that should occur on that line. |
|
38 | - * |
|
39 | - * @return array<int, int> |
|
40 | - */ |
|
41 | - public function getWarningList() |
|
42 | - { |
|
43 | - return []; |
|
44 | - |
|
45 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @return array<int, int> |
|
25 | + */ |
|
26 | + public function getErrorList() |
|
27 | + { |
|
28 | + return [4 => 1]; |
|
29 | + |
|
30 | + }//end getErrorList() |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Returns the lines where warnings should occur. |
|
35 | + * |
|
36 | + * The key of the array should represent the line number and the value |
|
37 | + * should represent the number of warnings that should occur on that line. |
|
38 | + * |
|
39 | + * @return array<int, int> |
|
40 | + */ |
|
41 | + public function getWarningList() |
|
42 | + { |
|
43 | + return []; |
|
44 | + |
|
45 | + }//end getWarningList() |
|
46 | 46 | |
47 | 47 | |
48 | 48 | }//end class |
@@ -15,45 +15,45 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @param string $testFile The name of the file being tested. |
|
25 | - * |
|
26 | - * @return array<int, int> |
|
27 | - */ |
|
28 | - public function getErrorList($testFile='CreateWidgetTypeCallbackUnitTest.js') |
|
29 | - { |
|
30 | - return [ |
|
31 | - 18 => 1, |
|
32 | - 23 => 2, |
|
33 | - 26 => 1, |
|
34 | - 30 => 1, |
|
35 | - 34 => 1, |
|
36 | - 43 => 2, |
|
37 | - 91 => 1, |
|
38 | - 123 => 1, |
|
39 | - ]; |
|
40 | - |
|
41 | - }//end getErrorList() |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Returns the lines where warnings should occur. |
|
46 | - * |
|
47 | - * The key of the array should represent the line number and the value |
|
48 | - * should represent the number of warnings that should occur on that line. |
|
49 | - * |
|
50 | - * @return array<int, int> |
|
51 | - */ |
|
52 | - public function getWarningList() |
|
53 | - { |
|
54 | - return []; |
|
55 | - |
|
56 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @param string $testFile The name of the file being tested. |
|
25 | + * |
|
26 | + * @return array<int, int> |
|
27 | + */ |
|
28 | + public function getErrorList($testFile='CreateWidgetTypeCallbackUnitTest.js') |
|
29 | + { |
|
30 | + return [ |
|
31 | + 18 => 1, |
|
32 | + 23 => 2, |
|
33 | + 26 => 1, |
|
34 | + 30 => 1, |
|
35 | + 34 => 1, |
|
36 | + 43 => 2, |
|
37 | + 91 => 1, |
|
38 | + 123 => 1, |
|
39 | + ]; |
|
40 | + |
|
41 | + }//end getErrorList() |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Returns the lines where warnings should occur. |
|
46 | + * |
|
47 | + * The key of the array should represent the line number and the value |
|
48 | + * should represent the number of warnings that should occur on that line. |
|
49 | + * |
|
50 | + * @return array<int, int> |
|
51 | + */ |
|
52 | + public function getWarningList() |
|
53 | + { |
|
54 | + return []; |
|
55 | + |
|
56 | + }//end getWarningList() |
|
57 | 57 | |
58 | 58 | |
59 | 59 | }//end class |
@@ -25,7 +25,7 @@ |
||
25 | 25 | * |
26 | 26 | * @return array<int, int> |
27 | 27 | */ |
28 | - public function getErrorList($testFile='CreateWidgetTypeCallbackUnitTest.js') |
|
28 | + public function getErrorList($testFile = 'CreateWidgetTypeCallbackUnitTest.js') |
|
29 | 29 | { |
30 | 30 | return [ |
31 | 31 | 18 => 1, |
@@ -15,40 +15,40 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the lines where errors should occur. |
|
20 | - * |
|
21 | - * The key of the array should represent the line number and the value |
|
22 | - * should represent the number of errors that should occur on that line. |
|
23 | - * |
|
24 | - * @return array<int, int> |
|
25 | - */ |
|
26 | - public function getErrorList() |
|
27 | - { |
|
28 | - return [ |
|
29 | - 28 => 1, |
|
30 | - 36 => 1, |
|
31 | - 37 => 2, |
|
32 | - 49 => 1, |
|
33 | - 58 => 1, |
|
34 | - ]; |
|
35 | - |
|
36 | - }//end getErrorList() |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns the lines where warnings should occur. |
|
41 | - * |
|
42 | - * The key of the array should represent the line number and the value |
|
43 | - * should represent the number of warnings that should occur on that line. |
|
44 | - * |
|
45 | - * @return array<int, int> |
|
46 | - */ |
|
47 | - public function getWarningList() |
|
48 | - { |
|
49 | - return []; |
|
50 | - |
|
51 | - }//end getWarningList() |
|
18 | + /** |
|
19 | + * Returns the lines where errors should occur. |
|
20 | + * |
|
21 | + * The key of the array should represent the line number and the value |
|
22 | + * should represent the number of errors that should occur on that line. |
|
23 | + * |
|
24 | + * @return array<int, int> |
|
25 | + */ |
|
26 | + public function getErrorList() |
|
27 | + { |
|
28 | + return [ |
|
29 | + 28 => 1, |
|
30 | + 36 => 1, |
|
31 | + 37 => 2, |
|
32 | + 49 => 1, |
|
33 | + 58 => 1, |
|
34 | + ]; |
|
35 | + |
|
36 | + }//end getErrorList() |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns the lines where warnings should occur. |
|
41 | + * |
|
42 | + * The key of the array should represent the line number and the value |
|
43 | + * should represent the number of warnings that should occur on that line. |
|
44 | + * |
|
45 | + * @return array<int, int> |
|
46 | + */ |
|
47 | + public function getWarningList() |
|
48 | + { |
|
49 | + return []; |
|
50 | + |
|
51 | + }//end getWarningList() |
|
52 | 52 | |
53 | 53 | |
54 | 54 | }//end class |
@@ -16,48 +16,48 @@ |
||
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_RETURN]; |
|
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 | - $functionName = $phpcsFile->findNext(T_STRING, ($stackPtr + 1), null, false, null, true); |
|
45 | - |
|
46 | - while ($functionName !== false) { |
|
47 | - // Check if this is really a function. |
|
48 | - $bracket = $phpcsFile->findNext(T_WHITESPACE, ($functionName + 1), null, true); |
|
49 | - if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { |
|
50 | - // Not a function call. |
|
51 | - $functionName = $phpcsFile->findNext(T_STRING, ($functionName + 1), null, false, null, true); |
|
52 | - continue; |
|
53 | - } |
|
54 | - |
|
55 | - $error = 'The result of a function call should be assigned to a variable before being returned'; |
|
56 | - $phpcsFile->addWarning($error, $stackPtr, 'NotAssigned'); |
|
57 | - break; |
|
58 | - } |
|
59 | - |
|
60 | - }//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_RETURN]; |
|
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 | + $functionName = $phpcsFile->findNext(T_STRING, ($stackPtr + 1), null, false, null, true); |
|
45 | + |
|
46 | + while ($functionName !== false) { |
|
47 | + // Check if this is really a function. |
|
48 | + $bracket = $phpcsFile->findNext(T_WHITESPACE, ($functionName + 1), null, true); |
|
49 | + if ($tokens[$bracket]['code'] !== T_OPEN_PARENTHESIS) { |
|
50 | + // Not a function call. |
|
51 | + $functionName = $phpcsFile->findNext(T_STRING, ($functionName + 1), null, false, null, true); |
|
52 | + continue; |
|
53 | + } |
|
54 | + |
|
55 | + $error = 'The result of a function call should be assigned to a variable before being returned'; |
|
56 | + $phpcsFile->addWarning($error, $stackPtr, 'NotAssigned'); |
|
57 | + break; |
|
58 | + } |
|
59 | + |
|
60 | + }//end process() |
|
61 | 61 | |
62 | 62 | |
63 | 63 | }//end class |
@@ -16,91 +16,91 @@ |
||
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_VARIABLE]; |
|
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 | - $varName = $tokens[$stackPtr]['content']; |
|
45 | - if ($varName !== '$_REQUEST' |
|
46 | - && $varName !== '$_GET' |
|
47 | - && $varName !== '$_POST' |
|
48 | - && $varName !== '$_FILES' |
|
49 | - ) { |
|
50 | - return; |
|
51 | - } |
|
52 | - |
|
53 | - // The only place these super globals can be accessed directly is |
|
54 | - // in the getRequestData() method of the Security class. |
|
55 | - $inClass = false; |
|
56 | - foreach ($tokens[$stackPtr]['conditions'] as $i => $type) { |
|
57 | - if ($tokens[$i]['code'] === T_CLASS) { |
|
58 | - $className = $phpcsFile->findNext(T_STRING, $i); |
|
59 | - $className = $tokens[$className]['content']; |
|
60 | - if (strtolower($className) === 'security') { |
|
61 | - $inClass = true; |
|
62 | - } else { |
|
63 | - // We don't have nested classes. |
|
64 | - break; |
|
65 | - } |
|
66 | - } else if ($inClass === true && $tokens[$i]['code'] === T_FUNCTION) { |
|
67 | - $funcName = $phpcsFile->findNext(T_STRING, $i); |
|
68 | - $funcName = $tokens[$funcName]['content']; |
|
69 | - if (strtolower($funcName) === 'getrequestdata') { |
|
70 | - // This is valid. |
|
71 | - return; |
|
72 | - } else { |
|
73 | - // We don't have nested functions. |
|
74 | - break; |
|
75 | - } |
|
76 | - }//end if |
|
77 | - }//end foreach |
|
78 | - |
|
79 | - // If we get to here, the super global was used incorrectly. |
|
80 | - // First find out how it is being used. |
|
81 | - $globalName = strtolower(substr($varName, 2)); |
|
82 | - $usedVar = ''; |
|
83 | - |
|
84 | - $openBracket = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
85 | - if ($tokens[$openBracket]['code'] === T_OPEN_SQUARE_BRACKET) { |
|
86 | - $closeBracket = $tokens[$openBracket]['bracket_closer']; |
|
87 | - $usedVar = $phpcsFile->getTokensAsString(($openBracket + 1), ($closeBracket - $openBracket - 1)); |
|
88 | - } |
|
89 | - |
|
90 | - $type = 'SuperglobalAccessed'; |
|
91 | - $error = 'The %s super global must not be accessed directly; use Security::getRequestData('; |
|
92 | - $data = [$varName]; |
|
93 | - if ($usedVar !== '') { |
|
94 | - $type .= 'WithVar'; |
|
95 | - $error .= '%s, \'%s\''; |
|
96 | - $data[] = $usedVar; |
|
97 | - $data[] = $globalName; |
|
98 | - } |
|
99 | - |
|
100 | - $error .= ') instead'; |
|
101 | - $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
102 | - |
|
103 | - }//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_VARIABLE]; |
|
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 | + $varName = $tokens[$stackPtr]['content']; |
|
45 | + if ($varName !== '$_REQUEST' |
|
46 | + && $varName !== '$_GET' |
|
47 | + && $varName !== '$_POST' |
|
48 | + && $varName !== '$_FILES' |
|
49 | + ) { |
|
50 | + return; |
|
51 | + } |
|
52 | + |
|
53 | + // The only place these super globals can be accessed directly is |
|
54 | + // in the getRequestData() method of the Security class. |
|
55 | + $inClass = false; |
|
56 | + foreach ($tokens[$stackPtr]['conditions'] as $i => $type) { |
|
57 | + if ($tokens[$i]['code'] === T_CLASS) { |
|
58 | + $className = $phpcsFile->findNext(T_STRING, $i); |
|
59 | + $className = $tokens[$className]['content']; |
|
60 | + if (strtolower($className) === 'security') { |
|
61 | + $inClass = true; |
|
62 | + } else { |
|
63 | + // We don't have nested classes. |
|
64 | + break; |
|
65 | + } |
|
66 | + } else if ($inClass === true && $tokens[$i]['code'] === T_FUNCTION) { |
|
67 | + $funcName = $phpcsFile->findNext(T_STRING, $i); |
|
68 | + $funcName = $tokens[$funcName]['content']; |
|
69 | + if (strtolower($funcName) === 'getrequestdata') { |
|
70 | + // This is valid. |
|
71 | + return; |
|
72 | + } else { |
|
73 | + // We don't have nested functions. |
|
74 | + break; |
|
75 | + } |
|
76 | + }//end if |
|
77 | + }//end foreach |
|
78 | + |
|
79 | + // If we get to here, the super global was used incorrectly. |
|
80 | + // First find out how it is being used. |
|
81 | + $globalName = strtolower(substr($varName, 2)); |
|
82 | + $usedVar = ''; |
|
83 | + |
|
84 | + $openBracket = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); |
|
85 | + if ($tokens[$openBracket]['code'] === T_OPEN_SQUARE_BRACKET) { |
|
86 | + $closeBracket = $tokens[$openBracket]['bracket_closer']; |
|
87 | + $usedVar = $phpcsFile->getTokensAsString(($openBracket + 1), ($closeBracket - $openBracket - 1)); |
|
88 | + } |
|
89 | + |
|
90 | + $type = 'SuperglobalAccessed'; |
|
91 | + $error = 'The %s super global must not be accessed directly; use Security::getRequestData('; |
|
92 | + $data = [$varName]; |
|
93 | + if ($usedVar !== '') { |
|
94 | + $type .= 'WithVar'; |
|
95 | + $error .= '%s, \'%s\''; |
|
96 | + $data[] = $usedVar; |
|
97 | + $data[] = $globalName; |
|
98 | + } |
|
99 | + |
|
100 | + $error .= ') instead'; |
|
101 | + $phpcsFile->addError($error, $stackPtr, $type, $data); |
|
102 | + |
|
103 | + }//end process() |
|
104 | 104 | |
105 | 105 | |
106 | 106 | }//end class |
@@ -16,61 +16,61 @@ |
||
16 | 16 | class JoinStringsSniff implements Sniff |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * A list of tokenizers this sniff supports. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - public $supportedTokenizers = ['JS']; |
|
19 | + /** |
|
20 | + * A list of tokenizers this sniff supports. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + public $supportedTokenizers = ['JS']; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Returns an array of tokens this test wants to listen for. |
|
29 | - * |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function register() |
|
33 | - { |
|
34 | - return [T_STRING]; |
|
27 | + /** |
|
28 | + * Returns an array of tokens this test wants to listen for. |
|
29 | + * |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function register() |
|
33 | + { |
|
34 | + return [T_STRING]; |
|
35 | 35 | |
36 | - }//end register() |
|
36 | + }//end register() |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Processes this test, when one of its tokens is encountered. |
|
41 | - * |
|
42 | - * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
43 | - * @param integer $stackPtr The position of the current token |
|
44 | - * in the stack passed in $tokens. |
|
45 | - * |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function process(File $phpcsFile, $stackPtr) |
|
49 | - { |
|
50 | - $tokens = $phpcsFile->getTokens(); |
|
39 | + /** |
|
40 | + * Processes this test, when one of its tokens is encountered. |
|
41 | + * |
|
42 | + * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
|
43 | + * @param integer $stackPtr The position of the current token |
|
44 | + * in the stack passed in $tokens. |
|
45 | + * |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function process(File $phpcsFile, $stackPtr) |
|
49 | + { |
|
50 | + $tokens = $phpcsFile->getTokens(); |
|
51 | 51 | |
52 | - if ($tokens[$stackPtr]['content'] !== 'join') { |
|
53 | - return; |
|
54 | - } |
|
52 | + if ($tokens[$stackPtr]['content'] !== 'join') { |
|
53 | + return; |
|
54 | + } |
|
55 | 55 | |
56 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
57 | - if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) { |
|
58 | - return; |
|
59 | - } |
|
56 | + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
57 | + if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR) { |
|
58 | + return; |
|
59 | + } |
|
60 | 60 | |
61 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); |
|
62 | - if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) { |
|
63 | - $opener = $tokens[$prev]['bracket_opener']; |
|
64 | - if ($tokens[($opener - 1)]['code'] !== T_STRING) { |
|
65 | - // This means the array is declared inline, like x = [a,b,c].join() |
|
66 | - // and not elsewhere, like x = y[a].join() |
|
67 | - // The first is not allowed while the second is. |
|
68 | - $error = 'Joining strings using inline arrays is not allowed; use the + operator instead'; |
|
69 | - $phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed'); |
|
70 | - } |
|
71 | - } |
|
61 | + $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prev - 1), null, true); |
|
62 | + if ($tokens[$prev]['code'] === T_CLOSE_SQUARE_BRACKET) { |
|
63 | + $opener = $tokens[$prev]['bracket_opener']; |
|
64 | + if ($tokens[($opener - 1)]['code'] !== T_STRING) { |
|
65 | + // This means the array is declared inline, like x = [a,b,c].join() |
|
66 | + // and not elsewhere, like x = y[a].join() |
|
67 | + // The first is not allowed while the second is. |
|
68 | + $error = 'Joining strings using inline arrays is not allowed; use the + operator instead'; |
|
69 | + $phpcsFile->addError($error, $stackPtr, 'ArrayNotAllowed'); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - }//end process() |
|
73 | + }//end process() |
|
74 | 74 | |
75 | 75 | |
76 | 76 | }//end class |