Completed
Branch fix-build-process (200f3b)
by
unknown
15:09 queued 04:26
created
src/Standards/Generic/Tests/Metrics/NestingLevelUnitTest.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
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 [73 => 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
-            27 => 1,
45
-            46 => 1,
46
-        ];
47
-
48
-    }//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 [73 => 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
+			27 => 1,
45
+			46 => 1,
46
+		];
47
+
48
+	}//end getWarningList()
49 49
 
50 50
 
51 51
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.3.inc 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace A\B {
3
-    class MyClass {}
4
-    interface MyInterface {}
3
+	class MyClass {}
4
+	interface MyInterface {}
5 5
 }
6 6
 
7 7
 namespace D {
8
-    class MyClass {}
8
+	class MyClass {}
9 9
 }
10 10
 ?>
11 11
\ No newline at end of file
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Classes/OpeningBraceSameLineUnitTest.inc 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 
53 53
 // This is OK.
54 54
 class A_Class_With_Really_Long_Name
55
-    extends Another_Class_With_A_Really_Long_Name {
55
+	extends Another_Class_With_A_Really_Long_Name {
56 56
 
57 57
 }
58 58
 
59 59
 // This is OK too.
60 60
 class A_Class_With_Really_Long_Name_2
61
-    extends Another_Class_With_A_Really_Long_Name
62
-    implements Some_Interface_With_A_Long_Name,
63
-          Another_Interface_With_A_Long_Name {
61
+	extends Another_Class_With_A_Really_Long_Name
62
+	implements Some_Interface_With_A_Long_Name,
63
+		  Another_Interface_With_A_Long_Name {
64 64
 
65 65
 }
66 66
 
67 67
 // But this is not.
68 68
 class A_Class_With_Really_Long_Name_3
69
-    extends Another_Class_With_A_Really_Long_Name
69
+	extends Another_Class_With_A_Really_Long_Name
70 70
 	{
71 71
 
72 72
 }
73 73
 
74 74
 // Nor is this.
75 75
 class A_Class_With_Really_Long_Name_4
76
-    extends Another_Class_With_A_Really_Long_Name
77
-    implements Some_Interface_With_A_Long_Name,
78
-          Another_Interface_With_A_Long_Name
76
+	extends Another_Class_With_A_Really_Long_Name
77
+	implements Some_Interface_With_A_Long_Name,
78
+		  Another_Interface_With_A_Long_Name
79 79
 {
80 80
 
81 81
 }
@@ -86,6 +86,6 @@  discard block
 block discarded – undo
86 86
 
87 87
 // And this is not.
88 88
 class Test_Class_Bad_G
89
-    /*some comment*/
89
+	/*some comment*/
90 90
 {
91 91
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,16 +35,16 @@
 block discarded – undo
35 35
 }
36 36
 
37 37
 // These should all be flagged for wrong whitespace before opening brace.
38
-interface Test_Interface_Bad_C   {
38
+interface Test_Interface_Bad_C {
39 39
 }
40 40
 
41
-class Test_Class_Bad_G	{		
41
+class Test_Class_Bad_G {		
42 42
 }
43 43
 
44
-class Test_Class_Bad_H extends Test_Class_Bad_G			{
44
+class Test_Class_Bad_H extends Test_Class_Bad_G {
45 45
 }
46 46
 
47
-class Test_Class_Bad_I implements Test_Interface_Bad_C{
47
+class Test_Class_Bad_I implements Test_Interface_Bad_C {
48 48
 }
49 49
 
50 50
 // This one should be flagged as a potential parse error.
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
      *
41 41
      * @return array<int, int>
42 42
      */
43
-    public function getWarningList($testFile='')
43
+    public function getWarningList($testFile = '')
44 44
     {
45 45
         switch ($testFile) {
46 46
         case 'DuplicateClassNameUnitTest.1.inc':
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@
 block discarded – undo
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 [];
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 29
 
30
-    }//end getErrorList()
30
+	}//end getErrorList()
31 31
 
32 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
-     * @param string $testFile The name of the file being tested.
40
-     *
41
-     * @return array<int, int>
42
-     */
43
-    public function getWarningList($testFile='')
44
-    {
45
-        switch ($testFile) {
46
-        case 'DuplicateClassNameUnitTest.1.inc':
47
-            return [
48
-                10 => 1,
49
-                11 => 1,
50
-                12 => 1,
51
-                13 => 1,
52
-            ];
53
-            break;
54
-        case 'DuplicateClassNameUnitTest.2.inc':
55
-            return [
56
-                2 => 1,
57
-                3 => 1,
58
-                4 => 1,
59
-                5 => 1,
60
-            ];
61
-            break;
62
-        case 'DuplicateClassNameUnitTest.5.inc':
63
-            return [
64
-                3 => 1,
65
-                7 => 1,
66
-            ];
67
-            break;
68
-        case 'DuplicateClassNameUnitTest.6.inc':
69
-            return [10 => 1];
70
-            break;
71
-        default:
72
-            return [];
73
-            break;
74
-        }//end switch
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
+	 * @param string $testFile The name of the file being tested.
40
+	 *
41
+	 * @return array<int, int>
42
+	 */
43
+	public function getWarningList($testFile='')
44
+	{
45
+		switch ($testFile) {
46
+		case 'DuplicateClassNameUnitTest.1.inc':
47
+			return [
48
+				10 => 1,
49
+				11 => 1,
50
+				12 => 1,
51
+				13 => 1,
52
+			];
53
+			break;
54
+		case 'DuplicateClassNameUnitTest.2.inc':
55
+			return [
56
+				2 => 1,
57
+				3 => 1,
58
+				4 => 1,
59
+				5 => 1,
60
+			];
61
+			break;
62
+		case 'DuplicateClassNameUnitTest.5.inc':
63
+			return [
64
+				3 => 1,
65
+				7 => 1,
66
+			];
67
+			break;
68
+		case 'DuplicateClassNameUnitTest.6.inc':
69
+			return [10 => 1];
70
+			break;
71
+		default:
72
+			return [];
73
+			break;
74
+		}//end switch
75 75
 
76
-    }//end getWarningList()
76
+	}//end getWarningList()
77 77
 
78 78
 
79 79
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -43,34 +43,34 @@
 block discarded – undo
43 43
     public function getWarningList($testFile='')
44 44
     {
45 45
         switch ($testFile) {
46
-        case 'DuplicateClassNameUnitTest.1.inc':
47
-            return [
48
-                10 => 1,
49
-                11 => 1,
50
-                12 => 1,
51
-                13 => 1,
52
-            ];
53
-            break;
54
-        case 'DuplicateClassNameUnitTest.2.inc':
55
-            return [
56
-                2 => 1,
57
-                3 => 1,
58
-                4 => 1,
59
-                5 => 1,
60
-            ];
61
-            break;
62
-        case 'DuplicateClassNameUnitTest.5.inc':
63
-            return [
64
-                3 => 1,
65
-                7 => 1,
66
-            ];
67
-            break;
68
-        case 'DuplicateClassNameUnitTest.6.inc':
69
-            return [10 => 1];
70
-            break;
71
-        default:
72
-            return [];
73
-            break;
46
+        	case 'DuplicateClassNameUnitTest.1.inc':
47
+            	return [
48
+                	10 => 1,
49
+                	11 => 1,
50
+                	12 => 1,
51
+                	13 => 1,
52
+            	];
53
+            	break;
54
+        	case 'DuplicateClassNameUnitTest.2.inc':
55
+            	return [
56
+                	2 => 1,
57
+                	3 => 1,
58
+                	4 => 1,
59
+                	5 => 1,
60
+            	];
61
+            	break;
62
+        	case 'DuplicateClassNameUnitTest.5.inc':
63
+            	return [
64
+                	3 => 1,
65
+                	7 => 1,
66
+            	];
67
+            	break;
68
+        	case 'DuplicateClassNameUnitTest.6.inc':
69
+            	return [10 => 1];
70
+            	break;
71
+        	default:
72
+            	return [];
73
+            	break;
74 74
         }//end switch
75 75
 
76 76
     }//end getWarningList()
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Classes/DuplicateClassNameUnitTest.6.inc 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 class Test{
3
-    public function testOne(){
4
-     ?>
3
+	public function testOne(){
4
+	 ?>
5 5
      <p>some html here</p>
6 6
     <?php 
7 7
    }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2
-class Test{
3
-    public function testOne(){
2
+class Test {
3
+    public function testOne() {
4 4
      ?>
5 5
      <p>some html here</p>
6 6
     <?php 
7 7
    }
8 8
 }
9 9
 
10
-class Test{
10
+class Test {
11 11
 
12 12
 }
Please login to merge, or discard this patch.
Standards/Generic/Sniffs/CodeAnalysis/ForLoopWithTestFunctionCallSniff.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -34,68 +34,68 @@
 block discarded – undo
34 34
 {
35 35
 
36 36
 
37
-    /**
38
-     * Registers the tokens that this sniff wants to listen for.
39
-     *
40
-     * @return int[]
41
-     */
42
-    public function register()
43
-    {
44
-        return [T_FOR];
45
-
46
-    }//end register()
47
-
48
-
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
53
-     * @param int                         $stackPtr  The position of the current token
54
-     *                                               in the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        $tokens = $phpcsFile->getTokens();
61
-        $token  = $tokens[$stackPtr];
62
-
63
-        // Skip invalid statement.
64
-        if (isset($token['parenthesis_opener']) === false) {
65
-            return;
66
-        }
67
-
68
-        $next = ++$token['parenthesis_opener'];
69
-        $end  = --$token['parenthesis_closer'];
70
-
71
-        $position = 0;
72
-
73
-        for (; $next <= $end; ++$next) {
74
-            $code = $tokens[$next]['code'];
75
-            if ($code === T_SEMICOLON) {
76
-                ++$position;
77
-            }
78
-
79
-            if ($position < 1) {
80
-                continue;
81
-            } else if ($position > 1) {
82
-                break;
83
-            } else if ($code !== T_VARIABLE && $code !== T_STRING) {
84
-                continue;
85
-            }
86
-
87
-            // Find next non empty token, if it is a open curly brace we have a
88
-            // function call.
89
-            $index = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
90
-
91
-            if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) {
92
-                $error = 'Avoid function calls in a FOR loop test part';
93
-                $phpcsFile->addWarning($error, $stackPtr, 'NotAllowed');
94
-                break;
95
-            }
96
-        }//end for
97
-
98
-    }//end process()
37
+	/**
38
+	 * Registers the tokens that this sniff wants to listen for.
39
+	 *
40
+	 * @return int[]
41
+	 */
42
+	public function register()
43
+	{
44
+		return [T_FOR];
45
+
46
+	}//end register()
47
+
48
+
49
+	/**
50
+	 * Processes this test, when one of its tokens is encountered.
51
+	 *
52
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
53
+	 * @param int                         $stackPtr  The position of the current token
54
+	 *                                               in the stack passed in $tokens.
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		$tokens = $phpcsFile->getTokens();
61
+		$token  = $tokens[$stackPtr];
62
+
63
+		// Skip invalid statement.
64
+		if (isset($token['parenthesis_opener']) === false) {
65
+			return;
66
+		}
67
+
68
+		$next = ++$token['parenthesis_opener'];
69
+		$end  = --$token['parenthesis_closer'];
70
+
71
+		$position = 0;
72
+
73
+		for (; $next <= $end; ++$next) {
74
+			$code = $tokens[$next]['code'];
75
+			if ($code === T_SEMICOLON) {
76
+				++$position;
77
+			}
78
+
79
+			if ($position < 1) {
80
+				continue;
81
+			} else if ($position > 1) {
82
+				break;
83
+			} else if ($code !== T_VARIABLE && $code !== T_STRING) {
84
+				continue;
85
+			}
86
+
87
+			// Find next non empty token, if it is a open curly brace we have a
88
+			// function call.
89
+			$index = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
90
+
91
+			if ($tokens[$index]['code'] === T_OPEN_PARENTHESIS) {
92
+				$error = 'Avoid function calls in a FOR loop test part';
93
+				$phpcsFile->addWarning($error, $stackPtr, 'NotAllowed');
94
+				break;
95
+			}
96
+		}//end for
97
+
98
+	}//end process()
99 99
 
100 100
 
101 101
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -30,56 +30,56 @@
 block discarded – undo
30 30
 {
31 31
 
32 32
 
33
-    /**
34
-     * Registers the tokens that this sniff wants to listen for.
35
-     *
36
-     * @return int[]
37
-     */
38
-    public function register()
39
-    {
40
-        return [T_CLASS];
41
-
42
-    }//end register()
43
-
44
-
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
-     * @param int                         $stackPtr  The position of the current token
50
-     *                                               in the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        $tokens = $phpcsFile->getTokens();
57
-        $token  = $tokens[$stackPtr];
58
-
59
-        // Skip for-statements without body.
60
-        if (isset($token['scope_opener']) === false) {
61
-            return;
62
-        }
63
-
64
-        // Fetch previous token.
65
-        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
66
-
67
-        // Skip for non final class.
68
-        if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) {
69
-            return;
70
-        }
71
-
72
-        $next = ++$token['scope_opener'];
73
-        $end  = --$token['scope_closer'];
74
-
75
-        for (; $next <= $end; ++$next) {
76
-            if ($tokens[$next]['code'] === T_FINAL) {
77
-                $error = 'Unnecessary FINAL modifier in FINAL class';
78
-                $phpcsFile->addWarning($error, $next, 'Found');
79
-            }
80
-        }
81
-
82
-    }//end process()
33
+	/**
34
+	 * Registers the tokens that this sniff wants to listen for.
35
+	 *
36
+	 * @return int[]
37
+	 */
38
+	public function register()
39
+	{
40
+		return [T_CLASS];
41
+
42
+	}//end register()
43
+
44
+
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
+	 * @param int                         $stackPtr  The position of the current token
50
+	 *                                               in the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		$tokens = $phpcsFile->getTokens();
57
+		$token  = $tokens[$stackPtr];
58
+
59
+		// Skip for-statements without body.
60
+		if (isset($token['scope_opener']) === false) {
61
+			return;
62
+		}
63
+
64
+		// Fetch previous token.
65
+		$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
66
+
67
+		// Skip for non final class.
68
+		if ($prev === false || $tokens[$prev]['code'] !== T_FINAL) {
69
+			return;
70
+		}
71
+
72
+		$next = ++$token['scope_opener'];
73
+		$end  = --$token['scope_closer'];
74
+
75
+		for (; $next <= $end; ++$next) {
76
+			if ($tokens[$next]['code'] === T_FINAL) {
77
+				$error = 'Unnecessary FINAL modifier in FINAL class';
78
+				$phpcsFile->addWarning($error, $next, 'Found');
79
+			}
80
+		}
81
+
82
+	}//end process()
83 83
 
84 84
 
85 85
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -36,99 +36,99 @@
 block discarded – undo
36 36
 {
37 37
 
38 38
 
39
-    /**
40
-     * Registers the tokens that this sniff wants to listen for.
41
-     *
42
-     * @return int[]
43
-     */
44
-    public function register()
45
-    {
46
-        return [T_FOR];
47
-
48
-    }//end register()
49
-
50
-
51
-    /**
52
-     * Processes this test, when one of its tokens is encountered.
53
-     *
54
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
55
-     * @param int                         $stackPtr  The position of the current token
56
-     *                                               in the stack passed in $tokens.
57
-     *
58
-     * @return void
59
-     */
60
-    public function process(File $phpcsFile, $stackPtr)
61
-    {
62
-        $tokens = $phpcsFile->getTokens();
63
-        $token  = $tokens[$stackPtr];
64
-
65
-        // Skip for-loop without body.
66
-        if (isset($token['scope_opener']) === false) {
67
-            return;
68
-        }
69
-
70
-        // Find incrementors for outer loop.
71
-        $outer = $this->findIncrementers($tokens, $token);
72
-
73
-        // Skip if empty.
74
-        if (count($outer) === 0) {
75
-            return;
76
-        }
77
-
78
-        // Find nested for loops.
79
-        $start = ++$token['scope_opener'];
80
-        $end   = --$token['scope_closer'];
81
-
82
-        for (; $start <= $end; ++$start) {
83
-            if ($tokens[$start]['code'] !== T_FOR) {
84
-                continue;
85
-            }
86
-
87
-            $inner = $this->findIncrementers($tokens, $tokens[$start]);
88
-            $diff  = array_intersect($outer, $inner);
89
-
90
-            if (count($diff) !== 0) {
91
-                $error = 'Loop incrementor (%s) jumbling with inner loop';
92
-                $data  = [join(', ', $diff)];
93
-                $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
94
-            }
95
-        }
96
-
97
-    }//end process()
98
-
99
-
100
-    /**
101
-     * Get all used variables in the incrementer part of a for statement.
102
-     *
103
-     * @param array(integer=>array) $tokens Array with all code sniffer tokens.
104
-     * @param array(string=>mixed)  $token  Current for loop token
105
-     *
106
-     * @return string[] List of all found incrementer variables.
107
-     */
108
-    protected function findIncrementers(array $tokens, array $token)
109
-    {
110
-        // Skip invalid statement.
111
-        if (isset($token['parenthesis_opener']) === false) {
112
-            return [];
113
-        }
114
-
115
-        $start = ++$token['parenthesis_opener'];
116
-        $end   = --$token['parenthesis_closer'];
117
-
118
-        $incrementers = [];
119
-        $semicolons   = 0;
120
-        for ($next = $start; $next <= $end; ++$next) {
121
-            $code = $tokens[$next]['code'];
122
-            if ($code === T_SEMICOLON) {
123
-                ++$semicolons;
124
-            } else if ($semicolons === 2 && $code === T_VARIABLE) {
125
-                $incrementers[] = $tokens[$next]['content'];
126
-            }
127
-        }
128
-
129
-        return $incrementers;
130
-
131
-    }//end findIncrementers()
39
+	/**
40
+	 * Registers the tokens that this sniff wants to listen for.
41
+	 *
42
+	 * @return int[]
43
+	 */
44
+	public function register()
45
+	{
46
+		return [T_FOR];
47
+
48
+	}//end register()
49
+
50
+
51
+	/**
52
+	 * Processes this test, when one of its tokens is encountered.
53
+	 *
54
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
55
+	 * @param int                         $stackPtr  The position of the current token
56
+	 *                                               in the stack passed in $tokens.
57
+	 *
58
+	 * @return void
59
+	 */
60
+	public function process(File $phpcsFile, $stackPtr)
61
+	{
62
+		$tokens = $phpcsFile->getTokens();
63
+		$token  = $tokens[$stackPtr];
64
+
65
+		// Skip for-loop without body.
66
+		if (isset($token['scope_opener']) === false) {
67
+			return;
68
+		}
69
+
70
+		// Find incrementors for outer loop.
71
+		$outer = $this->findIncrementers($tokens, $token);
72
+
73
+		// Skip if empty.
74
+		if (count($outer) === 0) {
75
+			return;
76
+		}
77
+
78
+		// Find nested for loops.
79
+		$start = ++$token['scope_opener'];
80
+		$end   = --$token['scope_closer'];
81
+
82
+		for (; $start <= $end; ++$start) {
83
+			if ($tokens[$start]['code'] !== T_FOR) {
84
+				continue;
85
+			}
86
+
87
+			$inner = $this->findIncrementers($tokens, $tokens[$start]);
88
+			$diff  = array_intersect($outer, $inner);
89
+
90
+			if (count($diff) !== 0) {
91
+				$error = 'Loop incrementor (%s) jumbling with inner loop';
92
+				$data  = [join(', ', $diff)];
93
+				$phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
94
+			}
95
+		}
96
+
97
+	}//end process()
98
+
99
+
100
+	/**
101
+	 * Get all used variables in the incrementer part of a for statement.
102
+	 *
103
+	 * @param array(integer=>array) $tokens Array with all code sniffer tokens.
104
+	 * @param array(string=>mixed)  $token  Current for loop token
105
+	 *
106
+	 * @return string[] List of all found incrementer variables.
107
+	 */
108
+	protected function findIncrementers(array $tokens, array $token)
109
+	{
110
+		// Skip invalid statement.
111
+		if (isset($token['parenthesis_opener']) === false) {
112
+			return [];
113
+		}
114
+
115
+		$start = ++$token['parenthesis_opener'];
116
+		$end   = --$token['parenthesis_closer'];
117
+
118
+		$incrementers = [];
119
+		$semicolons   = 0;
120
+		for ($next = $start; $next <= $end; ++$next) {
121
+			$code = $tokens[$next]['code'];
122
+			if ($code === T_SEMICOLON) {
123
+				++$semicolons;
124
+			} else if ($semicolons === 2 && $code === T_VARIABLE) {
125
+				$incrementers[] = $tokens[$next]['content'];
126
+			}
127
+		}
128
+
129
+		return $incrementers;
130
+
131
+	}//end findIncrementers()
132 132
 
133 133
 
134 134
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -29,133 +29,133 @@
 block discarded – undo
29 29
 {
30 30
 
31 31
 
32
-    /**
33
-     * Registers the tokens that this sniff wants to listen for.
34
-     *
35
-     * @return int[]
36
-     */
37
-    public function register()
38
-    {
39
-        return [T_FUNCTION];
40
-
41
-    }//end register()
42
-
43
-
44
-    /**
45
-     * Processes this test, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48
-     * @param int                         $stackPtr  The position of the current token
49
-     *                                               in the stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        $tokens = $phpcsFile->getTokens();
56
-        $token  = $tokens[$stackPtr];
57
-
58
-        // Skip function without body.
59
-        if (isset($token['scope_opener']) === false) {
60
-            return;
61
-        }
62
-
63
-        // Get function name.
64
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
65
-
66
-        // Get all parameters from method signature.
67
-        $signature = [];
68
-        foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
69
-            $signature[] = $param['name'];
70
-        }
71
-
72
-        $next = ++$token['scope_opener'];
73
-        $end  = --$token['scope_closer'];
74
-
75
-        for (; $next <= $end; ++$next) {
76
-            $code = $tokens[$next]['code'];
77
-
78
-            if (isset(Tokens::$emptyTokens[$code]) === true) {
79
-                continue;
80
-            } else if ($code === T_RETURN) {
81
-                continue;
82
-            }
83
-
84
-            break;
85
-        }
86
-
87
-        // Any token except 'parent' indicates correct code.
88
-        if ($tokens[$next]['code'] !== T_PARENT) {
89
-            return;
90
-        }
91
-
92
-        // Find next non empty token index, should be double colon.
93
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
94
-
95
-        // Skip for invalid code.
96
-        if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
97
-            return;
98
-        }
99
-
100
-        // Find next non empty token index, should be the function name.
101
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
102
-
103
-        // Skip for invalid code or other method.
104
-        if ($next === false || $tokens[$next]['content'] !== $methodName) {
105
-            return;
106
-        }
107
-
108
-        // Find next non empty token index, should be the open parenthesis.
109
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
110
-
111
-        // Skip for invalid code.
112
-        if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
113
-            return;
114
-        }
115
-
116
-        $parameters       = [''];
117
-        $parenthesisCount = 1;
118
-        $count            = count($tokens);
119
-        for (++$next; $next < $count; ++$next) {
120
-            $code = $tokens[$next]['code'];
121
-
122
-            if ($code === T_OPEN_PARENTHESIS) {
123
-                ++$parenthesisCount;
124
-            } else if ($code === T_CLOSE_PARENTHESIS) {
125
-                --$parenthesisCount;
126
-            } else if ($parenthesisCount === 1 && $code === T_COMMA) {
127
-                $parameters[] = '';
128
-            } else if (isset(Tokens::$emptyTokens[$code]) === false) {
129
-                $parameters[(count($parameters) - 1)] .= $tokens[$next]['content'];
130
-            }
131
-
132
-            if ($parenthesisCount === 0) {
133
-                break;
134
-            }
135
-        }//end for
136
-
137
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
138
-        if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
139
-            return;
140
-        }
141
-
142
-        // Check rest of the scope.
143
-        for (++$next; $next <= $end; ++$next) {
144
-            $code = $tokens[$next]['code'];
145
-            // Skip for any other content.
146
-            if (isset(Tokens::$emptyTokens[$code]) === false) {
147
-                return;
148
-            }
149
-        }
150
-
151
-        $parameters = array_map('trim', $parameters);
152
-        $parameters = array_filter($parameters);
153
-
154
-        if (count($parameters) === count($signature) && $parameters === $signature) {
155
-            $phpcsFile->addWarning('Possible useless method overriding detected', $stackPtr, 'Found');
156
-        }
157
-
158
-    }//end process()
32
+	/**
33
+	 * Registers the tokens that this sniff wants to listen for.
34
+	 *
35
+	 * @return int[]
36
+	 */
37
+	public function register()
38
+	{
39
+		return [T_FUNCTION];
40
+
41
+	}//end register()
42
+
43
+
44
+	/**
45
+	 * Processes this test, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48
+	 * @param int                         $stackPtr  The position of the current token
49
+	 *                                               in the stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		$tokens = $phpcsFile->getTokens();
56
+		$token  = $tokens[$stackPtr];
57
+
58
+		// Skip function without body.
59
+		if (isset($token['scope_opener']) === false) {
60
+			return;
61
+		}
62
+
63
+		// Get function name.
64
+		$methodName = $phpcsFile->getDeclarationName($stackPtr);
65
+
66
+		// Get all parameters from method signature.
67
+		$signature = [];
68
+		foreach ($phpcsFile->getMethodParameters($stackPtr) as $param) {
69
+			$signature[] = $param['name'];
70
+		}
71
+
72
+		$next = ++$token['scope_opener'];
73
+		$end  = --$token['scope_closer'];
74
+
75
+		for (; $next <= $end; ++$next) {
76
+			$code = $tokens[$next]['code'];
77
+
78
+			if (isset(Tokens::$emptyTokens[$code]) === true) {
79
+				continue;
80
+			} else if ($code === T_RETURN) {
81
+				continue;
82
+			}
83
+
84
+			break;
85
+		}
86
+
87
+		// Any token except 'parent' indicates correct code.
88
+		if ($tokens[$next]['code'] !== T_PARENT) {
89
+			return;
90
+		}
91
+
92
+		// Find next non empty token index, should be double colon.
93
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
94
+
95
+		// Skip for invalid code.
96
+		if ($next === false || $tokens[$next]['code'] !== T_DOUBLE_COLON) {
97
+			return;
98
+		}
99
+
100
+		// Find next non empty token index, should be the function name.
101
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
102
+
103
+		// Skip for invalid code or other method.
104
+		if ($next === false || $tokens[$next]['content'] !== $methodName) {
105
+			return;
106
+		}
107
+
108
+		// Find next non empty token index, should be the open parenthesis.
109
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
110
+
111
+		// Skip for invalid code.
112
+		if ($next === false || $tokens[$next]['code'] !== T_OPEN_PARENTHESIS) {
113
+			return;
114
+		}
115
+
116
+		$parameters       = [''];
117
+		$parenthesisCount = 1;
118
+		$count            = count($tokens);
119
+		for (++$next; $next < $count; ++$next) {
120
+			$code = $tokens[$next]['code'];
121
+
122
+			if ($code === T_OPEN_PARENTHESIS) {
123
+				++$parenthesisCount;
124
+			} else if ($code === T_CLOSE_PARENTHESIS) {
125
+				--$parenthesisCount;
126
+			} else if ($parenthesisCount === 1 && $code === T_COMMA) {
127
+				$parameters[] = '';
128
+			} else if (isset(Tokens::$emptyTokens[$code]) === false) {
129
+				$parameters[(count($parameters) - 1)] .= $tokens[$next]['content'];
130
+			}
131
+
132
+			if ($parenthesisCount === 0) {
133
+				break;
134
+			}
135
+		}//end for
136
+
137
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($next + 1), null, true);
138
+		if ($next === false || $tokens[$next]['code'] !== T_SEMICOLON) {
139
+			return;
140
+		}
141
+
142
+		// Check rest of the scope.
143
+		for (++$next; $next <= $end; ++$next) {
144
+			$code = $tokens[$next]['code'];
145
+			// Skip for any other content.
146
+			if (isset(Tokens::$emptyTokens[$code]) === false) {
147
+				return;
148
+			}
149
+		}
150
+
151
+		$parameters = array_map('trim', $parameters);
152
+		$parameters = array_filter($parameters);
153
+
154
+		if (count($parameters) === count($signature) && $parameters === $signature) {
155
+			$phpcsFile->addWarning('Possible useless method overriding detected', $stackPtr, 'Found');
156
+		}
157
+
158
+	}//end process()
159 159
 
160 160
 
161 161
 }//end class
Please login to merge, or discard this patch.