Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractScopeSniff.php 3 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -32,160 +32,160 @@
 block discarded – undo
32 32
 abstract class AbstractScopeSniff implements Sniff
33 33
 {
34 34
 
35
-    /**
36
-     * The token types that this test wishes to listen to within the scope.
37
-     *
38
-     * @var array
39
-     */
40
-    private $tokens = [];
41
-
42
-    /**
43
-     * The type of scope opener tokens that this test wishes to listen to.
44
-     *
45
-     * @var string
46
-     */
47
-    private $scopeTokens = [];
48
-
49
-    /**
50
-     * True if this test should fire on tokens outside of the scope.
51
-     *
52
-     * @var boolean
53
-     */
54
-    private $listenOutside = false;
55
-
56
-
57
-    /**
58
-     * Constructs a new AbstractScopeTest.
59
-     *
60
-     * @param array   $scopeTokens   The type of scope the test wishes to listen to.
61
-     * @param array   $tokens        The tokens that the test wishes to listen to
62
-     *                               within the scope.
63
-     * @param boolean $listenOutside If true this test will also alert the
64
-     *                               extending class when a token is found outside
65
-     *                               the scope, by calling the
66
-     *                               processTokenOutsideScope method.
67
-     *
68
-     * @see    PHP_CodeSniffer.getValidScopeTokeners()
69
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified tokens array is empty.
70
-     */
71
-    public function __construct(
72
-        array $scopeTokens,
73
-        array $tokens,
74
-        $listenOutside=false
75
-    ) {
76
-        if (empty($scopeTokens) === true) {
77
-            $error = 'The scope tokens list cannot be empty';
78
-            throw new RuntimeException($error);
79
-        }
80
-
81
-        if (empty($tokens) === true) {
82
-            $error = 'The tokens list cannot be empty';
83
-            throw new RuntimeException($error);
84
-        }
85
-
86
-        $invalidScopeTokens = array_intersect($scopeTokens, $tokens);
87
-        if (empty($invalidScopeTokens) === false) {
88
-            $invalid = implode(', ', $invalidScopeTokens);
89
-            $error   = "Scope tokens [$invalid] can't be in the tokens array";
90
-            throw new RuntimeException($error);
91
-        }
92
-
93
-        $this->listenOutside = $listenOutside;
94
-        $this->scopeTokens   = array_flip($scopeTokens);
95
-        $this->tokens        = $tokens;
96
-
97
-    }//end __construct()
98
-
99
-
100
-    /**
101
-     * The method that is called to register the tokens this test wishes to
102
-     * listen to.
103
-     *
104
-     * DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register
105
-     * for the desired tokens and scope.
106
-     *
107
-     * @return int[]
108
-     * @see    __constructor()
109
-     */
110
-    final public function register()
111
-    {
112
-        return $this->tokens;
113
-
114
-    }//end register()
115
-
116
-
117
-    /**
118
-     * Processes the tokens that this test is listening for.
119
-     *
120
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
121
-     * @param int                         $stackPtr  The position in the stack where this
122
-     *                                               token was found.
123
-     *
124
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
125
-     *                  called again on the current file until the returned stack
126
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
127
-     *                  the rest of the file.
128
-     * @see    processTokenWithinScope()
129
-     */
130
-    final public function process(File $phpcsFile, $stackPtr)
131
-    {
132
-        $tokens = $phpcsFile->getTokens();
133
-
134
-        $foundScope = false;
135
-        $skipPtrs   = [];
136
-        foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) {
137
-            if (isset($this->scopeTokens[$code]) === true) {
138
-                $skipPtrs[] = $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope);
139
-                $foundScope = true;
140
-            }
141
-        }
142
-
143
-        if ($this->listenOutside === true && $foundScope === false) {
144
-            $skipPtrs[] = $this->processTokenOutsideScope($phpcsFile, $stackPtr);
145
-        }
146
-
147
-        if (empty($skipPtrs) === false) {
148
-            return min($skipPtrs);
149
-        }
150
-
151
-        return;
152
-
153
-    }//end process()
154
-
155
-
156
-    /**
157
-     * Processes a token that is found within the scope that this test is
158
-     * listening to.
159
-     *
160
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
161
-     * @param int                         $stackPtr  The position in the stack where this
162
-     *                                               token was found.
163
-     * @param int                         $currScope The position in the tokens array that
164
-     *                                               opened the scope that this test is
165
-     *                                               listening for.
166
-     *
167
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
168
-     *                  called again on the current file until the returned stack
169
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
170
-     *                  the rest of the file.
171
-     */
172
-    abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope);
173
-
174
-
175
-    /**
176
-     * Processes a token that is found outside the scope that this test is
177
-     * listening to.
178
-     *
179
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
180
-     * @param int                         $stackPtr  The position in the stack where this
181
-     *                                               token was found.
182
-     *
183
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
184
-     *                  called again on the current file until the returned stack
185
-     *                  pointer is reached. Return (count($tokens) + 1) to skip
186
-     *                  the rest of the file.
187
-     */
188
-    abstract protected function processTokenOutsideScope(File $phpcsFile, $stackPtr);
35
+	/**
36
+	 * The token types that this test wishes to listen to within the scope.
37
+	 *
38
+	 * @var array
39
+	 */
40
+	private $tokens = [];
41
+
42
+	/**
43
+	 * The type of scope opener tokens that this test wishes to listen to.
44
+	 *
45
+	 * @var string
46
+	 */
47
+	private $scopeTokens = [];
48
+
49
+	/**
50
+	 * True if this test should fire on tokens outside of the scope.
51
+	 *
52
+	 * @var boolean
53
+	 */
54
+	private $listenOutside = false;
55
+
56
+
57
+	/**
58
+	 * Constructs a new AbstractScopeTest.
59
+	 *
60
+	 * @param array   $scopeTokens   The type of scope the test wishes to listen to.
61
+	 * @param array   $tokens        The tokens that the test wishes to listen to
62
+	 *                               within the scope.
63
+	 * @param boolean $listenOutside If true this test will also alert the
64
+	 *                               extending class when a token is found outside
65
+	 *                               the scope, by calling the
66
+	 *                               processTokenOutsideScope method.
67
+	 *
68
+	 * @see    PHP_CodeSniffer.getValidScopeTokeners()
69
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified tokens array is empty.
70
+	 */
71
+	public function __construct(
72
+		array $scopeTokens,
73
+		array $tokens,
74
+		$listenOutside=false
75
+	) {
76
+		if (empty($scopeTokens) === true) {
77
+			$error = 'The scope tokens list cannot be empty';
78
+			throw new RuntimeException($error);
79
+		}
80
+
81
+		if (empty($tokens) === true) {
82
+			$error = 'The tokens list cannot be empty';
83
+			throw new RuntimeException($error);
84
+		}
85
+
86
+		$invalidScopeTokens = array_intersect($scopeTokens, $tokens);
87
+		if (empty($invalidScopeTokens) === false) {
88
+			$invalid = implode(', ', $invalidScopeTokens);
89
+			$error   = "Scope tokens [$invalid] can't be in the tokens array";
90
+			throw new RuntimeException($error);
91
+		}
92
+
93
+		$this->listenOutside = $listenOutside;
94
+		$this->scopeTokens   = array_flip($scopeTokens);
95
+		$this->tokens        = $tokens;
96
+
97
+	}//end __construct()
98
+
99
+
100
+	/**
101
+	 * The method that is called to register the tokens this test wishes to
102
+	 * listen to.
103
+	 *
104
+	 * DO NOT OVERRIDE THIS METHOD. Use the constructor of this class to register
105
+	 * for the desired tokens and scope.
106
+	 *
107
+	 * @return int[]
108
+	 * @see    __constructor()
109
+	 */
110
+	final public function register()
111
+	{
112
+		return $this->tokens;
113
+
114
+	}//end register()
115
+
116
+
117
+	/**
118
+	 * Processes the tokens that this test is listening for.
119
+	 *
120
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
121
+	 * @param int                         $stackPtr  The position in the stack where this
122
+	 *                                               token was found.
123
+	 *
124
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
125
+	 *                  called again on the current file until the returned stack
126
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
127
+	 *                  the rest of the file.
128
+	 * @see    processTokenWithinScope()
129
+	 */
130
+	final public function process(File $phpcsFile, $stackPtr)
131
+	{
132
+		$tokens = $phpcsFile->getTokens();
133
+
134
+		$foundScope = false;
135
+		$skipPtrs   = [];
136
+		foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) {
137
+			if (isset($this->scopeTokens[$code]) === true) {
138
+				$skipPtrs[] = $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope);
139
+				$foundScope = true;
140
+			}
141
+		}
142
+
143
+		if ($this->listenOutside === true && $foundScope === false) {
144
+			$skipPtrs[] = $this->processTokenOutsideScope($phpcsFile, $stackPtr);
145
+		}
146
+
147
+		if (empty($skipPtrs) === false) {
148
+			return min($skipPtrs);
149
+		}
150
+
151
+		return;
152
+
153
+	}//end process()
154
+
155
+
156
+	/**
157
+	 * Processes a token that is found within the scope that this test is
158
+	 * listening to.
159
+	 *
160
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
161
+	 * @param int                         $stackPtr  The position in the stack where this
162
+	 *                                               token was found.
163
+	 * @param int                         $currScope The position in the tokens array that
164
+	 *                                               opened the scope that this test is
165
+	 *                                               listening for.
166
+	 *
167
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
168
+	 *                  called again on the current file until the returned stack
169
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
170
+	 *                  the rest of the file.
171
+	 */
172
+	abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope);
173
+
174
+
175
+	/**
176
+	 * Processes a token that is found outside the scope that this test is
177
+	 * listening to.
178
+	 *
179
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where this token was found.
180
+	 * @param int                         $stackPtr  The position in the stack where this
181
+	 *                                               token was found.
182
+	 *
183
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
184
+	 *                  called again on the current file until the returned stack
185
+	 *                  pointer is reached. Return (count($tokens) + 1) to skip
186
+	 *                  the rest of the file.
187
+	 */
188
+	abstract protected function processTokenOutsideScope(File $phpcsFile, $stackPtr);
189 189
 
190 190
 
191 191
 }//end class
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -37,14 +37,14 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @var array
39 39
      */
40
-    private $tokens = [];
40
+    private $tokens = [ ];
41 41
 
42 42
     /**
43 43
      * The type of scope opener tokens that this test wishes to listen to.
44 44
      *
45 45
      * @var string
46 46
      */
47
-    private $scopeTokens = [];
47
+    private $scopeTokens = [ ];
48 48
 
49 49
     /**
50 50
      * True if this test should fire on tokens outside of the scope.
@@ -71,27 +71,27 @@  discard block
 block discarded – undo
71 71
     public function __construct(
72 72
         array $scopeTokens,
73 73
         array $tokens,
74
-        $listenOutside=false
74
+        $listenOutside = false
75 75
     ) {
76
-        if (empty($scopeTokens) === true) {
76
+        if ( empty( $scopeTokens ) === true ) {
77 77
             $error = 'The scope tokens list cannot be empty';
78
-            throw new RuntimeException($error);
78
+            throw new RuntimeException( $error );
79 79
         }
80 80
 
81
-        if (empty($tokens) === true) {
81
+        if ( empty( $tokens ) === true ) {
82 82
             $error = 'The tokens list cannot be empty';
83
-            throw new RuntimeException($error);
83
+            throw new RuntimeException( $error );
84 84
         }
85 85
 
86
-        $invalidScopeTokens = array_intersect($scopeTokens, $tokens);
87
-        if (empty($invalidScopeTokens) === false) {
88
-            $invalid = implode(', ', $invalidScopeTokens);
86
+        $invalidScopeTokens = array_intersect( $scopeTokens, $tokens );
87
+        if ( empty( $invalidScopeTokens ) === false ) {
88
+            $invalid = implode( ', ', $invalidScopeTokens );
89 89
             $error   = "Scope tokens [$invalid] can't be in the tokens array";
90
-            throw new RuntimeException($error);
90
+            throw new RuntimeException( $error );
91 91
         }
92 92
 
93 93
         $this->listenOutside = $listenOutside;
94
-        $this->scopeTokens   = array_flip($scopeTokens);
94
+        $this->scopeTokens   = array_flip( $scopeTokens );
95 95
         $this->tokens        = $tokens;
96 96
 
97 97
     }//end __construct()
@@ -127,25 +127,25 @@  discard block
 block discarded – undo
127 127
      *                  the rest of the file.
128 128
      * @see    processTokenWithinScope()
129 129
      */
130
-    final public function process(File $phpcsFile, $stackPtr)
130
+    final public function process( File $phpcsFile, $stackPtr )
131 131
     {
132 132
         $tokens = $phpcsFile->getTokens();
133 133
 
134 134
         $foundScope = false;
135
-        $skipPtrs   = [];
136
-        foreach ($tokens[$stackPtr]['conditions'] as $scope => $code) {
137
-            if (isset($this->scopeTokens[$code]) === true) {
138
-                $skipPtrs[] = $this->processTokenWithinScope($phpcsFile, $stackPtr, $scope);
135
+        $skipPtrs   = [ ];
136
+        foreach ( $tokens[ $stackPtr ][ 'conditions' ] as $scope => $code ) {
137
+            if ( isset( $this->scopeTokens[ $code ] ) === true ) {
138
+                $skipPtrs[ ] = $this->processTokenWithinScope( $phpcsFile, $stackPtr, $scope );
139 139
                 $foundScope = true;
140 140
             }
141 141
         }
142 142
 
143
-        if ($this->listenOutside === true && $foundScope === false) {
144
-            $skipPtrs[] = $this->processTokenOutsideScope($phpcsFile, $stackPtr);
143
+        if ( $this->listenOutside === true && $foundScope === false ) {
144
+            $skipPtrs[ ] = $this->processTokenOutsideScope( $phpcsFile, $stackPtr );
145 145
         }
146 146
 
147
-        if (empty($skipPtrs) === false) {
148
-            return min($skipPtrs);
147
+        if ( empty( $skipPtrs ) === false ) {
148
+            return min( $skipPtrs );
149 149
         }
150 150
 
151 151
         return;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
170 170
      *                  the rest of the file.
171 171
      */
172
-    abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope);
172
+    abstract protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope );
173 173
 
174 174
 
175 175
     /**
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      *                  pointer is reached. Return (count($tokens) + 1) to skip
186 186
      *                  the rest of the file.
187 187
      */
188
-    abstract protected function processTokenOutsideScope(File $phpcsFile, $stackPtr);
188
+    abstract protected function processTokenOutsideScope( File $phpcsFile, $stackPtr );
189 189
 
190 190
 
191 191
 }//end class
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,8 +29,7 @@  discard block
 block discarded – undo
29 29
 use PHP_CodeSniffer\Files\File;
30 30
 use PHP_CodeSniffer\Exceptions\RuntimeException;
31 31
 
32
-abstract class AbstractScopeSniff implements Sniff
33
-{
32
+abstract class AbstractScopeSniff implements Sniff {
34 33
 
35 34
     /**
36 35
      * The token types that this test wishes to listen to within the scope.
@@ -107,8 +106,7 @@  discard block
 block discarded – undo
107 106
      * @return int[]
108 107
      * @see    __constructor()
109 108
      */
110
-    final public function register()
111
-    {
109
+    final public function register() {
112 110
         return $this->tokens;
113 111
 
114 112
     }//end register()
@@ -127,8 +125,7 @@  discard block
 block discarded – undo
127 125
      *                  the rest of the file.
128 126
      * @see    processTokenWithinScope()
129 127
      */
130
-    final public function process(File $phpcsFile, $stackPtr)
131
-    {
128
+    final public function process(File $phpcsFile, $stackPtr) {
132 129
         $tokens = $phpcsFile->getTokens();
133 130
 
134 131
         $foundScope = false;
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractPatternSniff.php 4 patches
Indentation   +914 added lines, -914 removed lines patch added patch discarded remove patch
@@ -17,920 +17,920 @@
 block discarded – undo
17 17
 abstract class AbstractPatternSniff implements Sniff
18 18
 {
19 19
 
20
-    /**
21
-     * If true, comments will be ignored if they are found in the code.
22
-     *
23
-     * @var boolean
24
-     */
25
-    public $ignoreComments = false;
26
-
27
-    /**
28
-     * The current file being checked.
29
-     *
30
-     * @var string
31
-     */
32
-    protected $currFile = '';
33
-
34
-    /**
35
-     * The parsed patterns array.
36
-     *
37
-     * @var array
38
-     */
39
-    private $parsedPatterns = [];
40
-
41
-    /**
42
-     * Tokens that this sniff wishes to process outside of the patterns.
43
-     *
44
-     * @var int[]
45
-     * @see registerSupplementary()
46
-     * @see processSupplementary()
47
-     */
48
-    private $supplementaryTokens = [];
49
-
50
-    /**
51
-     * Positions in the stack where errors have occurred.
52
-     *
53
-     * @var array<int, bool>
54
-     */
55
-    private $errorPos = [];
56
-
57
-
58
-    /**
59
-     * Constructs a AbstractPatternSniff.
60
-     *
61
-     * @param boolean $ignoreComments If true, comments will be ignored.
62
-     */
63
-    public function __construct($ignoreComments=null)
64
-    {
65
-        // This is here for backwards compatibility.
66
-        if ($ignoreComments !== null) {
67
-            $this->ignoreComments = $ignoreComments;
68
-        }
69
-
70
-        $this->supplementaryTokens = $this->registerSupplementary();
71
-
72
-    }//end __construct()
73
-
74
-
75
-    /**
76
-     * Registers the tokens to listen to.
77
-     *
78
-     * Classes extending <i>AbstractPatternTest</i> should implement the
79
-     * <i>getPatterns()</i> method to register the patterns they wish to test.
80
-     *
81
-     * @return int[]
82
-     * @see    process()
83
-     */
84
-    final public function register()
85
-    {
86
-        $listenTypes = [];
87
-        $patterns    = $this->getPatterns();
88
-
89
-        foreach ($patterns as $pattern) {
90
-            $parsedPattern = $this->parse($pattern);
91
-
92
-            // Find a token position in the pattern that we can use
93
-            // for a listener token.
94
-            $pos           = $this->getListenerTokenPos($parsedPattern);
95
-            $tokenType     = $parsedPattern[$pos]['token'];
96
-            $listenTypes[] = $tokenType;
97
-
98
-            $patternArray = [
99
-                'listen_pos'   => $pos,
100
-                'pattern'      => $parsedPattern,
101
-                'pattern_code' => $pattern,
102
-            ];
103
-
104
-            if (isset($this->parsedPatterns[$tokenType]) === false) {
105
-                $this->parsedPatterns[$tokenType] = [];
106
-            }
107
-
108
-            $this->parsedPatterns[$tokenType][] = $patternArray;
109
-        }//end foreach
110
-
111
-        return array_unique(array_merge($listenTypes, $this->supplementaryTokens));
112
-
113
-    }//end register()
114
-
115
-
116
-    /**
117
-     * Returns the token types that the specified pattern is checking for.
118
-     *
119
-     * Returned array is in the format:
120
-     * <code>
121
-     *   array(
122
-     *      T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token
123
-     *                         // should occur in the pattern.
124
-     *   );
125
-     * </code>
126
-     *
127
-     * @param array $pattern The parsed pattern to find the acquire the token
128
-     *                       types from.
129
-     *
130
-     * @return array<int, int>
131
-     */
132
-    private function getPatternTokenTypes($pattern)
133
-    {
134
-        $tokenTypes = [];
135
-        foreach ($pattern as $pos => $patternInfo) {
136
-            if ($patternInfo['type'] === 'token') {
137
-                if (isset($tokenTypes[$patternInfo['token']]) === false) {
138
-                    $tokenTypes[$patternInfo['token']] = $pos;
139
-                }
140
-            }
141
-        }
142
-
143
-        return $tokenTypes;
144
-
145
-    }//end getPatternTokenTypes()
146
-
147
-
148
-    /**
149
-     * Returns the position in the pattern that this test should register as
150
-     * a listener for the pattern.
151
-     *
152
-     * @param array $pattern The pattern to acquire the listener for.
153
-     *
154
-     * @return int The position in the pattern that this test should register
155
-     *             as the listener.
156
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
157
-     */
158
-    private function getListenerTokenPos($pattern)
159
-    {
160
-        $tokenTypes = $this->getPatternTokenTypes($pattern);
161
-        $tokenCodes = array_keys($tokenTypes);
162
-        $token      = Tokens::getHighestWeightedToken($tokenCodes);
163
-
164
-        // If we could not get a token.
165
-        if ($token === false) {
166
-            $error = 'Could not determine a token to listen for';
167
-            throw new RuntimeException($error);
168
-        }
169
-
170
-        return $tokenTypes[$token];
171
-
172
-    }//end getListenerTokenPos()
173
-
174
-
175
-    /**
176
-     * Processes the test.
177
-     *
178
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
179
-     *                                               token occurred.
180
-     * @param int                         $stackPtr  The position in the tokens stack
181
-     *                                               where the listening token type
182
-     *                                               was found.
183
-     *
184
-     * @return void
185
-     * @see    register()
186
-     */
187
-    final public function process(File $phpcsFile, $stackPtr)
188
-    {
189
-        $file = $phpcsFile->getFilename();
190
-        if ($this->currFile !== $file) {
191
-            // We have changed files, so clean up.
192
-            $this->errorPos = [];
193
-            $this->currFile = $file;
194
-        }
195
-
196
-        $tokens = $phpcsFile->getTokens();
197
-
198
-        if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens, true) === true) {
199
-            $this->processSupplementary($phpcsFile, $stackPtr);
200
-        }
201
-
202
-        $type = $tokens[$stackPtr]['code'];
203
-
204
-        // If the type is not set, then it must have been a token registered
205
-        // with registerSupplementary().
206
-        if (isset($this->parsedPatterns[$type]) === false) {
207
-            return;
208
-        }
209
-
210
-        $allErrors = [];
211
-
212
-        // Loop over each pattern that is listening to the current token type
213
-        // that we are processing.
214
-        foreach ($this->parsedPatterns[$type] as $patternInfo) {
215
-            // If processPattern returns false, then the pattern that we are
216
-            // checking the code with must not be designed to check that code.
217
-            $errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
218
-            if ($errors === false) {
219
-                // The pattern didn't match.
220
-                continue;
221
-            } else if (empty($errors) === true) {
222
-                // The pattern matched, but there were no errors.
223
-                break;
224
-            }
225
-
226
-            foreach ($errors as $stackPtr => $error) {
227
-                if (isset($this->errorPos[$stackPtr]) === false) {
228
-                    $this->errorPos[$stackPtr] = true;
229
-                    $allErrors[$stackPtr]      = $error;
230
-                }
231
-            }
232
-        }
233
-
234
-        foreach ($allErrors as $stackPtr => $error) {
235
-            $phpcsFile->addError($error, $stackPtr, 'Found');
236
-        }
237
-
238
-    }//end process()
239
-
240
-
241
-    /**
242
-     * Processes the pattern and verifies the code at $stackPtr.
243
-     *
244
-     * @param array                       $patternInfo Information about the pattern used
245
-     *                                                 for checking, which includes are
246
-     *                                                 parsed token representation of the
247
-     *                                                 pattern.
248
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The PHP_CodeSniffer file where the
249
-     *                                                 token occurred.
250
-     * @param int                         $stackPtr    The position in the tokens stack where
251
-     *                                                 the listening token type was found.
252
-     *
253
-     * @return array
254
-     */
255
-    protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
256
-    {
257
-        $tokens      = $phpcsFile->getTokens();
258
-        $pattern     = $patternInfo['pattern'];
259
-        $patternCode = $patternInfo['pattern_code'];
260
-        $errors      = [];
261
-        $found       = '';
262
-
263
-        $ignoreTokens = [T_WHITESPACE => T_WHITESPACE];
264
-        if ($this->ignoreComments === true) {
265
-            $ignoreTokens += Tokens::$commentTokens;
266
-        }
267
-
268
-        $origStackPtr = $stackPtr;
269
-        $hasError     = false;
270
-
271
-        if ($patternInfo['listen_pos'] > 0) {
272
-            $stackPtr--;
273
-
274
-            for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
275
-                if ($pattern[$i]['type'] === 'token') {
276
-                    if ($pattern[$i]['token'] === T_WHITESPACE) {
277
-                        if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
278
-                            $found = $tokens[$stackPtr]['content'].$found;
279
-                        }
280
-
281
-                        // Only check the size of the whitespace if this is not
282
-                        // the first token. We don't care about the size of
283
-                        // leading whitespace, just that there is some.
284
-                        if ($i !== 0) {
285
-                            if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
286
-                                $hasError = true;
287
-                            }
288
-                        }
289
-                    } else {
290
-                        // Check to see if this important token is the same as the
291
-                        // previous important token in the pattern. If it is not,
292
-                        // then the pattern cannot be for this piece of code.
293
-                        $prev = $phpcsFile->findPrevious(
294
-                            $ignoreTokens,
295
-                            $stackPtr,
296
-                            null,
297
-                            true
298
-                        );
299
-
300
-                        if ($prev === false
301
-                            || $tokens[$prev]['code'] !== $pattern[$i]['token']
302
-                        ) {
303
-                            return false;
304
-                        }
305
-
306
-                        // If we skipped past some whitespace tokens, then add them
307
-                        // to the found string.
308
-                        $tokenContent = $phpcsFile->getTokensAsString(
309
-                            ($prev + 1),
310
-                            ($stackPtr - $prev - 1)
311
-                        );
312
-
313
-                        $found = $tokens[$prev]['content'].$tokenContent.$found;
314
-
315
-                        if (isset($pattern[($i - 1)]) === true
316
-                            && $pattern[($i - 1)]['type'] === 'skip'
317
-                        ) {
318
-                            $stackPtr = $prev;
319
-                        } else {
320
-                            $stackPtr = ($prev - 1);
321
-                        }
322
-                    }//end if
323
-                } else if ($pattern[$i]['type'] === 'skip') {
324
-                    // Skip to next piece of relevant code.
325
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
326
-                        $to = 'parenthesis_opener';
327
-                    } else {
328
-                        $to = 'scope_opener';
329
-                    }
330
-
331
-                    // Find the previous opener.
332
-                    $next = $phpcsFile->findPrevious(
333
-                        $ignoreTokens,
334
-                        $stackPtr,
335
-                        null,
336
-                        true
337
-                    );
338
-
339
-                    if ($next === false || isset($tokens[$next][$to]) === false) {
340
-                        // If there was not opener, then we must be
341
-                        // using the wrong pattern.
342
-                        return false;
343
-                    }
344
-
345
-                    if ($to === 'parenthesis_opener') {
346
-                        $found = '{'.$found;
347
-                    } else {
348
-                        $found = '('.$found;
349
-                    }
350
-
351
-                    $found = '...'.$found;
352
-
353
-                    // Skip to the opening token.
354
-                    $stackPtr = ($tokens[$next][$to] - 1);
355
-                } else if ($pattern[$i]['type'] === 'string') {
356
-                    $found = 'abc';
357
-                } else if ($pattern[$i]['type'] === 'newline') {
358
-                    if ($this->ignoreComments === true
359
-                        && isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true
360
-                    ) {
361
-                        $startComment = $phpcsFile->findPrevious(
362
-                            Tokens::$commentTokens,
363
-                            ($stackPtr - 1),
364
-                            null,
365
-                            true
366
-                        );
367
-
368
-                        if ($tokens[$startComment]['line'] !== $tokens[($startComment + 1)]['line']) {
369
-                            $startComment++;
370
-                        }
371
-
372
-                        $tokenContent = $phpcsFile->getTokensAsString(
373
-                            $startComment,
374
-                            ($stackPtr - $startComment + 1)
375
-                        );
376
-
377
-                        $found    = $tokenContent.$found;
378
-                        $stackPtr = ($startComment - 1);
379
-                    }
380
-
381
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
382
-                        if ($tokens[$stackPtr]['content'] !== $phpcsFile->eolChar) {
383
-                            $found = $tokens[$stackPtr]['content'].$found;
384
-
385
-                            // This may just be an indent that comes after a newline
386
-                            // so check the token before to make sure. If it is a newline, we
387
-                            // can ignore the error here.
388
-                            if (($tokens[($stackPtr - 1)]['content'] !== $phpcsFile->eolChar)
389
-                                && ($this->ignoreComments === true
390
-                                && isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === false)
391
-                            ) {
392
-                                $hasError = true;
393
-                            } else {
394
-                                $stackPtr--;
395
-                            }
396
-                        } else {
397
-                            $found = 'EOL'.$found;
398
-                        }
399
-                    } else {
400
-                        $found    = $tokens[$stackPtr]['content'].$found;
401
-                        $hasError = true;
402
-                    }//end if
403
-
404
-                    if ($hasError === false && $pattern[($i - 1)]['type'] !== 'newline') {
405
-                        // Make sure they only have 1 newline.
406
-                        $prev = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true);
407
-                        if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line']) {
408
-                            $hasError = true;
409
-                        }
410
-                    }
411
-                }//end if
412
-            }//end for
413
-        }//end if
414
-
415
-        $stackPtr          = $origStackPtr;
416
-        $lastAddedStackPtr = null;
417
-        $patternLen        = count($pattern);
418
-
419
-        for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
420
-            if (isset($tokens[$stackPtr]) === false) {
421
-                break;
422
-            }
423
-
424
-            if ($pattern[$i]['type'] === 'token') {
425
-                if ($pattern[$i]['token'] === T_WHITESPACE) {
426
-                    if ($this->ignoreComments === true) {
427
-                        // If we are ignoring comments, check to see if this current
428
-                        // token is a comment. If so skip it.
429
-                        if (isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true) {
430
-                            continue;
431
-                        }
432
-
433
-                        // If the next token is a comment, the we need to skip the
434
-                        // current token as we should allow a space before a
435
-                        // comment for readability.
436
-                        if (isset($tokens[($stackPtr + 1)]) === true
437
-                            && isset(Tokens::$commentTokens[$tokens[($stackPtr + 1)]['code']]) === true
438
-                        ) {
439
-                            continue;
440
-                        }
441
-                    }
442
-
443
-                    $tokenContent = '';
444
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
445
-                        if (isset($pattern[($i + 1)]) === false) {
446
-                            // This is the last token in the pattern, so just compare
447
-                            // the next token of content.
448
-                            $tokenContent = $tokens[$stackPtr]['content'];
449
-                        } else {
450
-                            // Get all the whitespace to the next token.
451
-                            $next = $phpcsFile->findNext(
452
-                                Tokens::$emptyTokens,
453
-                                $stackPtr,
454
-                                null,
455
-                                true
456
-                            );
457
-
458
-                            $tokenContent = $phpcsFile->getTokensAsString(
459
-                                $stackPtr,
460
-                                ($next - $stackPtr)
461
-                            );
462
-
463
-                            $lastAddedStackPtr = $stackPtr;
464
-                            $stackPtr          = $next;
465
-                        }//end if
466
-
467
-                        if ($stackPtr !== $lastAddedStackPtr) {
468
-                            $found .= $tokenContent;
469
-                        }
470
-                    } else {
471
-                        if ($stackPtr !== $lastAddedStackPtr) {
472
-                            $found            .= $tokens[$stackPtr]['content'];
473
-                            $lastAddedStackPtr = $stackPtr;
474
-                        }
475
-                    }//end if
476
-
477
-                    if (isset($pattern[($i + 1)]) === true
478
-                        && $pattern[($i + 1)]['type'] === 'skip'
479
-                    ) {
480
-                        // The next token is a skip token, so we just need to make
481
-                        // sure the whitespace we found has *at least* the
482
-                        // whitespace required.
483
-                        if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
484
-                            $hasError = true;
485
-                        }
486
-                    } else {
487
-                        if ($tokenContent !== $pattern[$i]['value']) {
488
-                            $hasError = true;
489
-                        }
490
-                    }
491
-                } else {
492
-                    // Check to see if this important token is the same as the
493
-                    // next important token in the pattern. If it is not, then
494
-                    // the pattern cannot be for this piece of code.
495
-                    $next = $phpcsFile->findNext(
496
-                        $ignoreTokens,
497
-                        $stackPtr,
498
-                        null,
499
-                        true
500
-                    );
501
-
502
-                    if ($next === false
503
-                        || $tokens[$next]['code'] !== $pattern[$i]['token']
504
-                    ) {
505
-                        // The next important token did not match the pattern.
506
-                        return false;
507
-                    }
508
-
509
-                    if ($lastAddedStackPtr !== null) {
510
-                        if (($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET
511
-                            || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET)
512
-                            && isset($tokens[$next]['scope_condition']) === true
513
-                            && $tokens[$next]['scope_condition'] > $lastAddedStackPtr
514
-                        ) {
515
-                            // This is a brace, but the owner of it is after the current
516
-                            // token, which means it does not belong to any token in
517
-                            // our pattern. This means the pattern is not for us.
518
-                            return false;
519
-                        }
520
-
521
-                        if (($tokens[$next]['code'] === T_OPEN_PARENTHESIS
522
-                            || $tokens[$next]['code'] === T_CLOSE_PARENTHESIS)
523
-                            && isset($tokens[$next]['parenthesis_owner']) === true
524
-                            && $tokens[$next]['parenthesis_owner'] > $lastAddedStackPtr
525
-                        ) {
526
-                            // This is a bracket, but the owner of it is after the current
527
-                            // token, which means it does not belong to any token in
528
-                            // our pattern. This means the pattern is not for us.
529
-                            return false;
530
-                        }
531
-                    }//end if
532
-
533
-                    // If we skipped past some whitespace tokens, then add them
534
-                    // to the found string.
535
-                    if (($next - $stackPtr) > 0) {
536
-                        $hasComment = false;
537
-                        for ($j = $stackPtr; $j < $next; $j++) {
538
-                            $found .= $tokens[$j]['content'];
539
-                            if (isset(Tokens::$commentTokens[$tokens[$j]['code']]) === true) {
540
-                                $hasComment = true;
541
-                            }
542
-                        }
543
-
544
-                        // If we are not ignoring comments, this additional
545
-                        // whitespace or comment is not allowed. If we are
546
-                        // ignoring comments, there needs to be at least one
547
-                        // comment for this to be allowed.
548
-                        if ($this->ignoreComments === false
549
-                            || ($this->ignoreComments === true
550
-                            && $hasComment === false)
551
-                        ) {
552
-                            $hasError = true;
553
-                        }
554
-
555
-                        // Even when ignoring comments, we are not allowed to include
556
-                        // newlines without the pattern specifying them, so
557
-                        // everything should be on the same line.
558
-                        if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
559
-                            $hasError = true;
560
-                        }
561
-                    }//end if
562
-
563
-                    if ($next !== $lastAddedStackPtr) {
564
-                        $found            .= $tokens[$next]['content'];
565
-                        $lastAddedStackPtr = $next;
566
-                    }
567
-
568
-                    if (isset($pattern[($i + 1)]) === true
569
-                        && $pattern[($i + 1)]['type'] === 'skip'
570
-                    ) {
571
-                        $stackPtr = $next;
572
-                    } else {
573
-                        $stackPtr = ($next + 1);
574
-                    }
575
-                }//end if
576
-            } else if ($pattern[$i]['type'] === 'skip') {
577
-                if ($pattern[$i]['to'] === 'unknown') {
578
-                    $next = $phpcsFile->findNext(
579
-                        $pattern[($i + 1)]['token'],
580
-                        $stackPtr
581
-                    );
582
-
583
-                    if ($next === false) {
584
-                        // Couldn't find the next token, so we must
585
-                        // be using the wrong pattern.
586
-                        return false;
587
-                    }
588
-
589
-                    $found   .= '...';
590
-                    $stackPtr = $next;
591
-                } else {
592
-                    // Find the previous opener.
593
-                    $next = $phpcsFile->findPrevious(
594
-                        Tokens::$blockOpeners,
595
-                        $stackPtr
596
-                    );
597
-
598
-                    if ($next === false
599
-                        || isset($tokens[$next][$pattern[$i]['to']]) === false
600
-                    ) {
601
-                        // If there was not opener, then we must
602
-                        // be using the wrong pattern.
603
-                        return false;
604
-                    }
605
-
606
-                    $found .= '...';
607
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
608
-                        $found .= ')';
609
-                    } else {
610
-                        $found .= '}';
611
-                    }
612
-
613
-                    // Skip to the closing token.
614
-                    $stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
615
-                }//end if
616
-            } else if ($pattern[$i]['type'] === 'string') {
617
-                if ($tokens[$stackPtr]['code'] !== T_STRING) {
618
-                    $hasError = true;
619
-                }
620
-
621
-                if ($stackPtr !== $lastAddedStackPtr) {
622
-                    $found            .= 'abc';
623
-                    $lastAddedStackPtr = $stackPtr;
624
-                }
625
-
626
-                $stackPtr++;
627
-            } else if ($pattern[$i]['type'] === 'newline') {
628
-                // Find the next token that contains a newline character.
629
-                $newline = 0;
630
-                for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
631
-                    if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
632
-                        $newline = $j;
633
-                        break;
634
-                    }
635
-                }
636
-
637
-                if ($newline === 0) {
638
-                    // We didn't find a newline character in the rest of the file.
639
-                    $next     = ($phpcsFile->numTokens - 1);
640
-                    $hasError = true;
641
-                } else {
642
-                    if ($this->ignoreComments === false) {
643
-                        // The newline character cannot be part of a comment.
644
-                        if (isset(Tokens::$commentTokens[$tokens[$newline]['code']]) === true) {
645
-                            $hasError = true;
646
-                        }
647
-                    }
648
-
649
-                    if ($newline === $stackPtr) {
650
-                        $next = ($stackPtr + 1);
651
-                    } else {
652
-                        // Check that there were no significant tokens that we
653
-                        // skipped over to find our newline character.
654
-                        $next = $phpcsFile->findNext(
655
-                            $ignoreTokens,
656
-                            $stackPtr,
657
-                            null,
658
-                            true
659
-                        );
660
-
661
-                        if ($next < $newline) {
662
-                            // We skipped a non-ignored token.
663
-                            $hasError = true;
664
-                        } else {
665
-                            $next = ($newline + 1);
666
-                        }
667
-                    }
668
-                }//end if
669
-
670
-                if ($stackPtr !== $lastAddedStackPtr) {
671
-                    $found .= $phpcsFile->getTokensAsString(
672
-                        $stackPtr,
673
-                        ($next - $stackPtr)
674
-                    );
675
-
676
-                    $lastAddedStackPtr = ($next - 1);
677
-                }
678
-
679
-                $stackPtr = $next;
680
-            }//end if
681
-        }//end for
682
-
683
-        if ($hasError === true) {
684
-            $error = $this->prepareError($found, $patternCode);
685
-            $errors[$origStackPtr] = $error;
686
-        }
687
-
688
-        return $errors;
689
-
690
-    }//end processPattern()
691
-
692
-
693
-    /**
694
-     * Prepares an error for the specified patternCode.
695
-     *
696
-     * @param string $found       The actual found string in the code.
697
-     * @param string $patternCode The expected pattern code.
698
-     *
699
-     * @return string The error message.
700
-     */
701
-    protected function prepareError($found, $patternCode)
702
-    {
703
-        $found    = str_replace("\r\n", '\n', $found);
704
-        $found    = str_replace("\n", '\n', $found);
705
-        $found    = str_replace("\r", '\n', $found);
706
-        $found    = str_replace("\t", '\t', $found);
707
-        $found    = str_replace('EOL', '\n', $found);
708
-        $expected = str_replace('EOL', '\n', $patternCode);
709
-
710
-        $error = "Expected \"$expected\"; found \"$found\"";
711
-
712
-        return $error;
713
-
714
-    }//end prepareError()
715
-
716
-
717
-    /**
718
-     * Returns the patterns that should be checked.
719
-     *
720
-     * @return string[]
721
-     */
722
-    abstract protected function getPatterns();
723
-
724
-
725
-    /**
726
-     * Registers any supplementary tokens that this test might wish to process.
727
-     *
728
-     * A sniff may wish to register supplementary tests when it wishes to group
729
-     * an arbitrary validation that cannot be performed using a pattern, with
730
-     * other pattern tests.
731
-     *
732
-     * @return int[]
733
-     * @see    processSupplementary()
734
-     */
735
-    protected function registerSupplementary()
736
-    {
737
-        return [];
738
-
739
-    }//end registerSupplementary()
740
-
741
-
742
-     /**
743
-      * Processes any tokens registered with registerSupplementary().
744
-      *
745
-      * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where to
746
-      *                                               process the skip.
747
-      * @param int                         $stackPtr  The position in the tokens stack to
748
-      *                                               process.
749
-      *
750
-      * @return void
751
-      * @see    registerSupplementary()
752
-      */
753
-    protected function processSupplementary(File $phpcsFile, $stackPtr)
754
-    {
755
-
756
-    }//end processSupplementary()
757
-
758
-
759
-    /**
760
-     * Parses a pattern string into an array of pattern steps.
761
-     *
762
-     * @param string $pattern The pattern to parse.
763
-     *
764
-     * @return array The parsed pattern array.
765
-     * @see    createSkipPattern()
766
-     * @see    createTokenPattern()
767
-     */
768
-    private function parse($pattern)
769
-    {
770
-        $patterns   = [];
771
-        $length     = strlen($pattern);
772
-        $lastToken  = 0;
773
-        $firstToken = 0;
774
-
775
-        for ($i = 0; $i < $length; $i++) {
776
-            $specialPattern = false;
777
-            $isLastChar     = ($i === ($length - 1));
778
-            $oldFirstToken  = $firstToken;
779
-
780
-            if (substr($pattern, $i, 3) === '...') {
781
-                // It's a skip pattern. The skip pattern requires the
782
-                // content of the token in the "from" position and the token
783
-                // to skip to.
784
-                $specialPattern = $this->createSkipPattern($pattern, ($i - 1));
785
-                $lastToken      = ($i - $firstToken);
786
-                $firstToken     = ($i + 3);
787
-                $i += 2;
788
-
789
-                if ($specialPattern['to'] !== 'unknown') {
790
-                    $firstToken++;
791
-                }
792
-            } else if (substr($pattern, $i, 3) === 'abc') {
793
-                $specialPattern = ['type' => 'string'];
794
-                $lastToken      = ($i - $firstToken);
795
-                $firstToken     = ($i + 3);
796
-                $i += 2;
797
-            } else if (substr($pattern, $i, 3) === 'EOL') {
798
-                $specialPattern = ['type' => 'newline'];
799
-                $lastToken      = ($i - $firstToken);
800
-                $firstToken     = ($i + 3);
801
-                $i += 2;
802
-            }//end if
803
-
804
-            if ($specialPattern !== false || $isLastChar === true) {
805
-                // If we are at the end of the string, don't worry about a limit.
806
-                if ($isLastChar === true) {
807
-                    // Get the string from the end of the last skip pattern, if any,
808
-                    // to the end of the pattern string.
809
-                    $str = substr($pattern, $oldFirstToken);
810
-                } else {
811
-                    // Get the string from the end of the last special pattern,
812
-                    // if any, to the start of this special pattern.
813
-                    if ($lastToken === 0) {
814
-                        // Note that if the last special token was zero characters ago,
815
-                        // there will be nothing to process so we can skip this bit.
816
-                        // This happens if you have something like: EOL... in your pattern.
817
-                        $str = '';
818
-                    } else {
819
-                        $str = substr($pattern, $oldFirstToken, $lastToken);
820
-                    }
821
-                }
822
-
823
-                if ($str !== '') {
824
-                    $tokenPatterns = $this->createTokenPattern($str);
825
-                    foreach ($tokenPatterns as $tokenPattern) {
826
-                        $patterns[] = $tokenPattern;
827
-                    }
828
-                }
829
-
830
-                // Make sure we don't skip the last token.
831
-                if ($isLastChar === false && $i === ($length - 1)) {
832
-                    $i--;
833
-                }
834
-            }//end if
835
-
836
-            // Add the skip pattern *after* we have processed
837
-            // all the tokens from the end of the last skip pattern
838
-            // to the start of this skip pattern.
839
-            if ($specialPattern !== false) {
840
-                $patterns[] = $specialPattern;
841
-            }
842
-        }//end for
843
-
844
-        return $patterns;
845
-
846
-    }//end parse()
847
-
848
-
849
-    /**
850
-     * Creates a skip pattern.
851
-     *
852
-     * @param string $pattern The pattern being parsed.
853
-     * @param string $from    The token content that the skip pattern starts from.
854
-     *
855
-     * @return array The pattern step.
856
-     * @see    createTokenPattern()
857
-     * @see    parse()
858
-     */
859
-    private function createSkipPattern($pattern, $from)
860
-    {
861
-        $skip = ['type' => 'skip'];
862
-
863
-        $nestedParenthesis = 0;
864
-        $nestedBraces      = 0;
865
-        for ($start = $from; $start >= 0; $start--) {
866
-            switch ($pattern[$start]) {
867
-            case '(':
868
-                if ($nestedParenthesis === 0) {
869
-                    $skip['to'] = 'parenthesis_closer';
870
-                }
871
-
872
-                $nestedParenthesis--;
873
-                break;
874
-            case '{':
875
-                if ($nestedBraces === 0) {
876
-                    $skip['to'] = 'scope_closer';
877
-                }
878
-
879
-                $nestedBraces--;
880
-                break;
881
-            case '}':
882
-                $nestedBraces++;
883
-                break;
884
-            case ')':
885
-                $nestedParenthesis++;
886
-                break;
887
-            }//end switch
888
-
889
-            if (isset($skip['to']) === true) {
890
-                break;
891
-            }
892
-        }//end for
893
-
894
-        if (isset($skip['to']) === false) {
895
-            $skip['to'] = 'unknown';
896
-        }
897
-
898
-        return $skip;
899
-
900
-    }//end createSkipPattern()
901
-
902
-
903
-    /**
904
-     * Creates a token pattern.
905
-     *
906
-     * @param string $str The tokens string that the pattern should match.
907
-     *
908
-     * @return array The pattern step.
909
-     * @see    createSkipPattern()
910
-     * @see    parse()
911
-     */
912
-    private function createTokenPattern($str)
913
-    {
914
-        // Don't add a space after the closing php tag as it will add a new
915
-        // whitespace token.
916
-        $tokenizer = new PHP('<?php '.$str.'?>', null);
917
-
918
-        // Remove the <?php tag from the front and the end php tag from the back.
919
-        $tokens = $tokenizer->getTokens();
920
-        $tokens = array_slice($tokens, 1, (count($tokens) - 2));
921
-
922
-        $patterns = [];
923
-        foreach ($tokens as $patternInfo) {
924
-            $patterns[] = [
925
-                'type'  => 'token',
926
-                'token' => $patternInfo['code'],
927
-                'value' => $patternInfo['content'],
928
-            ];
929
-        }
930
-
931
-        return $patterns;
932
-
933
-    }//end createTokenPattern()
20
+	/**
21
+	 * If true, comments will be ignored if they are found in the code.
22
+	 *
23
+	 * @var boolean
24
+	 */
25
+	public $ignoreComments = false;
26
+
27
+	/**
28
+	 * The current file being checked.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $currFile = '';
33
+
34
+	/**
35
+	 * The parsed patterns array.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	private $parsedPatterns = [];
40
+
41
+	/**
42
+	 * Tokens that this sniff wishes to process outside of the patterns.
43
+	 *
44
+	 * @var int[]
45
+	 * @see registerSupplementary()
46
+	 * @see processSupplementary()
47
+	 */
48
+	private $supplementaryTokens = [];
49
+
50
+	/**
51
+	 * Positions in the stack where errors have occurred.
52
+	 *
53
+	 * @var array<int, bool>
54
+	 */
55
+	private $errorPos = [];
56
+
57
+
58
+	/**
59
+	 * Constructs a AbstractPatternSniff.
60
+	 *
61
+	 * @param boolean $ignoreComments If true, comments will be ignored.
62
+	 */
63
+	public function __construct($ignoreComments=null)
64
+	{
65
+		// This is here for backwards compatibility.
66
+		if ($ignoreComments !== null) {
67
+			$this->ignoreComments = $ignoreComments;
68
+		}
69
+
70
+		$this->supplementaryTokens = $this->registerSupplementary();
71
+
72
+	}//end __construct()
73
+
74
+
75
+	/**
76
+	 * Registers the tokens to listen to.
77
+	 *
78
+	 * Classes extending <i>AbstractPatternTest</i> should implement the
79
+	 * <i>getPatterns()</i> method to register the patterns they wish to test.
80
+	 *
81
+	 * @return int[]
82
+	 * @see    process()
83
+	 */
84
+	final public function register()
85
+	{
86
+		$listenTypes = [];
87
+		$patterns    = $this->getPatterns();
88
+
89
+		foreach ($patterns as $pattern) {
90
+			$parsedPattern = $this->parse($pattern);
91
+
92
+			// Find a token position in the pattern that we can use
93
+			// for a listener token.
94
+			$pos           = $this->getListenerTokenPos($parsedPattern);
95
+			$tokenType     = $parsedPattern[$pos]['token'];
96
+			$listenTypes[] = $tokenType;
97
+
98
+			$patternArray = [
99
+				'listen_pos'   => $pos,
100
+				'pattern'      => $parsedPattern,
101
+				'pattern_code' => $pattern,
102
+			];
103
+
104
+			if (isset($this->parsedPatterns[$tokenType]) === false) {
105
+				$this->parsedPatterns[$tokenType] = [];
106
+			}
107
+
108
+			$this->parsedPatterns[$tokenType][] = $patternArray;
109
+		}//end foreach
110
+
111
+		return array_unique(array_merge($listenTypes, $this->supplementaryTokens));
112
+
113
+	}//end register()
114
+
115
+
116
+	/**
117
+	 * Returns the token types that the specified pattern is checking for.
118
+	 *
119
+	 * Returned array is in the format:
120
+	 * <code>
121
+	 *   array(
122
+	 *      T_WHITESPACE => 0, // 0 is the position where the T_WHITESPACE token
123
+	 *                         // should occur in the pattern.
124
+	 *   );
125
+	 * </code>
126
+	 *
127
+	 * @param array $pattern The parsed pattern to find the acquire the token
128
+	 *                       types from.
129
+	 *
130
+	 * @return array<int, int>
131
+	 */
132
+	private function getPatternTokenTypes($pattern)
133
+	{
134
+		$tokenTypes = [];
135
+		foreach ($pattern as $pos => $patternInfo) {
136
+			if ($patternInfo['type'] === 'token') {
137
+				if (isset($tokenTypes[$patternInfo['token']]) === false) {
138
+					$tokenTypes[$patternInfo['token']] = $pos;
139
+				}
140
+			}
141
+		}
142
+
143
+		return $tokenTypes;
144
+
145
+	}//end getPatternTokenTypes()
146
+
147
+
148
+	/**
149
+	 * Returns the position in the pattern that this test should register as
150
+	 * a listener for the pattern.
151
+	 *
152
+	 * @param array $pattern The pattern to acquire the listener for.
153
+	 *
154
+	 * @return int The position in the pattern that this test should register
155
+	 *             as the listener.
156
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
157
+	 */
158
+	private function getListenerTokenPos($pattern)
159
+	{
160
+		$tokenTypes = $this->getPatternTokenTypes($pattern);
161
+		$tokenCodes = array_keys($tokenTypes);
162
+		$token      = Tokens::getHighestWeightedToken($tokenCodes);
163
+
164
+		// If we could not get a token.
165
+		if ($token === false) {
166
+			$error = 'Could not determine a token to listen for';
167
+			throw new RuntimeException($error);
168
+		}
169
+
170
+		return $tokenTypes[$token];
171
+
172
+	}//end getListenerTokenPos()
173
+
174
+
175
+	/**
176
+	 * Processes the test.
177
+	 *
178
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
179
+	 *                                               token occurred.
180
+	 * @param int                         $stackPtr  The position in the tokens stack
181
+	 *                                               where the listening token type
182
+	 *                                               was found.
183
+	 *
184
+	 * @return void
185
+	 * @see    register()
186
+	 */
187
+	final public function process(File $phpcsFile, $stackPtr)
188
+	{
189
+		$file = $phpcsFile->getFilename();
190
+		if ($this->currFile !== $file) {
191
+			// We have changed files, so clean up.
192
+			$this->errorPos = [];
193
+			$this->currFile = $file;
194
+		}
195
+
196
+		$tokens = $phpcsFile->getTokens();
197
+
198
+		if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens, true) === true) {
199
+			$this->processSupplementary($phpcsFile, $stackPtr);
200
+		}
201
+
202
+		$type = $tokens[$stackPtr]['code'];
203
+
204
+		// If the type is not set, then it must have been a token registered
205
+		// with registerSupplementary().
206
+		if (isset($this->parsedPatterns[$type]) === false) {
207
+			return;
208
+		}
209
+
210
+		$allErrors = [];
211
+
212
+		// Loop over each pattern that is listening to the current token type
213
+		// that we are processing.
214
+		foreach ($this->parsedPatterns[$type] as $patternInfo) {
215
+			// If processPattern returns false, then the pattern that we are
216
+			// checking the code with must not be designed to check that code.
217
+			$errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
218
+			if ($errors === false) {
219
+				// The pattern didn't match.
220
+				continue;
221
+			} else if (empty($errors) === true) {
222
+				// The pattern matched, but there were no errors.
223
+				break;
224
+			}
225
+
226
+			foreach ($errors as $stackPtr => $error) {
227
+				if (isset($this->errorPos[$stackPtr]) === false) {
228
+					$this->errorPos[$stackPtr] = true;
229
+					$allErrors[$stackPtr]      = $error;
230
+				}
231
+			}
232
+		}
233
+
234
+		foreach ($allErrors as $stackPtr => $error) {
235
+			$phpcsFile->addError($error, $stackPtr, 'Found');
236
+		}
237
+
238
+	}//end process()
239
+
240
+
241
+	/**
242
+	 * Processes the pattern and verifies the code at $stackPtr.
243
+	 *
244
+	 * @param array                       $patternInfo Information about the pattern used
245
+	 *                                                 for checking, which includes are
246
+	 *                                                 parsed token representation of the
247
+	 *                                                 pattern.
248
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile   The PHP_CodeSniffer file where the
249
+	 *                                                 token occurred.
250
+	 * @param int                         $stackPtr    The position in the tokens stack where
251
+	 *                                                 the listening token type was found.
252
+	 *
253
+	 * @return array
254
+	 */
255
+	protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
256
+	{
257
+		$tokens      = $phpcsFile->getTokens();
258
+		$pattern     = $patternInfo['pattern'];
259
+		$patternCode = $patternInfo['pattern_code'];
260
+		$errors      = [];
261
+		$found       = '';
262
+
263
+		$ignoreTokens = [T_WHITESPACE => T_WHITESPACE];
264
+		if ($this->ignoreComments === true) {
265
+			$ignoreTokens += Tokens::$commentTokens;
266
+		}
267
+
268
+		$origStackPtr = $stackPtr;
269
+		$hasError     = false;
270
+
271
+		if ($patternInfo['listen_pos'] > 0) {
272
+			$stackPtr--;
273
+
274
+			for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
275
+				if ($pattern[$i]['type'] === 'token') {
276
+					if ($pattern[$i]['token'] === T_WHITESPACE) {
277
+						if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
278
+							$found = $tokens[$stackPtr]['content'].$found;
279
+						}
280
+
281
+						// Only check the size of the whitespace if this is not
282
+						// the first token. We don't care about the size of
283
+						// leading whitespace, just that there is some.
284
+						if ($i !== 0) {
285
+							if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
286
+								$hasError = true;
287
+							}
288
+						}
289
+					} else {
290
+						// Check to see if this important token is the same as the
291
+						// previous important token in the pattern. If it is not,
292
+						// then the pattern cannot be for this piece of code.
293
+						$prev = $phpcsFile->findPrevious(
294
+							$ignoreTokens,
295
+							$stackPtr,
296
+							null,
297
+							true
298
+						);
299
+
300
+						if ($prev === false
301
+							|| $tokens[$prev]['code'] !== $pattern[$i]['token']
302
+						) {
303
+							return false;
304
+						}
305
+
306
+						// If we skipped past some whitespace tokens, then add them
307
+						// to the found string.
308
+						$tokenContent = $phpcsFile->getTokensAsString(
309
+							($prev + 1),
310
+							($stackPtr - $prev - 1)
311
+						);
312
+
313
+						$found = $tokens[$prev]['content'].$tokenContent.$found;
314
+
315
+						if (isset($pattern[($i - 1)]) === true
316
+							&& $pattern[($i - 1)]['type'] === 'skip'
317
+						) {
318
+							$stackPtr = $prev;
319
+						} else {
320
+							$stackPtr = ($prev - 1);
321
+						}
322
+					}//end if
323
+				} else if ($pattern[$i]['type'] === 'skip') {
324
+					// Skip to next piece of relevant code.
325
+					if ($pattern[$i]['to'] === 'parenthesis_closer') {
326
+						$to = 'parenthesis_opener';
327
+					} else {
328
+						$to = 'scope_opener';
329
+					}
330
+
331
+					// Find the previous opener.
332
+					$next = $phpcsFile->findPrevious(
333
+						$ignoreTokens,
334
+						$stackPtr,
335
+						null,
336
+						true
337
+					);
338
+
339
+					if ($next === false || isset($tokens[$next][$to]) === false) {
340
+						// If there was not opener, then we must be
341
+						// using the wrong pattern.
342
+						return false;
343
+					}
344
+
345
+					if ($to === 'parenthesis_opener') {
346
+						$found = '{'.$found;
347
+					} else {
348
+						$found = '('.$found;
349
+					}
350
+
351
+					$found = '...'.$found;
352
+
353
+					// Skip to the opening token.
354
+					$stackPtr = ($tokens[$next][$to] - 1);
355
+				} else if ($pattern[$i]['type'] === 'string') {
356
+					$found = 'abc';
357
+				} else if ($pattern[$i]['type'] === 'newline') {
358
+					if ($this->ignoreComments === true
359
+						&& isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true
360
+					) {
361
+						$startComment = $phpcsFile->findPrevious(
362
+							Tokens::$commentTokens,
363
+							($stackPtr - 1),
364
+							null,
365
+							true
366
+						);
367
+
368
+						if ($tokens[$startComment]['line'] !== $tokens[($startComment + 1)]['line']) {
369
+							$startComment++;
370
+						}
371
+
372
+						$tokenContent = $phpcsFile->getTokensAsString(
373
+							$startComment,
374
+							($stackPtr - $startComment + 1)
375
+						);
376
+
377
+						$found    = $tokenContent.$found;
378
+						$stackPtr = ($startComment - 1);
379
+					}
380
+
381
+					if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
382
+						if ($tokens[$stackPtr]['content'] !== $phpcsFile->eolChar) {
383
+							$found = $tokens[$stackPtr]['content'].$found;
384
+
385
+							// This may just be an indent that comes after a newline
386
+							// so check the token before to make sure. If it is a newline, we
387
+							// can ignore the error here.
388
+							if (($tokens[($stackPtr - 1)]['content'] !== $phpcsFile->eolChar)
389
+								&& ($this->ignoreComments === true
390
+								&& isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === false)
391
+							) {
392
+								$hasError = true;
393
+							} else {
394
+								$stackPtr--;
395
+							}
396
+						} else {
397
+							$found = 'EOL'.$found;
398
+						}
399
+					} else {
400
+						$found    = $tokens[$stackPtr]['content'].$found;
401
+						$hasError = true;
402
+					}//end if
403
+
404
+					if ($hasError === false && $pattern[($i - 1)]['type'] !== 'newline') {
405
+						// Make sure they only have 1 newline.
406
+						$prev = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true);
407
+						if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line']) {
408
+							$hasError = true;
409
+						}
410
+					}
411
+				}//end if
412
+			}//end for
413
+		}//end if
414
+
415
+		$stackPtr          = $origStackPtr;
416
+		$lastAddedStackPtr = null;
417
+		$patternLen        = count($pattern);
418
+
419
+		for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
420
+			if (isset($tokens[$stackPtr]) === false) {
421
+				break;
422
+			}
423
+
424
+			if ($pattern[$i]['type'] === 'token') {
425
+				if ($pattern[$i]['token'] === T_WHITESPACE) {
426
+					if ($this->ignoreComments === true) {
427
+						// If we are ignoring comments, check to see if this current
428
+						// token is a comment. If so skip it.
429
+						if (isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true) {
430
+							continue;
431
+						}
432
+
433
+						// If the next token is a comment, the we need to skip the
434
+						// current token as we should allow a space before a
435
+						// comment for readability.
436
+						if (isset($tokens[($stackPtr + 1)]) === true
437
+							&& isset(Tokens::$commentTokens[$tokens[($stackPtr + 1)]['code']]) === true
438
+						) {
439
+							continue;
440
+						}
441
+					}
442
+
443
+					$tokenContent = '';
444
+					if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
445
+						if (isset($pattern[($i + 1)]) === false) {
446
+							// This is the last token in the pattern, so just compare
447
+							// the next token of content.
448
+							$tokenContent = $tokens[$stackPtr]['content'];
449
+						} else {
450
+							// Get all the whitespace to the next token.
451
+							$next = $phpcsFile->findNext(
452
+								Tokens::$emptyTokens,
453
+								$stackPtr,
454
+								null,
455
+								true
456
+							);
457
+
458
+							$tokenContent = $phpcsFile->getTokensAsString(
459
+								$stackPtr,
460
+								($next - $stackPtr)
461
+							);
462
+
463
+							$lastAddedStackPtr = $stackPtr;
464
+							$stackPtr          = $next;
465
+						}//end if
466
+
467
+						if ($stackPtr !== $lastAddedStackPtr) {
468
+							$found .= $tokenContent;
469
+						}
470
+					} else {
471
+						if ($stackPtr !== $lastAddedStackPtr) {
472
+							$found            .= $tokens[$stackPtr]['content'];
473
+							$lastAddedStackPtr = $stackPtr;
474
+						}
475
+					}//end if
476
+
477
+					if (isset($pattern[($i + 1)]) === true
478
+						&& $pattern[($i + 1)]['type'] === 'skip'
479
+					) {
480
+						// The next token is a skip token, so we just need to make
481
+						// sure the whitespace we found has *at least* the
482
+						// whitespace required.
483
+						if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
484
+							$hasError = true;
485
+						}
486
+					} else {
487
+						if ($tokenContent !== $pattern[$i]['value']) {
488
+							$hasError = true;
489
+						}
490
+					}
491
+				} else {
492
+					// Check to see if this important token is the same as the
493
+					// next important token in the pattern. If it is not, then
494
+					// the pattern cannot be for this piece of code.
495
+					$next = $phpcsFile->findNext(
496
+						$ignoreTokens,
497
+						$stackPtr,
498
+						null,
499
+						true
500
+					);
501
+
502
+					if ($next === false
503
+						|| $tokens[$next]['code'] !== $pattern[$i]['token']
504
+					) {
505
+						// The next important token did not match the pattern.
506
+						return false;
507
+					}
508
+
509
+					if ($lastAddedStackPtr !== null) {
510
+						if (($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET
511
+							|| $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET)
512
+							&& isset($tokens[$next]['scope_condition']) === true
513
+							&& $tokens[$next]['scope_condition'] > $lastAddedStackPtr
514
+						) {
515
+							// This is a brace, but the owner of it is after the current
516
+							// token, which means it does not belong to any token in
517
+							// our pattern. This means the pattern is not for us.
518
+							return false;
519
+						}
520
+
521
+						if (($tokens[$next]['code'] === T_OPEN_PARENTHESIS
522
+							|| $tokens[$next]['code'] === T_CLOSE_PARENTHESIS)
523
+							&& isset($tokens[$next]['parenthesis_owner']) === true
524
+							&& $tokens[$next]['parenthesis_owner'] > $lastAddedStackPtr
525
+						) {
526
+							// This is a bracket, but the owner of it is after the current
527
+							// token, which means it does not belong to any token in
528
+							// our pattern. This means the pattern is not for us.
529
+							return false;
530
+						}
531
+					}//end if
532
+
533
+					// If we skipped past some whitespace tokens, then add them
534
+					// to the found string.
535
+					if (($next - $stackPtr) > 0) {
536
+						$hasComment = false;
537
+						for ($j = $stackPtr; $j < $next; $j++) {
538
+							$found .= $tokens[$j]['content'];
539
+							if (isset(Tokens::$commentTokens[$tokens[$j]['code']]) === true) {
540
+								$hasComment = true;
541
+							}
542
+						}
543
+
544
+						// If we are not ignoring comments, this additional
545
+						// whitespace or comment is not allowed. If we are
546
+						// ignoring comments, there needs to be at least one
547
+						// comment for this to be allowed.
548
+						if ($this->ignoreComments === false
549
+							|| ($this->ignoreComments === true
550
+							&& $hasComment === false)
551
+						) {
552
+							$hasError = true;
553
+						}
554
+
555
+						// Even when ignoring comments, we are not allowed to include
556
+						// newlines without the pattern specifying them, so
557
+						// everything should be on the same line.
558
+						if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
559
+							$hasError = true;
560
+						}
561
+					}//end if
562
+
563
+					if ($next !== $lastAddedStackPtr) {
564
+						$found            .= $tokens[$next]['content'];
565
+						$lastAddedStackPtr = $next;
566
+					}
567
+
568
+					if (isset($pattern[($i + 1)]) === true
569
+						&& $pattern[($i + 1)]['type'] === 'skip'
570
+					) {
571
+						$stackPtr = $next;
572
+					} else {
573
+						$stackPtr = ($next + 1);
574
+					}
575
+				}//end if
576
+			} else if ($pattern[$i]['type'] === 'skip') {
577
+				if ($pattern[$i]['to'] === 'unknown') {
578
+					$next = $phpcsFile->findNext(
579
+						$pattern[($i + 1)]['token'],
580
+						$stackPtr
581
+					);
582
+
583
+					if ($next === false) {
584
+						// Couldn't find the next token, so we must
585
+						// be using the wrong pattern.
586
+						return false;
587
+					}
588
+
589
+					$found   .= '...';
590
+					$stackPtr = $next;
591
+				} else {
592
+					// Find the previous opener.
593
+					$next = $phpcsFile->findPrevious(
594
+						Tokens::$blockOpeners,
595
+						$stackPtr
596
+					);
597
+
598
+					if ($next === false
599
+						|| isset($tokens[$next][$pattern[$i]['to']]) === false
600
+					) {
601
+						// If there was not opener, then we must
602
+						// be using the wrong pattern.
603
+						return false;
604
+					}
605
+
606
+					$found .= '...';
607
+					if ($pattern[$i]['to'] === 'parenthesis_closer') {
608
+						$found .= ')';
609
+					} else {
610
+						$found .= '}';
611
+					}
612
+
613
+					// Skip to the closing token.
614
+					$stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
615
+				}//end if
616
+			} else if ($pattern[$i]['type'] === 'string') {
617
+				if ($tokens[$stackPtr]['code'] !== T_STRING) {
618
+					$hasError = true;
619
+				}
620
+
621
+				if ($stackPtr !== $lastAddedStackPtr) {
622
+					$found            .= 'abc';
623
+					$lastAddedStackPtr = $stackPtr;
624
+				}
625
+
626
+				$stackPtr++;
627
+			} else if ($pattern[$i]['type'] === 'newline') {
628
+				// Find the next token that contains a newline character.
629
+				$newline = 0;
630
+				for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
631
+					if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
632
+						$newline = $j;
633
+						break;
634
+					}
635
+				}
636
+
637
+				if ($newline === 0) {
638
+					// We didn't find a newline character in the rest of the file.
639
+					$next     = ($phpcsFile->numTokens - 1);
640
+					$hasError = true;
641
+				} else {
642
+					if ($this->ignoreComments === false) {
643
+						// The newline character cannot be part of a comment.
644
+						if (isset(Tokens::$commentTokens[$tokens[$newline]['code']]) === true) {
645
+							$hasError = true;
646
+						}
647
+					}
648
+
649
+					if ($newline === $stackPtr) {
650
+						$next = ($stackPtr + 1);
651
+					} else {
652
+						// Check that there were no significant tokens that we
653
+						// skipped over to find our newline character.
654
+						$next = $phpcsFile->findNext(
655
+							$ignoreTokens,
656
+							$stackPtr,
657
+							null,
658
+							true
659
+						);
660
+
661
+						if ($next < $newline) {
662
+							// We skipped a non-ignored token.
663
+							$hasError = true;
664
+						} else {
665
+							$next = ($newline + 1);
666
+						}
667
+					}
668
+				}//end if
669
+
670
+				if ($stackPtr !== $lastAddedStackPtr) {
671
+					$found .= $phpcsFile->getTokensAsString(
672
+						$stackPtr,
673
+						($next - $stackPtr)
674
+					);
675
+
676
+					$lastAddedStackPtr = ($next - 1);
677
+				}
678
+
679
+				$stackPtr = $next;
680
+			}//end if
681
+		}//end for
682
+
683
+		if ($hasError === true) {
684
+			$error = $this->prepareError($found, $patternCode);
685
+			$errors[$origStackPtr] = $error;
686
+		}
687
+
688
+		return $errors;
689
+
690
+	}//end processPattern()
691
+
692
+
693
+	/**
694
+	 * Prepares an error for the specified patternCode.
695
+	 *
696
+	 * @param string $found       The actual found string in the code.
697
+	 * @param string $patternCode The expected pattern code.
698
+	 *
699
+	 * @return string The error message.
700
+	 */
701
+	protected function prepareError($found, $patternCode)
702
+	{
703
+		$found    = str_replace("\r\n", '\n', $found);
704
+		$found    = str_replace("\n", '\n', $found);
705
+		$found    = str_replace("\r", '\n', $found);
706
+		$found    = str_replace("\t", '\t', $found);
707
+		$found    = str_replace('EOL', '\n', $found);
708
+		$expected = str_replace('EOL', '\n', $patternCode);
709
+
710
+		$error = "Expected \"$expected\"; found \"$found\"";
711
+
712
+		return $error;
713
+
714
+	}//end prepareError()
715
+
716
+
717
+	/**
718
+	 * Returns the patterns that should be checked.
719
+	 *
720
+	 * @return string[]
721
+	 */
722
+	abstract protected function getPatterns();
723
+
724
+
725
+	/**
726
+	 * Registers any supplementary tokens that this test might wish to process.
727
+	 *
728
+	 * A sniff may wish to register supplementary tests when it wishes to group
729
+	 * an arbitrary validation that cannot be performed using a pattern, with
730
+	 * other pattern tests.
731
+	 *
732
+	 * @return int[]
733
+	 * @see    processSupplementary()
734
+	 */
735
+	protected function registerSupplementary()
736
+	{
737
+		return [];
738
+
739
+	}//end registerSupplementary()
740
+
741
+
742
+	 /**
743
+	  * Processes any tokens registered with registerSupplementary().
744
+	  *
745
+	  * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where to
746
+	  *                                               process the skip.
747
+	  * @param int                         $stackPtr  The position in the tokens stack to
748
+	  *                                               process.
749
+	  *
750
+	  * @return void
751
+	  * @see    registerSupplementary()
752
+	  */
753
+	protected function processSupplementary(File $phpcsFile, $stackPtr)
754
+	{
755
+
756
+	}//end processSupplementary()
757
+
758
+
759
+	/**
760
+	 * Parses a pattern string into an array of pattern steps.
761
+	 *
762
+	 * @param string $pattern The pattern to parse.
763
+	 *
764
+	 * @return array The parsed pattern array.
765
+	 * @see    createSkipPattern()
766
+	 * @see    createTokenPattern()
767
+	 */
768
+	private function parse($pattern)
769
+	{
770
+		$patterns   = [];
771
+		$length     = strlen($pattern);
772
+		$lastToken  = 0;
773
+		$firstToken = 0;
774
+
775
+		for ($i = 0; $i < $length; $i++) {
776
+			$specialPattern = false;
777
+			$isLastChar     = ($i === ($length - 1));
778
+			$oldFirstToken  = $firstToken;
779
+
780
+			if (substr($pattern, $i, 3) === '...') {
781
+				// It's a skip pattern. The skip pattern requires the
782
+				// content of the token in the "from" position and the token
783
+				// to skip to.
784
+				$specialPattern = $this->createSkipPattern($pattern, ($i - 1));
785
+				$lastToken      = ($i - $firstToken);
786
+				$firstToken     = ($i + 3);
787
+				$i += 2;
788
+
789
+				if ($specialPattern['to'] !== 'unknown') {
790
+					$firstToken++;
791
+				}
792
+			} else if (substr($pattern, $i, 3) === 'abc') {
793
+				$specialPattern = ['type' => 'string'];
794
+				$lastToken      = ($i - $firstToken);
795
+				$firstToken     = ($i + 3);
796
+				$i += 2;
797
+			} else if (substr($pattern, $i, 3) === 'EOL') {
798
+				$specialPattern = ['type' => 'newline'];
799
+				$lastToken      = ($i - $firstToken);
800
+				$firstToken     = ($i + 3);
801
+				$i += 2;
802
+			}//end if
803
+
804
+			if ($specialPattern !== false || $isLastChar === true) {
805
+				// If we are at the end of the string, don't worry about a limit.
806
+				if ($isLastChar === true) {
807
+					// Get the string from the end of the last skip pattern, if any,
808
+					// to the end of the pattern string.
809
+					$str = substr($pattern, $oldFirstToken);
810
+				} else {
811
+					// Get the string from the end of the last special pattern,
812
+					// if any, to the start of this special pattern.
813
+					if ($lastToken === 0) {
814
+						// Note that if the last special token was zero characters ago,
815
+						// there will be nothing to process so we can skip this bit.
816
+						// This happens if you have something like: EOL... in your pattern.
817
+						$str = '';
818
+					} else {
819
+						$str = substr($pattern, $oldFirstToken, $lastToken);
820
+					}
821
+				}
822
+
823
+				if ($str !== '') {
824
+					$tokenPatterns = $this->createTokenPattern($str);
825
+					foreach ($tokenPatterns as $tokenPattern) {
826
+						$patterns[] = $tokenPattern;
827
+					}
828
+				}
829
+
830
+				// Make sure we don't skip the last token.
831
+				if ($isLastChar === false && $i === ($length - 1)) {
832
+					$i--;
833
+				}
834
+			}//end if
835
+
836
+			// Add the skip pattern *after* we have processed
837
+			// all the tokens from the end of the last skip pattern
838
+			// to the start of this skip pattern.
839
+			if ($specialPattern !== false) {
840
+				$patterns[] = $specialPattern;
841
+			}
842
+		}//end for
843
+
844
+		return $patterns;
845
+
846
+	}//end parse()
847
+
848
+
849
+	/**
850
+	 * Creates a skip pattern.
851
+	 *
852
+	 * @param string $pattern The pattern being parsed.
853
+	 * @param string $from    The token content that the skip pattern starts from.
854
+	 *
855
+	 * @return array The pattern step.
856
+	 * @see    createTokenPattern()
857
+	 * @see    parse()
858
+	 */
859
+	private function createSkipPattern($pattern, $from)
860
+	{
861
+		$skip = ['type' => 'skip'];
862
+
863
+		$nestedParenthesis = 0;
864
+		$nestedBraces      = 0;
865
+		for ($start = $from; $start >= 0; $start--) {
866
+			switch ($pattern[$start]) {
867
+			case '(':
868
+				if ($nestedParenthesis === 0) {
869
+					$skip['to'] = 'parenthesis_closer';
870
+				}
871
+
872
+				$nestedParenthesis--;
873
+				break;
874
+			case '{':
875
+				if ($nestedBraces === 0) {
876
+					$skip['to'] = 'scope_closer';
877
+				}
878
+
879
+				$nestedBraces--;
880
+				break;
881
+			case '}':
882
+				$nestedBraces++;
883
+				break;
884
+			case ')':
885
+				$nestedParenthesis++;
886
+				break;
887
+			}//end switch
888
+
889
+			if (isset($skip['to']) === true) {
890
+				break;
891
+			}
892
+		}//end for
893
+
894
+		if (isset($skip['to']) === false) {
895
+			$skip['to'] = 'unknown';
896
+		}
897
+
898
+		return $skip;
899
+
900
+	}//end createSkipPattern()
901
+
902
+
903
+	/**
904
+	 * Creates a token pattern.
905
+	 *
906
+	 * @param string $str The tokens string that the pattern should match.
907
+	 *
908
+	 * @return array The pattern step.
909
+	 * @see    createSkipPattern()
910
+	 * @see    parse()
911
+	 */
912
+	private function createTokenPattern($str)
913
+	{
914
+		// Don't add a space after the closing php tag as it will add a new
915
+		// whitespace token.
916
+		$tokenizer = new PHP('<?php '.$str.'?>', null);
917
+
918
+		// Remove the <?php tag from the front and the end php tag from the back.
919
+		$tokens = $tokenizer->getTokens();
920
+		$tokens = array_slice($tokens, 1, (count($tokens) - 2));
921
+
922
+		$patterns = [];
923
+		foreach ($tokens as $patternInfo) {
924
+			$patterns[] = [
925
+				'type'  => 'token',
926
+				'token' => $patternInfo['code'],
927
+				'value' => $patternInfo['content'],
928
+			];
929
+		}
930
+
931
+		return $patterns;
932
+
933
+	}//end createTokenPattern()
934 934
 
935 935
 
936 936
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -864,26 +864,26 @@
 block discarded – undo
864 864
         $nestedBraces      = 0;
865 865
         for ($start = $from; $start >= 0; $start--) {
866 866
             switch ($pattern[$start]) {
867
-            case '(':
868
-                if ($nestedParenthesis === 0) {
869
-                    $skip['to'] = 'parenthesis_closer';
870
-                }
871
-
872
-                $nestedParenthesis--;
873
-                break;
874
-            case '{':
875
-                if ($nestedBraces === 0) {
876
-                    $skip['to'] = 'scope_closer';
877
-                }
878
-
879
-                $nestedBraces--;
880
-                break;
881
-            case '}':
882
-                $nestedBraces++;
883
-                break;
884
-            case ')':
885
-                $nestedParenthesis++;
886
-                break;
867
+            	case '(':
868
+                	if ($nestedParenthesis === 0) {
869
+                    	$skip['to'] = 'parenthesis_closer';
870
+                	}
871
+
872
+                	$nestedParenthesis--;
873
+                	break;
874
+            	case '{':
875
+                	if ($nestedBraces === 0) {
876
+                    	$skip['to'] = 'scope_closer';
877
+                	}
878
+
879
+                	$nestedBraces--;
880
+                	break;
881
+            	case '}':
882
+                	$nestedBraces++;
883
+                	break;
884
+            	case ')':
885
+                	$nestedParenthesis++;
886
+                	break;
887 887
             }//end switch
888 888
 
889 889
             if (isset($skip['to']) === true) {
Please login to merge, or discard this patch.
Spacing   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @var array
38 38
      */
39
-    private $parsedPatterns = [];
39
+    private $parsedPatterns = [ ];
40 40
 
41 41
     /**
42 42
      * Tokens that this sniff wishes to process outside of the patterns.
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
      * @see registerSupplementary()
46 46
      * @see processSupplementary()
47 47
      */
48
-    private $supplementaryTokens = [];
48
+    private $supplementaryTokens = [ ];
49 49
 
50 50
     /**
51 51
      * Positions in the stack where errors have occurred.
52 52
      *
53 53
      * @var array<int, bool>
54 54
      */
55
-    private $errorPos = [];
55
+    private $errorPos = [ ];
56 56
 
57 57
 
58 58
     /**
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @param boolean $ignoreComments If true, comments will be ignored.
62 62
      */
63
-    public function __construct($ignoreComments=null)
63
+    public function __construct( $ignoreComments = null )
64 64
     {
65 65
         // This is here for backwards compatibility.
66
-        if ($ignoreComments !== null) {
66
+        if ( $ignoreComments !== null ) {
67 67
             $this->ignoreComments = $ignoreComments;
68 68
         }
69 69
 
@@ -83,17 +83,17 @@  discard block
 block discarded – undo
83 83
      */
84 84
     final public function register()
85 85
     {
86
-        $listenTypes = [];
86
+        $listenTypes = [ ];
87 87
         $patterns    = $this->getPatterns();
88 88
 
89
-        foreach ($patterns as $pattern) {
90
-            $parsedPattern = $this->parse($pattern);
89
+        foreach ( $patterns as $pattern ) {
90
+            $parsedPattern = $this->parse( $pattern );
91 91
 
92 92
             // Find a token position in the pattern that we can use
93 93
             // for a listener token.
94
-            $pos           = $this->getListenerTokenPos($parsedPattern);
95
-            $tokenType     = $parsedPattern[$pos]['token'];
96
-            $listenTypes[] = $tokenType;
94
+            $pos           = $this->getListenerTokenPos( $parsedPattern );
95
+            $tokenType     = $parsedPattern[ $pos ][ 'token' ];
96
+            $listenTypes[ ] = $tokenType;
97 97
 
98 98
             $patternArray = [
99 99
                 'listen_pos'   => $pos,
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
                 'pattern_code' => $pattern,
102 102
             ];
103 103
 
104
-            if (isset($this->parsedPatterns[$tokenType]) === false) {
105
-                $this->parsedPatterns[$tokenType] = [];
104
+            if ( isset( $this->parsedPatterns[ $tokenType ] ) === false ) {
105
+                $this->parsedPatterns[ $tokenType ] = [ ];
106 106
             }
107 107
 
108
-            $this->parsedPatterns[$tokenType][] = $patternArray;
108
+            $this->parsedPatterns[ $tokenType ][ ] = $patternArray;
109 109
         }//end foreach
110 110
 
111
-        return array_unique(array_merge($listenTypes, $this->supplementaryTokens));
111
+        return array_unique( array_merge( $listenTypes, $this->supplementaryTokens ) );
112 112
 
113 113
     }//end register()
114 114
 
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return array<int, int>
131 131
      */
132
-    private function getPatternTokenTypes($pattern)
132
+    private function getPatternTokenTypes( $pattern )
133 133
     {
134
-        $tokenTypes = [];
135
-        foreach ($pattern as $pos => $patternInfo) {
136
-            if ($patternInfo['type'] === 'token') {
137
-                if (isset($tokenTypes[$patternInfo['token']]) === false) {
138
-                    $tokenTypes[$patternInfo['token']] = $pos;
134
+        $tokenTypes = [ ];
135
+        foreach ( $pattern as $pos => $patternInfo ) {
136
+            if ( $patternInfo[ 'type' ] === 'token' ) {
137
+                if ( isset( $tokenTypes[ $patternInfo[ 'token' ] ] ) === false ) {
138
+                    $tokenTypes[ $patternInfo[ 'token' ] ] = $pos;
139 139
                 }
140 140
             }
141 141
         }
@@ -155,19 +155,19 @@  discard block
 block discarded – undo
155 155
      *             as the listener.
156 156
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
157 157
      */
158
-    private function getListenerTokenPos($pattern)
158
+    private function getListenerTokenPos( $pattern )
159 159
     {
160
-        $tokenTypes = $this->getPatternTokenTypes($pattern);
161
-        $tokenCodes = array_keys($tokenTypes);
162
-        $token      = Tokens::getHighestWeightedToken($tokenCodes);
160
+        $tokenTypes = $this->getPatternTokenTypes( $pattern );
161
+        $tokenCodes = array_keys( $tokenTypes );
162
+        $token      = Tokens::getHighestWeightedToken( $tokenCodes );
163 163
 
164 164
         // If we could not get a token.
165
-        if ($token === false) {
165
+        if ( $token === false ) {
166 166
             $error = 'Could not determine a token to listen for';
167
-            throw new RuntimeException($error);
167
+            throw new RuntimeException( $error );
168 168
         }
169 169
 
170
-        return $tokenTypes[$token];
170
+        return $tokenTypes[ $token ];
171 171
 
172 172
     }//end getListenerTokenPos()
173 173
 
@@ -184,55 +184,55 @@  discard block
 block discarded – undo
184 184
      * @return void
185 185
      * @see    register()
186 186
      */
187
-    final public function process(File $phpcsFile, $stackPtr)
187
+    final public function process( File $phpcsFile, $stackPtr )
188 188
     {
189 189
         $file = $phpcsFile->getFilename();
190
-        if ($this->currFile !== $file) {
190
+        if ( $this->currFile !== $file ) {
191 191
             // We have changed files, so clean up.
192
-            $this->errorPos = [];
192
+            $this->errorPos = [ ];
193 193
             $this->currFile = $file;
194 194
         }
195 195
 
196 196
         $tokens = $phpcsFile->getTokens();
197 197
 
198
-        if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens, true) === true) {
199
-            $this->processSupplementary($phpcsFile, $stackPtr);
198
+        if ( in_array( $tokens[ $stackPtr ][ 'code' ], $this->supplementaryTokens, true ) === true ) {
199
+            $this->processSupplementary( $phpcsFile, $stackPtr );
200 200
         }
201 201
 
202
-        $type = $tokens[$stackPtr]['code'];
202
+        $type = $tokens[ $stackPtr ][ 'code' ];
203 203
 
204 204
         // If the type is not set, then it must have been a token registered
205 205
         // with registerSupplementary().
206
-        if (isset($this->parsedPatterns[$type]) === false) {
206
+        if ( isset( $this->parsedPatterns[ $type ] ) === false ) {
207 207
             return;
208 208
         }
209 209
 
210
-        $allErrors = [];
210
+        $allErrors = [ ];
211 211
 
212 212
         // Loop over each pattern that is listening to the current token type
213 213
         // that we are processing.
214
-        foreach ($this->parsedPatterns[$type] as $patternInfo) {
214
+        foreach ( $this->parsedPatterns[ $type ] as $patternInfo ) {
215 215
             // If processPattern returns false, then the pattern that we are
216 216
             // checking the code with must not be designed to check that code.
217
-            $errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
218
-            if ($errors === false) {
217
+            $errors = $this->processPattern( $patternInfo, $phpcsFile, $stackPtr );
218
+            if ( $errors === false ) {
219 219
                 // The pattern didn't match.
220 220
                 continue;
221
-            } else if (empty($errors) === true) {
221
+            } else if ( empty( $errors ) === true ) {
222 222
                 // The pattern matched, but there were no errors.
223 223
                 break;
224 224
             }
225 225
 
226
-            foreach ($errors as $stackPtr => $error) {
227
-                if (isset($this->errorPos[$stackPtr]) === false) {
228
-                    $this->errorPos[$stackPtr] = true;
229
-                    $allErrors[$stackPtr]      = $error;
226
+            foreach ( $errors as $stackPtr => $error ) {
227
+                if ( isset( $this->errorPos[ $stackPtr ] ) === false ) {
228
+                    $this->errorPos[ $stackPtr ] = true;
229
+                    $allErrors[ $stackPtr ]      = $error;
230 230
                 }
231 231
             }
232 232
         }
233 233
 
234
-        foreach ($allErrors as $stackPtr => $error) {
235
-            $phpcsFile->addError($error, $stackPtr, 'Found');
234
+        foreach ( $allErrors as $stackPtr => $error ) {
235
+            $phpcsFile->addError( $error, $stackPtr, 'Found' );
236 236
         }
237 237
 
238 238
     }//end process()
@@ -252,37 +252,37 @@  discard block
 block discarded – undo
252 252
      *
253 253
      * @return array
254 254
      */
255
-    protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
255
+    protected function processPattern( $patternInfo, File $phpcsFile, $stackPtr )
256 256
     {
257 257
         $tokens      = $phpcsFile->getTokens();
258
-        $pattern     = $patternInfo['pattern'];
259
-        $patternCode = $patternInfo['pattern_code'];
260
-        $errors      = [];
258
+        $pattern     = $patternInfo[ 'pattern' ];
259
+        $patternCode = $patternInfo[ 'pattern_code' ];
260
+        $errors      = [ ];
261 261
         $found       = '';
262 262
 
263
-        $ignoreTokens = [T_WHITESPACE => T_WHITESPACE];
264
-        if ($this->ignoreComments === true) {
263
+        $ignoreTokens = [ T_WHITESPACE => T_WHITESPACE ];
264
+        if ( $this->ignoreComments === true ) {
265 265
             $ignoreTokens += Tokens::$commentTokens;
266 266
         }
267 267
 
268 268
         $origStackPtr = $stackPtr;
269 269
         $hasError     = false;
270 270
 
271
-        if ($patternInfo['listen_pos'] > 0) {
271
+        if ( $patternInfo[ 'listen_pos' ] > 0 ) {
272 272
             $stackPtr--;
273 273
 
274
-            for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
275
-                if ($pattern[$i]['type'] === 'token') {
276
-                    if ($pattern[$i]['token'] === T_WHITESPACE) {
277
-                        if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
278
-                            $found = $tokens[$stackPtr]['content'].$found;
274
+            for ( $i = ( $patternInfo[ 'listen_pos' ] - 1 ); $i >= 0; $i-- ) {
275
+                if ( $pattern[ $i ][ 'type' ] === 'token' ) {
276
+                    if ( $pattern[ $i ][ 'token' ] === T_WHITESPACE ) {
277
+                        if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
278
+                            $found = $tokens[ $stackPtr ][ 'content' ] . $found;
279 279
                         }
280 280
 
281 281
                         // Only check the size of the whitespace if this is not
282 282
                         // the first token. We don't care about the size of
283 283
                         // leading whitespace, just that there is some.
284
-                        if ($i !== 0) {
285
-                            if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
284
+                        if ( $i !== 0 ) {
285
+                            if ( $tokens[ $stackPtr ][ 'content' ] !== $pattern[ $i ][ 'value' ] ) {
286 286
                                 $hasError = true;
287 287
                             }
288 288
                         }
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
                             true
298 298
                         );
299 299
 
300
-                        if ($prev === false
301
-                            || $tokens[$prev]['code'] !== $pattern[$i]['token']
300
+                        if ( $prev === false
301
+                            || $tokens[ $prev ][ 'code' ] !== $pattern[ $i ][ 'token' ]
302 302
                         ) {
303 303
                             return false;
304 304
                         }
@@ -306,23 +306,23 @@  discard block
 block discarded – undo
306 306
                         // If we skipped past some whitespace tokens, then add them
307 307
                         // to the found string.
308 308
                         $tokenContent = $phpcsFile->getTokensAsString(
309
-                            ($prev + 1),
310
-                            ($stackPtr - $prev - 1)
309
+                            ( $prev + 1 ),
310
+                            ( $stackPtr - $prev - 1 )
311 311
                         );
312 312
 
313
-                        $found = $tokens[$prev]['content'].$tokenContent.$found;
313
+                        $found = $tokens[ $prev ][ 'content' ] . $tokenContent . $found;
314 314
 
315
-                        if (isset($pattern[($i - 1)]) === true
316
-                            && $pattern[($i - 1)]['type'] === 'skip'
315
+                        if ( isset( $pattern[ ( $i - 1 ) ] ) === true
316
+                            && $pattern[ ( $i - 1 ) ][ 'type' ] === 'skip'
317 317
                         ) {
318 318
                             $stackPtr = $prev;
319 319
                         } else {
320
-                            $stackPtr = ($prev - 1);
320
+                            $stackPtr = ( $prev - 1 );
321 321
                         }
322 322
                     }//end if
323
-                } else if ($pattern[$i]['type'] === 'skip') {
323
+                } else if ( $pattern[ $i ][ 'type' ] === 'skip' ) {
324 324
                     // Skip to next piece of relevant code.
325
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
325
+                    if ( $pattern[ $i ][ 'to' ] === 'parenthesis_closer' ) {
326 326
                         $to = 'parenthesis_opener';
327 327
                     } else {
328 328
                         $to = 'scope_opener';
@@ -336,75 +336,75 @@  discard block
 block discarded – undo
336 336
                         true
337 337
                     );
338 338
 
339
-                    if ($next === false || isset($tokens[$next][$to]) === false) {
339
+                    if ( $next === false || isset( $tokens[ $next ][ $to ] ) === false ) {
340 340
                         // If there was not opener, then we must be
341 341
                         // using the wrong pattern.
342 342
                         return false;
343 343
                     }
344 344
 
345
-                    if ($to === 'parenthesis_opener') {
346
-                        $found = '{'.$found;
345
+                    if ( $to === 'parenthesis_opener' ) {
346
+                        $found = '{' . $found;
347 347
                     } else {
348
-                        $found = '('.$found;
348
+                        $found = '(' . $found;
349 349
                     }
350 350
 
351
-                    $found = '...'.$found;
351
+                    $found = '...' . $found;
352 352
 
353 353
                     // Skip to the opening token.
354
-                    $stackPtr = ($tokens[$next][$to] - 1);
355
-                } else if ($pattern[$i]['type'] === 'string') {
354
+                    $stackPtr = ( $tokens[ $next ][ $to ] - 1 );
355
+                } else if ( $pattern[ $i ][ 'type' ] === 'string' ) {
356 356
                     $found = 'abc';
357
-                } else if ($pattern[$i]['type'] === 'newline') {
358
-                    if ($this->ignoreComments === true
359
-                        && isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true
357
+                } else if ( $pattern[ $i ][ 'type' ] === 'newline' ) {
358
+                    if ( $this->ignoreComments === true
359
+                        && isset( Tokens::$commentTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true
360 360
                     ) {
361 361
                         $startComment = $phpcsFile->findPrevious(
362 362
                             Tokens::$commentTokens,
363
-                            ($stackPtr - 1),
363
+                            ( $stackPtr - 1 ),
364 364
                             null,
365 365
                             true
366 366
                         );
367 367
 
368
-                        if ($tokens[$startComment]['line'] !== $tokens[($startComment + 1)]['line']) {
368
+                        if ( $tokens[ $startComment ][ 'line' ] !== $tokens[ ( $startComment + 1 ) ][ 'line' ] ) {
369 369
                             $startComment++;
370 370
                         }
371 371
 
372 372
                         $tokenContent = $phpcsFile->getTokensAsString(
373 373
                             $startComment,
374
-                            ($stackPtr - $startComment + 1)
374
+                            ( $stackPtr - $startComment + 1 )
375 375
                         );
376 376
 
377
-                        $found    = $tokenContent.$found;
378
-                        $stackPtr = ($startComment - 1);
377
+                        $found    = $tokenContent . $found;
378
+                        $stackPtr = ( $startComment - 1 );
379 379
                     }
380 380
 
381
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
382
-                        if ($tokens[$stackPtr]['content'] !== $phpcsFile->eolChar) {
383
-                            $found = $tokens[$stackPtr]['content'].$found;
381
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
382
+                        if ( $tokens[ $stackPtr ][ 'content' ] !== $phpcsFile->eolChar ) {
383
+                            $found = $tokens[ $stackPtr ][ 'content' ] . $found;
384 384
 
385 385
                             // This may just be an indent that comes after a newline
386 386
                             // so check the token before to make sure. If it is a newline, we
387 387
                             // can ignore the error here.
388
-                            if (($tokens[($stackPtr - 1)]['content'] !== $phpcsFile->eolChar)
389
-                                && ($this->ignoreComments === true
390
-                                && isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === false)
388
+                            if ( ( $tokens[ ( $stackPtr - 1 ) ][ 'content' ] !== $phpcsFile->eolChar )
389
+                                && ( $this->ignoreComments === true
390
+                                && isset( Tokens::$commentTokens[ $tokens[ ( $stackPtr - 1 ) ][ 'code' ] ] ) === false )
391 391
                             ) {
392 392
                                 $hasError = true;
393 393
                             } else {
394 394
                                 $stackPtr--;
395 395
                             }
396 396
                         } else {
397
-                            $found = 'EOL'.$found;
397
+                            $found = 'EOL' . $found;
398 398
                         }
399 399
                     } else {
400
-                        $found    = $tokens[$stackPtr]['content'].$found;
400
+                        $found    = $tokens[ $stackPtr ][ 'content' ] . $found;
401 401
                         $hasError = true;
402 402
                     }//end if
403 403
 
404
-                    if ($hasError === false && $pattern[($i - 1)]['type'] !== 'newline') {
404
+                    if ( $hasError === false && $pattern[ ( $i - 1 ) ][ 'type' ] !== 'newline' ) {
405 405
                         // Make sure they only have 1 newline.
406
-                        $prev = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true);
407
-                        if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line']) {
406
+                        $prev = $phpcsFile->findPrevious( $ignoreTokens, ( $stackPtr - 1 ), null, true );
407
+                        if ( $prev !== false && $tokens[ $prev ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) {
408 408
                             $hasError = true;
409 409
                         }
410 410
                     }
@@ -414,38 +414,38 @@  discard block
 block discarded – undo
414 414
 
415 415
         $stackPtr          = $origStackPtr;
416 416
         $lastAddedStackPtr = null;
417
-        $patternLen        = count($pattern);
417
+        $patternLen        = count( $pattern );
418 418
 
419
-        for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
420
-            if (isset($tokens[$stackPtr]) === false) {
419
+        for ( $i = $patternInfo[ 'listen_pos' ]; $i < $patternLen; $i++ ) {
420
+            if ( isset( $tokens[ $stackPtr ] ) === false ) {
421 421
                 break;
422 422
             }
423 423
 
424
-            if ($pattern[$i]['type'] === 'token') {
425
-                if ($pattern[$i]['token'] === T_WHITESPACE) {
426
-                    if ($this->ignoreComments === true) {
424
+            if ( $pattern[ $i ][ 'type' ] === 'token' ) {
425
+                if ( $pattern[ $i ][ 'token' ] === T_WHITESPACE ) {
426
+                    if ( $this->ignoreComments === true ) {
427 427
                         // If we are ignoring comments, check to see if this current
428 428
                         // token is a comment. If so skip it.
429
-                        if (isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true) {
429
+                        if ( isset( Tokens::$commentTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true ) {
430 430
                             continue;
431 431
                         }
432 432
 
433 433
                         // If the next token is a comment, the we need to skip the
434 434
                         // current token as we should allow a space before a
435 435
                         // comment for readability.
436
-                        if (isset($tokens[($stackPtr + 1)]) === true
437
-                            && isset(Tokens::$commentTokens[$tokens[($stackPtr + 1)]['code']]) === true
436
+                        if ( isset( $tokens[ ( $stackPtr + 1 ) ] ) === true
437
+                            && isset( Tokens::$commentTokens[ $tokens[ ( $stackPtr + 1 ) ][ 'code' ] ] ) === true
438 438
                         ) {
439 439
                             continue;
440 440
                         }
441 441
                     }
442 442
 
443 443
                     $tokenContent = '';
444
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
445
-                        if (isset($pattern[($i + 1)]) === false) {
444
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
445
+                        if ( isset( $pattern[ ( $i + 1 ) ] ) === false ) {
446 446
                             // This is the last token in the pattern, so just compare
447 447
                             // the next token of content.
448
-                            $tokenContent = $tokens[$stackPtr]['content'];
448
+                            $tokenContent = $tokens[ $stackPtr ][ 'content' ];
449 449
                         } else {
450 450
                             // Get all the whitespace to the next token.
451 451
                             $next = $phpcsFile->findNext(
@@ -457,34 +457,34 @@  discard block
 block discarded – undo
457 457
 
458 458
                             $tokenContent = $phpcsFile->getTokensAsString(
459 459
                                 $stackPtr,
460
-                                ($next - $stackPtr)
460
+                                ( $next - $stackPtr )
461 461
                             );
462 462
 
463 463
                             $lastAddedStackPtr = $stackPtr;
464 464
                             $stackPtr          = $next;
465 465
                         }//end if
466 466
 
467
-                        if ($stackPtr !== $lastAddedStackPtr) {
467
+                        if ( $stackPtr !== $lastAddedStackPtr ) {
468 468
                             $found .= $tokenContent;
469 469
                         }
470 470
                     } else {
471
-                        if ($stackPtr !== $lastAddedStackPtr) {
472
-                            $found            .= $tokens[$stackPtr]['content'];
471
+                        if ( $stackPtr !== $lastAddedStackPtr ) {
472
+                            $found            .= $tokens[ $stackPtr ][ 'content' ];
473 473
                             $lastAddedStackPtr = $stackPtr;
474 474
                         }
475 475
                     }//end if
476 476
 
477
-                    if (isset($pattern[($i + 1)]) === true
478
-                        && $pattern[($i + 1)]['type'] === 'skip'
477
+                    if ( isset( $pattern[ ( $i + 1 ) ] ) === true
478
+                        && $pattern[ ( $i + 1 ) ][ 'type' ] === 'skip'
479 479
                     ) {
480 480
                         // The next token is a skip token, so we just need to make
481 481
                         // sure the whitespace we found has *at least* the
482 482
                         // whitespace required.
483
-                        if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
483
+                        if ( strpos( $tokenContent, $pattern[ $i ][ 'value' ] ) !== 0 ) {
484 484
                             $hasError = true;
485 485
                         }
486 486
                     } else {
487
-                        if ($tokenContent !== $pattern[$i]['value']) {
487
+                        if ( $tokenContent !== $pattern[ $i ][ 'value' ] ) {
488 488
                             $hasError = true;
489 489
                         }
490 490
                     }
@@ -499,18 +499,18 @@  discard block
 block discarded – undo
499 499
                         true
500 500
                     );
501 501
 
502
-                    if ($next === false
503
-                        || $tokens[$next]['code'] !== $pattern[$i]['token']
502
+                    if ( $next === false
503
+                        || $tokens[ $next ][ 'code' ] !== $pattern[ $i ][ 'token' ]
504 504
                     ) {
505 505
                         // The next important token did not match the pattern.
506 506
                         return false;
507 507
                     }
508 508
 
509
-                    if ($lastAddedStackPtr !== null) {
510
-                        if (($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET
511
-                            || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET)
512
-                            && isset($tokens[$next]['scope_condition']) === true
513
-                            && $tokens[$next]['scope_condition'] > $lastAddedStackPtr
509
+                    if ( $lastAddedStackPtr !== null ) {
510
+                        if ( ( $tokens[ $next ][ 'code' ] === T_OPEN_CURLY_BRACKET
511
+                            || $tokens[ $next ][ 'code' ] === T_CLOSE_CURLY_BRACKET )
512
+                            && isset( $tokens[ $next ][ 'scope_condition' ] ) === true
513
+                            && $tokens[ $next ][ 'scope_condition' ] > $lastAddedStackPtr
514 514
                         ) {
515 515
                             // This is a brace, but the owner of it is after the current
516 516
                             // token, which means it does not belong to any token in
@@ -518,10 +518,10 @@  discard block
 block discarded – undo
518 518
                             return false;
519 519
                         }
520 520
 
521
-                        if (($tokens[$next]['code'] === T_OPEN_PARENTHESIS
522
-                            || $tokens[$next]['code'] === T_CLOSE_PARENTHESIS)
523
-                            && isset($tokens[$next]['parenthesis_owner']) === true
524
-                            && $tokens[$next]['parenthesis_owner'] > $lastAddedStackPtr
521
+                        if ( ( $tokens[ $next ][ 'code' ] === T_OPEN_PARENTHESIS
522
+                            || $tokens[ $next ][ 'code' ] === T_CLOSE_PARENTHESIS )
523
+                            && isset( $tokens[ $next ][ 'parenthesis_owner' ] ) === true
524
+                            && $tokens[ $next ][ 'parenthesis_owner' ] > $lastAddedStackPtr
525 525
                         ) {
526 526
                             // This is a bracket, but the owner of it is after the current
527 527
                             // token, which means it does not belong to any token in
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 
533 533
                     // If we skipped past some whitespace tokens, then add them
534 534
                     // to the found string.
535
-                    if (($next - $stackPtr) > 0) {
535
+                    if ( ( $next - $stackPtr ) > 0 ) {
536 536
                         $hasComment = false;
537
-                        for ($j = $stackPtr; $j < $next; $j++) {
538
-                            $found .= $tokens[$j]['content'];
539
-                            if (isset(Tokens::$commentTokens[$tokens[$j]['code']]) === true) {
537
+                        for ( $j = $stackPtr; $j < $next; $j++ ) {
538
+                            $found .= $tokens[ $j ][ 'content' ];
539
+                            if ( isset( Tokens::$commentTokens[ $tokens[ $j ][ 'code' ] ] ) === true ) {
540 540
                                 $hasComment = true;
541 541
                             }
542 542
                         }
@@ -545,9 +545,9 @@  discard block
 block discarded – undo
545 545
                         // whitespace or comment is not allowed. If we are
546 546
                         // ignoring comments, there needs to be at least one
547 547
                         // comment for this to be allowed.
548
-                        if ($this->ignoreComments === false
549
-                            || ($this->ignoreComments === true
550
-                            && $hasComment === false)
548
+                        if ( $this->ignoreComments === false
549
+                            || ( $this->ignoreComments === true
550
+                            && $hasComment === false )
551 551
                         ) {
552 552
                             $hasError = true;
553 553
                         }
@@ -555,32 +555,32 @@  discard block
 block discarded – undo
555 555
                         // Even when ignoring comments, we are not allowed to include
556 556
                         // newlines without the pattern specifying them, so
557 557
                         // everything should be on the same line.
558
-                        if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
558
+                        if ( $tokens[ $next ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) {
559 559
                             $hasError = true;
560 560
                         }
561 561
                     }//end if
562 562
 
563
-                    if ($next !== $lastAddedStackPtr) {
564
-                        $found            .= $tokens[$next]['content'];
563
+                    if ( $next !== $lastAddedStackPtr ) {
564
+                        $found            .= $tokens[ $next ][ 'content' ];
565 565
                         $lastAddedStackPtr = $next;
566 566
                     }
567 567
 
568
-                    if (isset($pattern[($i + 1)]) === true
569
-                        && $pattern[($i + 1)]['type'] === 'skip'
568
+                    if ( isset( $pattern[ ( $i + 1 ) ] ) === true
569
+                        && $pattern[ ( $i + 1 ) ][ 'type' ] === 'skip'
570 570
                     ) {
571 571
                         $stackPtr = $next;
572 572
                     } else {
573
-                        $stackPtr = ($next + 1);
573
+                        $stackPtr = ( $next + 1 );
574 574
                     }
575 575
                 }//end if
576
-            } else if ($pattern[$i]['type'] === 'skip') {
577
-                if ($pattern[$i]['to'] === 'unknown') {
576
+            } else if ( $pattern[ $i ][ 'type' ] === 'skip' ) {
577
+                if ( $pattern[ $i ][ 'to' ] === 'unknown' ) {
578 578
                     $next = $phpcsFile->findNext(
579
-                        $pattern[($i + 1)]['token'],
579
+                        $pattern[ ( $i + 1 ) ][ 'token' ],
580 580
                         $stackPtr
581 581
                     );
582 582
 
583
-                    if ($next === false) {
583
+                    if ( $next === false ) {
584 584
                         // Couldn't find the next token, so we must
585 585
                         // be using the wrong pattern.
586 586
                         return false;
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
                         $stackPtr
596 596
                     );
597 597
 
598
-                    if ($next === false
599
-                        || isset($tokens[$next][$pattern[$i]['to']]) === false
598
+                    if ( $next === false
599
+                        || isset( $tokens[ $next ][ $pattern[ $i ][ 'to' ] ] ) === false
600 600
                     ) {
601 601
                         // If there was not opener, then we must
602 602
                         // be using the wrong pattern.
@@ -604,50 +604,50 @@  discard block
 block discarded – undo
604 604
                     }
605 605
 
606 606
                     $found .= '...';
607
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
607
+                    if ( $pattern[ $i ][ 'to' ] === 'parenthesis_closer' ) {
608 608
                         $found .= ')';
609 609
                     } else {
610 610
                         $found .= '}';
611 611
                     }
612 612
 
613 613
                     // Skip to the closing token.
614
-                    $stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
614
+                    $stackPtr = ( $tokens[ $next ][ $pattern[ $i ][ 'to' ] ] + 1 );
615 615
                 }//end if
616
-            } else if ($pattern[$i]['type'] === 'string') {
617
-                if ($tokens[$stackPtr]['code'] !== T_STRING) {
616
+            } else if ( $pattern[ $i ][ 'type' ] === 'string' ) {
617
+                if ( $tokens[ $stackPtr ][ 'code' ] !== T_STRING ) {
618 618
                     $hasError = true;
619 619
                 }
620 620
 
621
-                if ($stackPtr !== $lastAddedStackPtr) {
621
+                if ( $stackPtr !== $lastAddedStackPtr ) {
622 622
                     $found            .= 'abc';
623 623
                     $lastAddedStackPtr = $stackPtr;
624 624
                 }
625 625
 
626 626
                 $stackPtr++;
627
-            } else if ($pattern[$i]['type'] === 'newline') {
627
+            } else if ( $pattern[ $i ][ 'type' ] === 'newline' ) {
628 628
                 // Find the next token that contains a newline character.
629 629
                 $newline = 0;
630
-                for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
631
-                    if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
630
+                for ( $j = $stackPtr; $j < $phpcsFile->numTokens; $j++ ) {
631
+                    if ( strpos( $tokens[ $j ][ 'content' ], $phpcsFile->eolChar ) !== false ) {
632 632
                         $newline = $j;
633 633
                         break;
634 634
                     }
635 635
                 }
636 636
 
637
-                if ($newline === 0) {
637
+                if ( $newline === 0 ) {
638 638
                     // We didn't find a newline character in the rest of the file.
639
-                    $next     = ($phpcsFile->numTokens - 1);
639
+                    $next     = ( $phpcsFile->numTokens - 1 );
640 640
                     $hasError = true;
641 641
                 } else {
642
-                    if ($this->ignoreComments === false) {
642
+                    if ( $this->ignoreComments === false ) {
643 643
                         // The newline character cannot be part of a comment.
644
-                        if (isset(Tokens::$commentTokens[$tokens[$newline]['code']]) === true) {
644
+                        if ( isset( Tokens::$commentTokens[ $tokens[ $newline ][ 'code' ] ] ) === true ) {
645 645
                             $hasError = true;
646 646
                         }
647 647
                     }
648 648
 
649
-                    if ($newline === $stackPtr) {
650
-                        $next = ($stackPtr + 1);
649
+                    if ( $newline === $stackPtr ) {
650
+                        $next = ( $stackPtr + 1 );
651 651
                     } else {
652 652
                         // Check that there were no significant tokens that we
653 653
                         // skipped over to find our newline character.
@@ -658,31 +658,31 @@  discard block
 block discarded – undo
658 658
                             true
659 659
                         );
660 660
 
661
-                        if ($next < $newline) {
661
+                        if ( $next < $newline ) {
662 662
                             // We skipped a non-ignored token.
663 663
                             $hasError = true;
664 664
                         } else {
665
-                            $next = ($newline + 1);
665
+                            $next = ( $newline + 1 );
666 666
                         }
667 667
                     }
668 668
                 }//end if
669 669
 
670
-                if ($stackPtr !== $lastAddedStackPtr) {
670
+                if ( $stackPtr !== $lastAddedStackPtr ) {
671 671
                     $found .= $phpcsFile->getTokensAsString(
672 672
                         $stackPtr,
673
-                        ($next - $stackPtr)
673
+                        ( $next - $stackPtr )
674 674
                     );
675 675
 
676
-                    $lastAddedStackPtr = ($next - 1);
676
+                    $lastAddedStackPtr = ( $next - 1 );
677 677
                 }
678 678
 
679 679
                 $stackPtr = $next;
680 680
             }//end if
681 681
         }//end for
682 682
 
683
-        if ($hasError === true) {
684
-            $error = $this->prepareError($found, $patternCode);
685
-            $errors[$origStackPtr] = $error;
683
+        if ( $hasError === true ) {
684
+            $error = $this->prepareError( $found, $patternCode );
685
+            $errors[ $origStackPtr ] = $error;
686 686
         }
687 687
 
688 688
         return $errors;
@@ -698,14 +698,14 @@  discard block
 block discarded – undo
698 698
      *
699 699
      * @return string The error message.
700 700
      */
701
-    protected function prepareError($found, $patternCode)
701
+    protected function prepareError( $found, $patternCode )
702 702
     {
703
-        $found    = str_replace("\r\n", '\n', $found);
704
-        $found    = str_replace("\n", '\n', $found);
705
-        $found    = str_replace("\r", '\n', $found);
706
-        $found    = str_replace("\t", '\t', $found);
707
-        $found    = str_replace('EOL', '\n', $found);
708
-        $expected = str_replace('EOL', '\n', $patternCode);
703
+        $found    = str_replace( "\r\n", '\n', $found );
704
+        $found    = str_replace( "\n", '\n', $found );
705
+        $found    = str_replace( "\r", '\n', $found );
706
+        $found    = str_replace( "\t", '\t', $found );
707
+        $found    = str_replace( 'EOL', '\n', $found );
708
+        $expected = str_replace( 'EOL', '\n', $patternCode );
709 709
 
710 710
         $error = "Expected \"$expected\"; found \"$found\"";
711 711
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
      */
735 735
     protected function registerSupplementary()
736 736
     {
737
-        return [];
737
+        return [ ];
738 738
 
739 739
     }//end registerSupplementary()
740 740
 
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
       * @return void
751 751
       * @see    registerSupplementary()
752 752
       */
753
-    protected function processSupplementary(File $phpcsFile, $stackPtr)
753
+    protected function processSupplementary( File $phpcsFile, $stackPtr )
754 754
     {
755 755
 
756 756
     }//end processSupplementary()
@@ -765,70 +765,70 @@  discard block
 block discarded – undo
765 765
      * @see    createSkipPattern()
766 766
      * @see    createTokenPattern()
767 767
      */
768
-    private function parse($pattern)
768
+    private function parse( $pattern )
769 769
     {
770
-        $patterns   = [];
771
-        $length     = strlen($pattern);
770
+        $patterns   = [ ];
771
+        $length     = strlen( $pattern );
772 772
         $lastToken  = 0;
773 773
         $firstToken = 0;
774 774
 
775
-        for ($i = 0; $i < $length; $i++) {
775
+        for ( $i = 0; $i < $length; $i++ ) {
776 776
             $specialPattern = false;
777
-            $isLastChar     = ($i === ($length - 1));
777
+            $isLastChar     = ( $i === ( $length - 1 ) );
778 778
             $oldFirstToken  = $firstToken;
779 779
 
780
-            if (substr($pattern, $i, 3) === '...') {
780
+            if ( substr( $pattern, $i, 3 ) === '...' ) {
781 781
                 // It's a skip pattern. The skip pattern requires the
782 782
                 // content of the token in the "from" position and the token
783 783
                 // to skip to.
784
-                $specialPattern = $this->createSkipPattern($pattern, ($i - 1));
785
-                $lastToken      = ($i - $firstToken);
786
-                $firstToken     = ($i + 3);
784
+                $specialPattern = $this->createSkipPattern( $pattern, ( $i - 1 ) );
785
+                $lastToken      = ( $i - $firstToken );
786
+                $firstToken     = ( $i + 3 );
787 787
                 $i += 2;
788 788
 
789
-                if ($specialPattern['to'] !== 'unknown') {
789
+                if ( $specialPattern[ 'to' ] !== 'unknown' ) {
790 790
                     $firstToken++;
791 791
                 }
792
-            } else if (substr($pattern, $i, 3) === 'abc') {
793
-                $specialPattern = ['type' => 'string'];
794
-                $lastToken      = ($i - $firstToken);
795
-                $firstToken     = ($i + 3);
792
+            } else if ( substr( $pattern, $i, 3 ) === 'abc' ) {
793
+                $specialPattern = [ 'type' => 'string' ];
794
+                $lastToken      = ( $i - $firstToken );
795
+                $firstToken     = ( $i + 3 );
796 796
                 $i += 2;
797
-            } else if (substr($pattern, $i, 3) === 'EOL') {
798
-                $specialPattern = ['type' => 'newline'];
799
-                $lastToken      = ($i - $firstToken);
800
-                $firstToken     = ($i + 3);
797
+            } else if ( substr( $pattern, $i, 3 ) === 'EOL' ) {
798
+                $specialPattern = [ 'type' => 'newline' ];
799
+                $lastToken      = ( $i - $firstToken );
800
+                $firstToken     = ( $i + 3 );
801 801
                 $i += 2;
802 802
             }//end if
803 803
 
804
-            if ($specialPattern !== false || $isLastChar === true) {
804
+            if ( $specialPattern !== false || $isLastChar === true ) {
805 805
                 // If we are at the end of the string, don't worry about a limit.
806
-                if ($isLastChar === true) {
806
+                if ( $isLastChar === true ) {
807 807
                     // Get the string from the end of the last skip pattern, if any,
808 808
                     // to the end of the pattern string.
809
-                    $str = substr($pattern, $oldFirstToken);
809
+                    $str = substr( $pattern, $oldFirstToken );
810 810
                 } else {
811 811
                     // Get the string from the end of the last special pattern,
812 812
                     // if any, to the start of this special pattern.
813
-                    if ($lastToken === 0) {
813
+                    if ( $lastToken === 0 ) {
814 814
                         // Note that if the last special token was zero characters ago,
815 815
                         // there will be nothing to process so we can skip this bit.
816 816
                         // This happens if you have something like: EOL... in your pattern.
817 817
                         $str = '';
818 818
                     } else {
819
-                        $str = substr($pattern, $oldFirstToken, $lastToken);
819
+                        $str = substr( $pattern, $oldFirstToken, $lastToken );
820 820
                     }
821 821
                 }
822 822
 
823
-                if ($str !== '') {
824
-                    $tokenPatterns = $this->createTokenPattern($str);
825
-                    foreach ($tokenPatterns as $tokenPattern) {
826
-                        $patterns[] = $tokenPattern;
823
+                if ( $str !== '' ) {
824
+                    $tokenPatterns = $this->createTokenPattern( $str );
825
+                    foreach ( $tokenPatterns as $tokenPattern ) {
826
+                        $patterns[ ] = $tokenPattern;
827 827
                     }
828 828
                 }
829 829
 
830 830
                 // Make sure we don't skip the last token.
831
-                if ($isLastChar === false && $i === ($length - 1)) {
831
+                if ( $isLastChar === false && $i === ( $length - 1 ) ) {
832 832
                     $i--;
833 833
                 }
834 834
             }//end if
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
             // Add the skip pattern *after* we have processed
837 837
             // all the tokens from the end of the last skip pattern
838 838
             // to the start of this skip pattern.
839
-            if ($specialPattern !== false) {
840
-                $patterns[] = $specialPattern;
839
+            if ( $specialPattern !== false ) {
840
+                $patterns[ ] = $specialPattern;
841 841
             }
842 842
         }//end for
843 843
 
@@ -856,24 +856,24 @@  discard block
 block discarded – undo
856 856
      * @see    createTokenPattern()
857 857
      * @see    parse()
858 858
      */
859
-    private function createSkipPattern($pattern, $from)
859
+    private function createSkipPattern( $pattern, $from )
860 860
     {
861
-        $skip = ['type' => 'skip'];
861
+        $skip = [ 'type' => 'skip' ];
862 862
 
863 863
         $nestedParenthesis = 0;
864 864
         $nestedBraces      = 0;
865
-        for ($start = $from; $start >= 0; $start--) {
866
-            switch ($pattern[$start]) {
865
+        for ( $start = $from; $start >= 0; $start-- ) {
866
+            switch ( $pattern[ $start ] ) {
867 867
             case '(':
868
-                if ($nestedParenthesis === 0) {
869
-                    $skip['to'] = 'parenthesis_closer';
868
+                if ( $nestedParenthesis === 0 ) {
869
+                    $skip[ 'to' ] = 'parenthesis_closer';
870 870
                 }
871 871
 
872 872
                 $nestedParenthesis--;
873 873
                 break;
874 874
             case '{':
875
-                if ($nestedBraces === 0) {
876
-                    $skip['to'] = 'scope_closer';
875
+                if ( $nestedBraces === 0 ) {
876
+                    $skip[ 'to' ] = 'scope_closer';
877 877
                 }
878 878
 
879 879
                 $nestedBraces--;
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
                 break;
887 887
             }//end switch
888 888
 
889
-            if (isset($skip['to']) === true) {
889
+            if ( isset( $skip[ 'to' ] ) === true ) {
890 890
                 break;
891 891
             }
892 892
         }//end for
893 893
 
894
-        if (isset($skip['to']) === false) {
895
-            $skip['to'] = 'unknown';
894
+        if ( isset( $skip[ 'to' ] ) === false ) {
895
+            $skip[ 'to' ] = 'unknown';
896 896
         }
897 897
 
898 898
         return $skip;
@@ -909,22 +909,22 @@  discard block
 block discarded – undo
909 909
      * @see    createSkipPattern()
910 910
      * @see    parse()
911 911
      */
912
-    private function createTokenPattern($str)
912
+    private function createTokenPattern( $str )
913 913
     {
914 914
         // Don't add a space after the closing php tag as it will add a new
915 915
         // whitespace token.
916
-        $tokenizer = new PHP('<?php '.$str.'?>', null);
916
+        $tokenizer = new PHP( '<?php ' . $str . '?>', null );
917 917
 
918 918
         // Remove the <?php tag from the front and the end php tag from the back.
919 919
         $tokens = $tokenizer->getTokens();
920
-        $tokens = array_slice($tokens, 1, (count($tokens) - 2));
920
+        $tokens = array_slice( $tokens, 1, ( count( $tokens ) - 2 ) );
921 921
 
922
-        $patterns = [];
923
-        foreach ($tokens as $patternInfo) {
924
-            $patterns[] = [
922
+        $patterns = [ ];
923
+        foreach ( $tokens as $patternInfo ) {
924
+            $patterns[ ] = [
925 925
                 'type'  => 'token',
926
-                'token' => $patternInfo['code'],
927
-                'value' => $patternInfo['content'],
926
+                'token' => $patternInfo[ 'code' ],
927
+                'value' => $patternInfo[ 'content' ],
928 928
             ];
929 929
         }
930 930
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@  discard block
 block discarded – undo
14 14
 use PHP_CodeSniffer\Tokenizers\PHP;
15 15
 use PHP_CodeSniffer\Exceptions\RuntimeException;
16 16
 
17
-abstract class AbstractPatternSniff implements Sniff
18
-{
17
+abstract class AbstractPatternSniff implements Sniff {
19 18
 
20 19
     /**
21 20
      * If true, comments will be ignored if they are found in the code.
@@ -60,8 +59,7 @@  discard block
 block discarded – undo
60 59
      *
61 60
      * @param boolean $ignoreComments If true, comments will be ignored.
62 61
      */
63
-    public function __construct($ignoreComments=null)
64
-    {
62
+    public function __construct($ignoreComments=null) {
65 63
         // This is here for backwards compatibility.
66 64
         if ($ignoreComments !== null) {
67 65
             $this->ignoreComments = $ignoreComments;
@@ -81,8 +79,7 @@  discard block
 block discarded – undo
81 79
      * @return int[]
82 80
      * @see    process()
83 81
      */
84
-    final public function register()
85
-    {
82
+    final public function register() {
86 83
         $listenTypes = [];
87 84
         $patterns    = $this->getPatterns();
88 85
 
@@ -129,8 +126,7 @@  discard block
 block discarded – undo
129 126
      *
130 127
      * @return array<int, int>
131 128
      */
132
-    private function getPatternTokenTypes($pattern)
133
-    {
129
+    private function getPatternTokenTypes($pattern) {
134 130
         $tokenTypes = [];
135 131
         foreach ($pattern as $pos => $patternInfo) {
136 132
             if ($patternInfo['type'] === 'token') {
@@ -155,8 +151,7 @@  discard block
 block discarded – undo
155 151
      *             as the listener.
156 152
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
157 153
      */
158
-    private function getListenerTokenPos($pattern)
159
-    {
154
+    private function getListenerTokenPos($pattern) {
160 155
         $tokenTypes = $this->getPatternTokenTypes($pattern);
161 156
         $tokenCodes = array_keys($tokenTypes);
162 157
         $token      = Tokens::getHighestWeightedToken($tokenCodes);
@@ -184,8 +179,7 @@  discard block
 block discarded – undo
184 179
      * @return void
185 180
      * @see    register()
186 181
      */
187
-    final public function process(File $phpcsFile, $stackPtr)
188
-    {
182
+    final public function process(File $phpcsFile, $stackPtr) {
189 183
         $file = $phpcsFile->getFilename();
190 184
         if ($this->currFile !== $file) {
191 185
             // We have changed files, so clean up.
@@ -252,8 +246,7 @@  discard block
 block discarded – undo
252 246
      *
253 247
      * @return array
254 248
      */
255
-    protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
256
-    {
249
+    protected function processPattern($patternInfo, File $phpcsFile, $stackPtr) {
257 250
         $tokens      = $phpcsFile->getTokens();
258 251
         $pattern     = $patternInfo['pattern'];
259 252
         $patternCode = $patternInfo['pattern_code'];
@@ -698,8 +691,7 @@  discard block
 block discarded – undo
698 691
      *
699 692
      * @return string The error message.
700 693
      */
701
-    protected function prepareError($found, $patternCode)
702
-    {
694
+    protected function prepareError($found, $patternCode) {
703 695
         $found    = str_replace("\r\n", '\n', $found);
704 696
         $found    = str_replace("\n", '\n', $found);
705 697
         $found    = str_replace("\r", '\n', $found);
@@ -732,8 +724,7 @@  discard block
 block discarded – undo
732 724
      * @return int[]
733 725
      * @see    processSupplementary()
734 726
      */
735
-    protected function registerSupplementary()
736
-    {
727
+    protected function registerSupplementary() {
737 728
         return [];
738 729
 
739 730
     }//end registerSupplementary()
@@ -750,8 +741,7 @@  discard block
 block discarded – undo
750 741
       * @return void
751 742
       * @see    registerSupplementary()
752 743
       */
753
-    protected function processSupplementary(File $phpcsFile, $stackPtr)
754
-    {
744
+    protected function processSupplementary(File $phpcsFile, $stackPtr) {
755 745
 
756 746
     }//end processSupplementary()
757 747
 
@@ -765,8 +755,7 @@  discard block
 block discarded – undo
765 755
      * @see    createSkipPattern()
766 756
      * @see    createTokenPattern()
767 757
      */
768
-    private function parse($pattern)
769
-    {
758
+    private function parse($pattern) {
770 759
         $patterns   = [];
771 760
         $length     = strlen($pattern);
772 761
         $lastToken  = 0;
@@ -856,8 +845,7 @@  discard block
 block discarded – undo
856 845
      * @see    createTokenPattern()
857 846
      * @see    parse()
858 847
      */
859
-    private function createSkipPattern($pattern, $from)
860
-    {
848
+    private function createSkipPattern($pattern, $from) {
861 849
         $skip = ['type' => 'skip'];
862 850
 
863 851
         $nestedParenthesis = 0;
@@ -909,8 +897,7 @@  discard block
 block discarded – undo
909 897
      * @see    createSkipPattern()
910 898
      * @see    parse()
911 899
      */
912
-    private function createTokenPattern($str)
913
-    {
900
+    private function createTokenPattern($str) {
914 901
         // Don't add a space after the closing php tag as it will add a new
915 902
         // whitespace token.
916 903
         $tokenizer = new PHP('<?php '.$str.'?>', null);
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php 3 patches
Indentation   +213 added lines, -213 removed lines patch added patch discarded remove patch
@@ -16,219 +16,219 @@
 block discarded – undo
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
-    final public function register()
25
-    {
26
-        return [
27
-            T_ARRAY,
28
-            T_OPEN_SHORT_ARRAY,
29
-        ];
30
-
31
-    }//end register()
32
-
33
-
34
-    /**
35
-     * Processes this sniff, when one of its tokens is encountered.
36
-     *
37
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
38
-     * @param int                         $stackPtr  The position of the current token in
39
-     *                                               the stack passed in $tokens.
40
-     *
41
-     * @return void
42
-     */
43
-    public function process(File $phpcsFile, $stackPtr)
44
-    {
45
-        $tokens = $phpcsFile->getTokens();
46
-
47
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
48
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no');
49
-
50
-            $arrayStart = $tokens[$stackPtr]['parenthesis_opener'];
51
-            if (isset($tokens[$arrayStart]['parenthesis_closer']) === false) {
52
-                // Incomplete array.
53
-                return;
54
-            }
55
-
56
-            $arrayEnd = $tokens[$arrayStart]['parenthesis_closer'];
57
-        } else {
58
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
59
-            $arrayStart = $stackPtr;
60
-            $arrayEnd   = $tokens[$stackPtr]['bracket_closer'];
61
-        }
62
-
63
-        $lastContent = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrayEnd - 1), null, true);
64
-        if ($tokens[$lastContent]['code'] === T_COMMA) {
65
-            // Last array item ends with a comma.
66
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'yes');
67
-            $lastArrayToken = $lastContent;
68
-        } else {
69
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'no');
70
-            $lastArrayToken = $arrayEnd;
71
-        }
72
-
73
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
74
-            $lastToken = $tokens[$stackPtr]['parenthesis_opener'];
75
-        } else {
76
-            $lastToken = $stackPtr;
77
-        }
78
-
79
-        $keyUsed = false;
80
-        $indices = [];
81
-
82
-        for ($checkToken = ($stackPtr + 1); $checkToken <= $lastArrayToken; $checkToken++) {
83
-            // Skip bracketed statements, like function calls.
84
-            if ($tokens[$checkToken]['code'] === T_OPEN_PARENTHESIS
85
-                && (isset($tokens[$checkToken]['parenthesis_owner']) === false
86
-                || $tokens[$checkToken]['parenthesis_owner'] !== $stackPtr)
87
-            ) {
88
-                $checkToken = $tokens[$checkToken]['parenthesis_closer'];
89
-                continue;
90
-            }
91
-
92
-            if ($tokens[$checkToken]['code'] === T_ARRAY
93
-                || $tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY
94
-                || $tokens[$checkToken]['code'] === T_CLOSURE
95
-            ) {
96
-                // Let subsequent calls of this test handle nested arrays.
97
-                if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {
98
-                    $indices[] = ['value_start' => $checkToken];
99
-                    $lastToken = $checkToken;
100
-                }
101
-
102
-                if ($tokens[$checkToken]['code'] === T_ARRAY) {
103
-                    $checkToken = $tokens[$tokens[$checkToken]['parenthesis_opener']]['parenthesis_closer'];
104
-                } else if ($tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY) {
105
-                    $checkToken = $tokens[$checkToken]['bracket_closer'];
106
-                } else {
107
-                    // T_CLOSURE.
108
-                    $checkToken = $tokens[$checkToken]['scope_closer'];
109
-                }
110
-
111
-                $checkToken = $phpcsFile->findNext(T_WHITESPACE, ($checkToken + 1), null, true);
112
-                $lastToken  = $checkToken;
113
-                if ($tokens[$checkToken]['code'] !== T_COMMA) {
114
-                    $checkToken--;
115
-                }
116
-
117
-                continue;
118
-            }//end if
119
-
120
-            if ($tokens[$checkToken]['code'] !== T_DOUBLE_ARROW
121
-                && $tokens[$checkToken]['code'] !== T_COMMA
122
-                && $checkToken !== $arrayEnd
123
-            ) {
124
-                continue;
125
-            }
126
-
127
-            if ($tokens[$checkToken]['code'] === T_COMMA
128
-                || $checkToken === $arrayEnd
129
-            ) {
130
-                $stackPtrCount = 0;
131
-                if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
132
-                    $stackPtrCount = count($tokens[$stackPtr]['nested_parenthesis']);
133
-                }
134
-
135
-                $commaCount = 0;
136
-                if (isset($tokens[$checkToken]['nested_parenthesis']) === true) {
137
-                    $commaCount = count($tokens[$checkToken]['nested_parenthesis']);
138
-                    if ($tokens[$stackPtr]['code'] === T_ARRAY) {
139
-                        // Remove parenthesis that are used to define the array.
140
-                        $commaCount--;
141
-                    }
142
-                }
143
-
144
-                if ($commaCount > $stackPtrCount) {
145
-                    // This comma is inside more parenthesis than the ARRAY keyword,
146
-                    // so it is actually a comma used to do things like
147
-                    // separate arguments in a function call.
148
-                    continue;
149
-                }
150
-
151
-                if ($keyUsed === false) {
152
-                    $valueContent = $phpcsFile->findNext(
153
-                        Tokens::$emptyTokens,
154
-                        ($lastToken + 1),
155
-                        $checkToken,
156
-                        true
157
-                    );
158
-
159
-                    $indices[] = ['value_start' => $valueContent];
160
-                }
161
-
162
-                $lastToken = $checkToken;
163
-                $keyUsed   = false;
164
-                continue;
165
-            }//end if
166
-
167
-            if ($tokens[$checkToken]['code'] === T_DOUBLE_ARROW) {
168
-                $keyUsed = true;
169
-
170
-                // Find the start of index that uses this double arrow.
171
-                $indexEnd   = $phpcsFile->findPrevious(T_WHITESPACE, ($checkToken - 1), $arrayStart, true);
172
-                $indexStart = $phpcsFile->findStartOfStatement($indexEnd);
173
-
174
-                // Find the value of this index.
175
-                $nextContent = $phpcsFile->findNext(
176
-                    Tokens::$emptyTokens,
177
-                    ($checkToken + 1),
178
-                    $arrayEnd,
179
-                    true
180
-                );
181
-
182
-                $indices[] = [
183
-                    'index_start' => $indexStart,
184
-                    'index_end'   => $indexEnd,
185
-                    'arrow'       => $checkToken,
186
-                    'value_start' => $nextContent,
187
-                ];
188
-
189
-                $lastToken = $checkToken;
190
-            }//end if
191
-        }//end for
192
-
193
-        if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) {
194
-            $this->processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
195
-        } else {
196
-            $this->processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
197
-        }
198
-
199
-    }//end process()
200
-
201
-
202
-    /**
203
-     * Processes a single-line array definition.
204
-     *
205
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile  The current file being checked.
206
-     * @param int                         $stackPtr   The position of the current token
207
-     *                                                in the stack passed in $tokens.
208
-     * @param int                         $arrayStart The token that starts the array definition.
209
-     * @param int                         $arrayEnd   The token that ends the array definition.
210
-     * @param array                       $indices    An array of token positions for the array keys,
211
-     *                                                double arrows, and values.
212
-     *
213
-     * @return void
214
-     */
215
-    abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
216
-
217
-
218
-    /**
219
-     * Processes a multi-line array definition.
220
-     *
221
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile  The current file being checked.
222
-     * @param int                         $stackPtr   The position of the current token
223
-     *                                                in the stack passed in $tokens.
224
-     * @param int                         $arrayStart The token that starts the array definition.
225
-     * @param int                         $arrayEnd   The token that ends the array definition.
226
-     * @param array                       $indices    An array of token positions for the array keys,
227
-     *                                                double arrows, and values.
228
-     *
229
-     * @return void
230
-     */
231
-    abstract protected function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	final public function register()
25
+	{
26
+		return [
27
+			T_ARRAY,
28
+			T_OPEN_SHORT_ARRAY,
29
+		];
30
+
31
+	}//end register()
32
+
33
+
34
+	/**
35
+	 * Processes this sniff, when one of its tokens is encountered.
36
+	 *
37
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
38
+	 * @param int                         $stackPtr  The position of the current token in
39
+	 *                                               the stack passed in $tokens.
40
+	 *
41
+	 * @return void
42
+	 */
43
+	public function process(File $phpcsFile, $stackPtr)
44
+	{
45
+		$tokens = $phpcsFile->getTokens();
46
+
47
+		if ($tokens[$stackPtr]['code'] === T_ARRAY) {
48
+			$phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no');
49
+
50
+			$arrayStart = $tokens[$stackPtr]['parenthesis_opener'];
51
+			if (isset($tokens[$arrayStart]['parenthesis_closer']) === false) {
52
+				// Incomplete array.
53
+				return;
54
+			}
55
+
56
+			$arrayEnd = $tokens[$arrayStart]['parenthesis_closer'];
57
+		} else {
58
+			$phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
59
+			$arrayStart = $stackPtr;
60
+			$arrayEnd   = $tokens[$stackPtr]['bracket_closer'];
61
+		}
62
+
63
+		$lastContent = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrayEnd - 1), null, true);
64
+		if ($tokens[$lastContent]['code'] === T_COMMA) {
65
+			// Last array item ends with a comma.
66
+			$phpcsFile->recordMetric($stackPtr, 'Array end comma', 'yes');
67
+			$lastArrayToken = $lastContent;
68
+		} else {
69
+			$phpcsFile->recordMetric($stackPtr, 'Array end comma', 'no');
70
+			$lastArrayToken = $arrayEnd;
71
+		}
72
+
73
+		if ($tokens[$stackPtr]['code'] === T_ARRAY) {
74
+			$lastToken = $tokens[$stackPtr]['parenthesis_opener'];
75
+		} else {
76
+			$lastToken = $stackPtr;
77
+		}
78
+
79
+		$keyUsed = false;
80
+		$indices = [];
81
+
82
+		for ($checkToken = ($stackPtr + 1); $checkToken <= $lastArrayToken; $checkToken++) {
83
+			// Skip bracketed statements, like function calls.
84
+			if ($tokens[$checkToken]['code'] === T_OPEN_PARENTHESIS
85
+				&& (isset($tokens[$checkToken]['parenthesis_owner']) === false
86
+				|| $tokens[$checkToken]['parenthesis_owner'] !== $stackPtr)
87
+			) {
88
+				$checkToken = $tokens[$checkToken]['parenthesis_closer'];
89
+				continue;
90
+			}
91
+
92
+			if ($tokens[$checkToken]['code'] === T_ARRAY
93
+				|| $tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY
94
+				|| $tokens[$checkToken]['code'] === T_CLOSURE
95
+			) {
96
+				// Let subsequent calls of this test handle nested arrays.
97
+				if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {
98
+					$indices[] = ['value_start' => $checkToken];
99
+					$lastToken = $checkToken;
100
+				}
101
+
102
+				if ($tokens[$checkToken]['code'] === T_ARRAY) {
103
+					$checkToken = $tokens[$tokens[$checkToken]['parenthesis_opener']]['parenthesis_closer'];
104
+				} else if ($tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY) {
105
+					$checkToken = $tokens[$checkToken]['bracket_closer'];
106
+				} else {
107
+					// T_CLOSURE.
108
+					$checkToken = $tokens[$checkToken]['scope_closer'];
109
+				}
110
+
111
+				$checkToken = $phpcsFile->findNext(T_WHITESPACE, ($checkToken + 1), null, true);
112
+				$lastToken  = $checkToken;
113
+				if ($tokens[$checkToken]['code'] !== T_COMMA) {
114
+					$checkToken--;
115
+				}
116
+
117
+				continue;
118
+			}//end if
119
+
120
+			if ($tokens[$checkToken]['code'] !== T_DOUBLE_ARROW
121
+				&& $tokens[$checkToken]['code'] !== T_COMMA
122
+				&& $checkToken !== $arrayEnd
123
+			) {
124
+				continue;
125
+			}
126
+
127
+			if ($tokens[$checkToken]['code'] === T_COMMA
128
+				|| $checkToken === $arrayEnd
129
+			) {
130
+				$stackPtrCount = 0;
131
+				if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
132
+					$stackPtrCount = count($tokens[$stackPtr]['nested_parenthesis']);
133
+				}
134
+
135
+				$commaCount = 0;
136
+				if (isset($tokens[$checkToken]['nested_parenthesis']) === true) {
137
+					$commaCount = count($tokens[$checkToken]['nested_parenthesis']);
138
+					if ($tokens[$stackPtr]['code'] === T_ARRAY) {
139
+						// Remove parenthesis that are used to define the array.
140
+						$commaCount--;
141
+					}
142
+				}
143
+
144
+				if ($commaCount > $stackPtrCount) {
145
+					// This comma is inside more parenthesis than the ARRAY keyword,
146
+					// so it is actually a comma used to do things like
147
+					// separate arguments in a function call.
148
+					continue;
149
+				}
150
+
151
+				if ($keyUsed === false) {
152
+					$valueContent = $phpcsFile->findNext(
153
+						Tokens::$emptyTokens,
154
+						($lastToken + 1),
155
+						$checkToken,
156
+						true
157
+					);
158
+
159
+					$indices[] = ['value_start' => $valueContent];
160
+				}
161
+
162
+				$lastToken = $checkToken;
163
+				$keyUsed   = false;
164
+				continue;
165
+			}//end if
166
+
167
+			if ($tokens[$checkToken]['code'] === T_DOUBLE_ARROW) {
168
+				$keyUsed = true;
169
+
170
+				// Find the start of index that uses this double arrow.
171
+				$indexEnd   = $phpcsFile->findPrevious(T_WHITESPACE, ($checkToken - 1), $arrayStart, true);
172
+				$indexStart = $phpcsFile->findStartOfStatement($indexEnd);
173
+
174
+				// Find the value of this index.
175
+				$nextContent = $phpcsFile->findNext(
176
+					Tokens::$emptyTokens,
177
+					($checkToken + 1),
178
+					$arrayEnd,
179
+					true
180
+				);
181
+
182
+				$indices[] = [
183
+					'index_start' => $indexStart,
184
+					'index_end'   => $indexEnd,
185
+					'arrow'       => $checkToken,
186
+					'value_start' => $nextContent,
187
+				];
188
+
189
+				$lastToken = $checkToken;
190
+			}//end if
191
+		}//end for
192
+
193
+		if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) {
194
+			$this->processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
195
+		} else {
196
+			$this->processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
197
+		}
198
+
199
+	}//end process()
200
+
201
+
202
+	/**
203
+	 * Processes a single-line array definition.
204
+	 *
205
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile  The current file being checked.
206
+	 * @param int                         $stackPtr   The position of the current token
207
+	 *                                                in the stack passed in $tokens.
208
+	 * @param int                         $arrayStart The token that starts the array definition.
209
+	 * @param int                         $arrayEnd   The token that ends the array definition.
210
+	 * @param array                       $indices    An array of token positions for the array keys,
211
+	 *                                                double arrows, and values.
212
+	 *
213
+	 * @return void
214
+	 */
215
+	abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
216
+
217
+
218
+	/**
219
+	 * Processes a multi-line array definition.
220
+	 *
221
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile  The current file being checked.
222
+	 * @param int                         $stackPtr   The position of the current token
223
+	 *                                                in the stack passed in $tokens.
224
+	 * @param int                         $arrayStart The token that starts the array definition.
225
+	 * @param int                         $arrayEnd   The token that ends the array definition.
226
+	 * @param array                       $indices    An array of token positions for the array keys,
227
+	 *                                                double arrows, and values.
228
+	 *
229
+	 * @return void
230
+	 */
231
+	abstract protected function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
232 232
 
233 233
 
234 234
 }//end class
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -40,123 +40,123 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return void
42 42
      */
43
-    public function process(File $phpcsFile, $stackPtr)
43
+    public function process( File $phpcsFile, $stackPtr )
44 44
     {
45 45
         $tokens = $phpcsFile->getTokens();
46 46
 
47
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
48
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no');
47
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
48
+            $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'no' );
49 49
 
50
-            $arrayStart = $tokens[$stackPtr]['parenthesis_opener'];
51
-            if (isset($tokens[$arrayStart]['parenthesis_closer']) === false) {
50
+            $arrayStart = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
51
+            if ( isset( $tokens[ $arrayStart ][ 'parenthesis_closer' ] ) === false ) {
52 52
                 // Incomplete array.
53 53
                 return;
54 54
             }
55 55
 
56
-            $arrayEnd = $tokens[$arrayStart]['parenthesis_closer'];
56
+            $arrayEnd = $tokens[ $arrayStart ][ 'parenthesis_closer' ];
57 57
         } else {
58
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
58
+            $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'yes' );
59 59
             $arrayStart = $stackPtr;
60
-            $arrayEnd   = $tokens[$stackPtr]['bracket_closer'];
60
+            $arrayEnd   = $tokens[ $stackPtr ][ 'bracket_closer' ];
61 61
         }
62 62
 
63
-        $lastContent = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrayEnd - 1), null, true);
64
-        if ($tokens[$lastContent]['code'] === T_COMMA) {
63
+        $lastContent = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $arrayEnd - 1 ), null, true );
64
+        if ( $tokens[ $lastContent ][ 'code' ] === T_COMMA ) {
65 65
             // Last array item ends with a comma.
66
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'yes');
66
+            $phpcsFile->recordMetric( $stackPtr, 'Array end comma', 'yes' );
67 67
             $lastArrayToken = $lastContent;
68 68
         } else {
69
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'no');
69
+            $phpcsFile->recordMetric( $stackPtr, 'Array end comma', 'no' );
70 70
             $lastArrayToken = $arrayEnd;
71 71
         }
72 72
 
73
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
74
-            $lastToken = $tokens[$stackPtr]['parenthesis_opener'];
73
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
74
+            $lastToken = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
75 75
         } else {
76 76
             $lastToken = $stackPtr;
77 77
         }
78 78
 
79 79
         $keyUsed = false;
80
-        $indices = [];
80
+        $indices = [ ];
81 81
 
82
-        for ($checkToken = ($stackPtr + 1); $checkToken <= $lastArrayToken; $checkToken++) {
82
+        for ( $checkToken = ( $stackPtr + 1 ); $checkToken <= $lastArrayToken; $checkToken++ ) {
83 83
             // Skip bracketed statements, like function calls.
84
-            if ($tokens[$checkToken]['code'] === T_OPEN_PARENTHESIS
85
-                && (isset($tokens[$checkToken]['parenthesis_owner']) === false
86
-                || $tokens[$checkToken]['parenthesis_owner'] !== $stackPtr)
84
+            if ( $tokens[ $checkToken ][ 'code' ] === T_OPEN_PARENTHESIS
85
+                && ( isset( $tokens[ $checkToken ][ 'parenthesis_owner' ] ) === false
86
+                || $tokens[ $checkToken ][ 'parenthesis_owner' ] !== $stackPtr )
87 87
             ) {
88
-                $checkToken = $tokens[$checkToken]['parenthesis_closer'];
88
+                $checkToken = $tokens[ $checkToken ][ 'parenthesis_closer' ];
89 89
                 continue;
90 90
             }
91 91
 
92
-            if ($tokens[$checkToken]['code'] === T_ARRAY
93
-                || $tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY
94
-                || $tokens[$checkToken]['code'] === T_CLOSURE
92
+            if ( $tokens[ $checkToken ][ 'code' ] === T_ARRAY
93
+                || $tokens[ $checkToken ][ 'code' ] === T_OPEN_SHORT_ARRAY
94
+                || $tokens[ $checkToken ][ 'code' ] === T_CLOSURE
95 95
             ) {
96 96
                 // Let subsequent calls of this test handle nested arrays.
97
-                if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {
98
-                    $indices[] = ['value_start' => $checkToken];
97
+                if ( $tokens[ $lastToken ][ 'code' ] !== T_DOUBLE_ARROW ) {
98
+                    $indices[ ] = [ 'value_start' => $checkToken ];
99 99
                     $lastToken = $checkToken;
100 100
                 }
101 101
 
102
-                if ($tokens[$checkToken]['code'] === T_ARRAY) {
103
-                    $checkToken = $tokens[$tokens[$checkToken]['parenthesis_opener']]['parenthesis_closer'];
104
-                } else if ($tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY) {
105
-                    $checkToken = $tokens[$checkToken]['bracket_closer'];
102
+                if ( $tokens[ $checkToken ][ 'code' ] === T_ARRAY ) {
103
+                    $checkToken = $tokens[ $tokens[ $checkToken ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ];
104
+                } else if ( $tokens[ $checkToken ][ 'code' ] === T_OPEN_SHORT_ARRAY ) {
105
+                    $checkToken = $tokens[ $checkToken ][ 'bracket_closer' ];
106 106
                 } else {
107 107
                     // T_CLOSURE.
108
-                    $checkToken = $tokens[$checkToken]['scope_closer'];
108
+                    $checkToken = $tokens[ $checkToken ][ 'scope_closer' ];
109 109
                 }
110 110
 
111
-                $checkToken = $phpcsFile->findNext(T_WHITESPACE, ($checkToken + 1), null, true);
111
+                $checkToken = $phpcsFile->findNext( T_WHITESPACE, ( $checkToken + 1 ), null, true );
112 112
                 $lastToken  = $checkToken;
113
-                if ($tokens[$checkToken]['code'] !== T_COMMA) {
113
+                if ( $tokens[ $checkToken ][ 'code' ] !== T_COMMA ) {
114 114
                     $checkToken--;
115 115
                 }
116 116
 
117 117
                 continue;
118 118
             }//end if
119 119
 
120
-            if ($tokens[$checkToken]['code'] !== T_DOUBLE_ARROW
121
-                && $tokens[$checkToken]['code'] !== T_COMMA
120
+            if ( $tokens[ $checkToken ][ 'code' ] !== T_DOUBLE_ARROW
121
+                && $tokens[ $checkToken ][ 'code' ] !== T_COMMA
122 122
                 && $checkToken !== $arrayEnd
123 123
             ) {
124 124
                 continue;
125 125
             }
126 126
 
127
-            if ($tokens[$checkToken]['code'] === T_COMMA
127
+            if ( $tokens[ $checkToken ][ 'code' ] === T_COMMA
128 128
                 || $checkToken === $arrayEnd
129 129
             ) {
130 130
                 $stackPtrCount = 0;
131
-                if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
132
-                    $stackPtrCount = count($tokens[$stackPtr]['nested_parenthesis']);
131
+                if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
132
+                    $stackPtrCount = count( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
133 133
                 }
134 134
 
135 135
                 $commaCount = 0;
136
-                if (isset($tokens[$checkToken]['nested_parenthesis']) === true) {
137
-                    $commaCount = count($tokens[$checkToken]['nested_parenthesis']);
138
-                    if ($tokens[$stackPtr]['code'] === T_ARRAY) {
136
+                if ( isset( $tokens[ $checkToken ][ 'nested_parenthesis' ] ) === true ) {
137
+                    $commaCount = count( $tokens[ $checkToken ][ 'nested_parenthesis' ] );
138
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
139 139
                         // Remove parenthesis that are used to define the array.
140 140
                         $commaCount--;
141 141
                     }
142 142
                 }
143 143
 
144
-                if ($commaCount > $stackPtrCount) {
144
+                if ( $commaCount > $stackPtrCount ) {
145 145
                     // This comma is inside more parenthesis than the ARRAY keyword,
146 146
                     // so it is actually a comma used to do things like
147 147
                     // separate arguments in a function call.
148 148
                     continue;
149 149
                 }
150 150
 
151
-                if ($keyUsed === false) {
151
+                if ( $keyUsed === false ) {
152 152
                     $valueContent = $phpcsFile->findNext(
153 153
                         Tokens::$emptyTokens,
154
-                        ($lastToken + 1),
154
+                        ( $lastToken + 1 ),
155 155
                         $checkToken,
156 156
                         true
157 157
                     );
158 158
 
159
-                    $indices[] = ['value_start' => $valueContent];
159
+                    $indices[ ] = [ 'value_start' => $valueContent ];
160 160
                 }
161 161
 
162 162
                 $lastToken = $checkToken;
@@ -164,22 +164,22 @@  discard block
 block discarded – undo
164 164
                 continue;
165 165
             }//end if
166 166
 
167
-            if ($tokens[$checkToken]['code'] === T_DOUBLE_ARROW) {
167
+            if ( $tokens[ $checkToken ][ 'code' ] === T_DOUBLE_ARROW ) {
168 168
                 $keyUsed = true;
169 169
 
170 170
                 // Find the start of index that uses this double arrow.
171
-                $indexEnd   = $phpcsFile->findPrevious(T_WHITESPACE, ($checkToken - 1), $arrayStart, true);
172
-                $indexStart = $phpcsFile->findStartOfStatement($indexEnd);
171
+                $indexEnd   = $phpcsFile->findPrevious( T_WHITESPACE, ( $checkToken - 1 ), $arrayStart, true );
172
+                $indexStart = $phpcsFile->findStartOfStatement( $indexEnd );
173 173
 
174 174
                 // Find the value of this index.
175 175
                 $nextContent = $phpcsFile->findNext(
176 176
                     Tokens::$emptyTokens,
177
-                    ($checkToken + 1),
177
+                    ( $checkToken + 1 ),
178 178
                     $arrayEnd,
179 179
                     true
180 180
                 );
181 181
 
182
-                $indices[] = [
182
+                $indices[ ] = [
183 183
                     'index_start' => $indexStart,
184 184
                     'index_end'   => $indexEnd,
185 185
                     'arrow'       => $checkToken,
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
             }//end if
191 191
         }//end for
192 192
 
193
-        if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) {
194
-            $this->processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
193
+        if ( $tokens[ $arrayStart ][ 'line' ] === $tokens[ $arrayEnd ][ 'line' ] ) {
194
+            $this->processSingleLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
195 195
         } else {
196
-            $this->processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
196
+            $this->processMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
197 197
         }
198 198
 
199 199
     }//end process()
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @return void
214 214
      */
215
-    abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
215
+    abstract protected function processSingleLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
216 216
 
217 217
 
218 218
     /**
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      *
229 229
      * @return void
230 230
      */
231
-    abstract protected function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
231
+    abstract protected function processMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
232 232
 
233 233
 
234 234
 }//end class
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Files\File;
13 13
 use PHP_CodeSniffer\Util\Tokens;
14 14
 
15
-abstract class AbstractArraySniff implements Sniff
16
-{
15
+abstract class AbstractArraySniff implements Sniff {
17 16
 
18 17
 
19 18
     /**
@@ -21,8 +20,7 @@  discard block
 block discarded – undo
21 20
      *
22 21
      * @return array
23 22
      */
24
-    final public function register()
25
-    {
23
+    final public function register() {
26 24
         return [
27 25
             T_ARRAY,
28 26
             T_OPEN_SHORT_ARRAY,
@@ -40,8 +38,7 @@  discard block
 block discarded – undo
40 38
      *
41 39
      * @return void
42 40
      */
43
-    public function process(File $phpcsFile, $stackPtr)
44
-    {
41
+    public function process(File $phpcsFile, $stackPtr) {
45 42
         $tokens = $phpcsFile->getTokens();
46 43
 
47 44
         if ($tokens[$stackPtr]['code'] === T_ARRAY) {
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractVariableSniff.php 3 patches
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -22,210 +22,210 @@
 block discarded – undo
22 22
 {
23 23
 
24 24
 
25
-    /**
26
-     * List of PHP Reserved variables.
27
-     *
28
-     * Used by various naming convention sniffs.
29
-     *
30
-     * @var array
31
-     */
32
-    protected $phpReservedVars = [
33
-        '_SERVER'              => true,
34
-        '_GET'                 => true,
35
-        '_POST'                => true,
36
-        '_REQUEST'             => true,
37
-        '_SESSION'             => true,
38
-        '_ENV'                 => true,
39
-        '_COOKIE'              => true,
40
-        '_FILES'               => true,
41
-        'GLOBALS'              => true,
42
-        'http_response_header' => true,
43
-        'HTTP_RAW_POST_DATA'   => true,
44
-        'php_errormsg'         => true,
45
-    ];
46
-
47
-
48
-    /**
49
-     * Constructs an AbstractVariableTest.
50
-     */
51
-    public function __construct()
52
-    {
53
-        $scopes = Tokens::$ooScopeTokens;
54
-
55
-        $listen = [
56
-            T_VARIABLE,
57
-            T_DOUBLE_QUOTED_STRING,
58
-            T_HEREDOC,
59
-        ];
60
-
61
-        parent::__construct($scopes, $listen, true);
62
-
63
-    }//end __construct()
64
-
65
-
66
-    /**
67
-     * Processes the token in the specified PHP_CodeSniffer\Files\File.
68
-     *
69
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
70
-     *                                               token was found.
71
-     * @param int                         $stackPtr  The position where the token was found.
72
-     * @param int                         $currScope The current scope opener token.
73
-     *
74
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
75
-     *                  called again on the current file until the returned stack
76
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
77
-     *                  the rest of the file.
78
-     */
79
-    final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
80
-    {
81
-        $tokens = $phpcsFile->getTokens();
82
-
83
-        if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
84
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
85
-        ) {
86
-            // Check to see if this string has a variable in it.
87
-            $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
88
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
89
-                return $this->processVariableInString($phpcsFile, $stackPtr);
90
-            }
91
-
92
-            return;
93
-        }
94
-
95
-        // If this token is nested inside a function at a deeper
96
-        // level than the current OO scope that was found, it's a normal
97
-        // variable and not a member var.
98
-        $conditions = array_reverse($tokens[$stackPtr]['conditions'], true);
99
-        $inFunction = false;
100
-        foreach ($conditions as $scope => $code) {
101
-            if (isset(Tokens::$ooScopeTokens[$code]) === true) {
102
-                break;
103
-            }
104
-
105
-            if ($code === T_FUNCTION || $code === T_CLOSURE) {
106
-                $inFunction = true;
107
-            }
108
-        }
109
-
110
-        if ($scope !== $currScope) {
111
-            // We found a closer scope to this token, so ignore
112
-            // this particular time through the sniff. We will process
113
-            // this token when this closer scope is found to avoid
114
-            // duplicate checks.
115
-            return;
116
-        }
117
-
118
-        // Just make sure this isn't a variable in a function declaration.
119
-        if ($inFunction === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
120
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $opener => $closer) {
121
-                if (isset($tokens[$opener]['parenthesis_owner']) === false) {
122
-                    // Check if this is a USE statement for a closure.
123
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true);
124
-                    if ($tokens[$prev]['code'] === T_USE) {
125
-                        $inFunction = true;
126
-                        break;
127
-                    }
128
-
129
-                    continue;
130
-                }
131
-
132
-                $owner = $tokens[$opener]['parenthesis_owner'];
133
-                if ($tokens[$owner]['code'] === T_FUNCTION
134
-                    || $tokens[$owner]['code'] === T_CLOSURE
135
-                ) {
136
-                    $inFunction = true;
137
-                    break;
138
-                }
139
-            }
140
-        }//end if
141
-
142
-        if ($inFunction === true) {
143
-            return $this->processVariable($phpcsFile, $stackPtr);
144
-        } else {
145
-            return $this->processMemberVar($phpcsFile, $stackPtr);
146
-        }
147
-
148
-    }//end processTokenWithinScope()
149
-
150
-
151
-    /**
152
-     * Processes the token outside the scope in the file.
153
-     *
154
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
155
-     *                                               token was found.
156
-     * @param int                         $stackPtr  The position where the token was found.
157
-     *
158
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
159
-     *                  called again on the current file until the returned stack
160
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
161
-     *                  the rest of the file.
162
-     */
163
-    final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
164
-    {
165
-        $tokens = $phpcsFile->getTokens();
166
-        // These variables are not member vars.
167
-        if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
168
-            return $this->processVariable($phpcsFile, $stackPtr);
169
-        } else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
170
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
171
-        ) {
172
-            // Check to see if this string has a variable in it.
173
-            $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
174
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
175
-                return $this->processVariableInString($phpcsFile, $stackPtr);
176
-            }
177
-        }
178
-
179
-    }//end processTokenOutsideScope()
180
-
181
-
182
-    /**
183
-     * Called to process class member vars.
184
-     *
185
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
186
-     *                                               token was found.
187
-     * @param int                         $stackPtr  The position where the token was found.
188
-     *
189
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
190
-     *                  called again on the current file until the returned stack
191
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
192
-     *                  the rest of the file.
193
-     */
194
-    abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
195
-
196
-
197
-    /**
198
-     * Called to process normal member vars.
199
-     *
200
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
201
-     *                                               token was found.
202
-     * @param int                         $stackPtr  The position where the token was found.
203
-     *
204
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
205
-     *                  called again on the current file until the returned stack
206
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
207
-     *                  the rest of the file.
208
-     */
209
-    abstract protected function processVariable(File $phpcsFile, $stackPtr);
210
-
211
-
212
-    /**
213
-     * Called to process variables found in double quoted strings or heredocs.
214
-     *
215
-     * Note that there may be more than one variable in the string, which will
216
-     * result only in one call for the string or one call per line for heredocs.
217
-     *
218
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
219
-     *                                               token was found.
220
-     * @param int                         $stackPtr  The position where the double quoted
221
-     *                                               string was found.
222
-     *
223
-     * @return void|int Optionally returns a stack pointer. The sniff will not be
224
-     *                  called again on the current file until the returned stack
225
-     *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
226
-     *                  the rest of the file.
227
-     */
228
-    abstract protected function processVariableInString(File $phpcsFile, $stackPtr);
25
+	/**
26
+	 * List of PHP Reserved variables.
27
+	 *
28
+	 * Used by various naming convention sniffs.
29
+	 *
30
+	 * @var array
31
+	 */
32
+	protected $phpReservedVars = [
33
+		'_SERVER'              => true,
34
+		'_GET'                 => true,
35
+		'_POST'                => true,
36
+		'_REQUEST'             => true,
37
+		'_SESSION'             => true,
38
+		'_ENV'                 => true,
39
+		'_COOKIE'              => true,
40
+		'_FILES'               => true,
41
+		'GLOBALS'              => true,
42
+		'http_response_header' => true,
43
+		'HTTP_RAW_POST_DATA'   => true,
44
+		'php_errormsg'         => true,
45
+	];
46
+
47
+
48
+	/**
49
+	 * Constructs an AbstractVariableTest.
50
+	 */
51
+	public function __construct()
52
+	{
53
+		$scopes = Tokens::$ooScopeTokens;
54
+
55
+		$listen = [
56
+			T_VARIABLE,
57
+			T_DOUBLE_QUOTED_STRING,
58
+			T_HEREDOC,
59
+		];
60
+
61
+		parent::__construct($scopes, $listen, true);
62
+
63
+	}//end __construct()
64
+
65
+
66
+	/**
67
+	 * Processes the token in the specified PHP_CodeSniffer\Files\File.
68
+	 *
69
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
70
+	 *                                               token was found.
71
+	 * @param int                         $stackPtr  The position where the token was found.
72
+	 * @param int                         $currScope The current scope opener token.
73
+	 *
74
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
75
+	 *                  called again on the current file until the returned stack
76
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
77
+	 *                  the rest of the file.
78
+	 */
79
+	final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
80
+	{
81
+		$tokens = $phpcsFile->getTokens();
82
+
83
+		if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
84
+			|| $tokens[$stackPtr]['code'] === T_HEREDOC
85
+		) {
86
+			// Check to see if this string has a variable in it.
87
+			$pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
88
+			if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
89
+				return $this->processVariableInString($phpcsFile, $stackPtr);
90
+			}
91
+
92
+			return;
93
+		}
94
+
95
+		// If this token is nested inside a function at a deeper
96
+		// level than the current OO scope that was found, it's a normal
97
+		// variable and not a member var.
98
+		$conditions = array_reverse($tokens[$stackPtr]['conditions'], true);
99
+		$inFunction = false;
100
+		foreach ($conditions as $scope => $code) {
101
+			if (isset(Tokens::$ooScopeTokens[$code]) === true) {
102
+				break;
103
+			}
104
+
105
+			if ($code === T_FUNCTION || $code === T_CLOSURE) {
106
+				$inFunction = true;
107
+			}
108
+		}
109
+
110
+		if ($scope !== $currScope) {
111
+			// We found a closer scope to this token, so ignore
112
+			// this particular time through the sniff. We will process
113
+			// this token when this closer scope is found to avoid
114
+			// duplicate checks.
115
+			return;
116
+		}
117
+
118
+		// Just make sure this isn't a variable in a function declaration.
119
+		if ($inFunction === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
120
+			foreach ($tokens[$stackPtr]['nested_parenthesis'] as $opener => $closer) {
121
+				if (isset($tokens[$opener]['parenthesis_owner']) === false) {
122
+					// Check if this is a USE statement for a closure.
123
+					$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true);
124
+					if ($tokens[$prev]['code'] === T_USE) {
125
+						$inFunction = true;
126
+						break;
127
+					}
128
+
129
+					continue;
130
+				}
131
+
132
+				$owner = $tokens[$opener]['parenthesis_owner'];
133
+				if ($tokens[$owner]['code'] === T_FUNCTION
134
+					|| $tokens[$owner]['code'] === T_CLOSURE
135
+				) {
136
+					$inFunction = true;
137
+					break;
138
+				}
139
+			}
140
+		}//end if
141
+
142
+		if ($inFunction === true) {
143
+			return $this->processVariable($phpcsFile, $stackPtr);
144
+		} else {
145
+			return $this->processMemberVar($phpcsFile, $stackPtr);
146
+		}
147
+
148
+	}//end processTokenWithinScope()
149
+
150
+
151
+	/**
152
+	 * Processes the token outside the scope in the file.
153
+	 *
154
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
155
+	 *                                               token was found.
156
+	 * @param int                         $stackPtr  The position where the token was found.
157
+	 *
158
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
159
+	 *                  called again on the current file until the returned stack
160
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
161
+	 *                  the rest of the file.
162
+	 */
163
+	final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
164
+	{
165
+		$tokens = $phpcsFile->getTokens();
166
+		// These variables are not member vars.
167
+		if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
168
+			return $this->processVariable($phpcsFile, $stackPtr);
169
+		} else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
170
+			|| $tokens[$stackPtr]['code'] === T_HEREDOC
171
+		) {
172
+			// Check to see if this string has a variable in it.
173
+			$pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
174
+			if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
175
+				return $this->processVariableInString($phpcsFile, $stackPtr);
176
+			}
177
+		}
178
+
179
+	}//end processTokenOutsideScope()
180
+
181
+
182
+	/**
183
+	 * Called to process class member vars.
184
+	 *
185
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
186
+	 *                                               token was found.
187
+	 * @param int                         $stackPtr  The position where the token was found.
188
+	 *
189
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
190
+	 *                  called again on the current file until the returned stack
191
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
192
+	 *                  the rest of the file.
193
+	 */
194
+	abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
195
+
196
+
197
+	/**
198
+	 * Called to process normal member vars.
199
+	 *
200
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
201
+	 *                                               token was found.
202
+	 * @param int                         $stackPtr  The position where the token was found.
203
+	 *
204
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
205
+	 *                  called again on the current file until the returned stack
206
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
207
+	 *                  the rest of the file.
208
+	 */
209
+	abstract protected function processVariable(File $phpcsFile, $stackPtr);
210
+
211
+
212
+	/**
213
+	 * Called to process variables found in double quoted strings or heredocs.
214
+	 *
215
+	 * Note that there may be more than one variable in the string, which will
216
+	 * result only in one call for the string or one call per line for heredocs.
217
+	 *
218
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
219
+	 *                                               token was found.
220
+	 * @param int                         $stackPtr  The position where the double quoted
221
+	 *                                               string was found.
222
+	 *
223
+	 * @return void|int Optionally returns a stack pointer. The sniff will not be
224
+	 *                  called again on the current file until the returned stack
225
+	 *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
226
+	 *                  the rest of the file.
227
+	 */
228
+	abstract protected function processVariableInString(File $phpcsFile, $stackPtr);
229 229
 
230 230
 
231 231
 }//end class
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             T_HEREDOC,
59 59
         ];
60 60
 
61
-        parent::__construct($scopes, $listen, true);
61
+        parent::__construct( $scopes, $listen, true );
62 62
 
63 63
     }//end __construct()
64 64
 
@@ -76,17 +76,17 @@  discard block
 block discarded – undo
76 76
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
77 77
      *                  the rest of the file.
78 78
      */
79
-    final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
79
+    final protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope )
80 80
     {
81 81
         $tokens = $phpcsFile->getTokens();
82 82
 
83
-        if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
84
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
83
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DOUBLE_QUOTED_STRING
84
+            || $tokens[ $stackPtr ][ 'code' ] === T_HEREDOC
85 85
         ) {
86 86
             // Check to see if this string has a variable in it.
87 87
             $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
88
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
89
-                return $this->processVariableInString($phpcsFile, $stackPtr);
88
+            if ( preg_match( $pattern, $tokens[ $stackPtr ][ 'content' ] ) !== 0 ) {
89
+                return $this->processVariableInString( $phpcsFile, $stackPtr );
90 90
             }
91 91
 
92 92
             return;
@@ -95,19 +95,19 @@  discard block
 block discarded – undo
95 95
         // If this token is nested inside a function at a deeper
96 96
         // level than the current OO scope that was found, it's a normal
97 97
         // variable and not a member var.
98
-        $conditions = array_reverse($tokens[$stackPtr]['conditions'], true);
98
+        $conditions = array_reverse( $tokens[ $stackPtr ][ 'conditions' ], true );
99 99
         $inFunction = false;
100
-        foreach ($conditions as $scope => $code) {
101
-            if (isset(Tokens::$ooScopeTokens[$code]) === true) {
100
+        foreach ( $conditions as $scope => $code ) {
101
+            if ( isset( Tokens::$ooScopeTokens[ $code ] ) === true ) {
102 102
                 break;
103 103
             }
104 104
 
105
-            if ($code === T_FUNCTION || $code === T_CLOSURE) {
105
+            if ( $code === T_FUNCTION || $code === T_CLOSURE ) {
106 106
                 $inFunction = true;
107 107
             }
108 108
         }
109 109
 
110
-        if ($scope !== $currScope) {
110
+        if ( $scope !== $currScope ) {
111 111
             // We found a closer scope to this token, so ignore
112 112
             // this particular time through the sniff. We will process
113 113
             // this token when this closer scope is found to avoid
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Just make sure this isn't a variable in a function declaration.
119
-        if ($inFunction === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
120
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $opener => $closer) {
121
-                if (isset($tokens[$opener]['parenthesis_owner']) === false) {
119
+        if ( $inFunction === false && isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
120
+            foreach ( $tokens[ $stackPtr ][ 'nested_parenthesis' ] as $opener => $closer ) {
121
+                if ( isset( $tokens[ $opener ][ 'parenthesis_owner' ] ) === false ) {
122 122
                     // Check if this is a USE statement for a closure.
123
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true);
124
-                    if ($tokens[$prev]['code'] === T_USE) {
123
+                    $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true );
124
+                    if ( $tokens[ $prev ][ 'code' ] === T_USE ) {
125 125
                         $inFunction = true;
126 126
                         break;
127 127
                     }
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
                     continue;
130 130
                 }
131 131
 
132
-                $owner = $tokens[$opener]['parenthesis_owner'];
133
-                if ($tokens[$owner]['code'] === T_FUNCTION
134
-                    || $tokens[$owner]['code'] === T_CLOSURE
132
+                $owner = $tokens[ $opener ][ 'parenthesis_owner' ];
133
+                if ( $tokens[ $owner ][ 'code' ] === T_FUNCTION
134
+                    || $tokens[ $owner ][ 'code' ] === T_CLOSURE
135 135
                 ) {
136 136
                     $inFunction = true;
137 137
                     break;
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
             }
140 140
         }//end if
141 141
 
142
-        if ($inFunction === true) {
143
-            return $this->processVariable($phpcsFile, $stackPtr);
142
+        if ( $inFunction === true ) {
143
+            return $this->processVariable( $phpcsFile, $stackPtr );
144 144
         } else {
145
-            return $this->processMemberVar($phpcsFile, $stackPtr);
145
+            return $this->processMemberVar( $phpcsFile, $stackPtr );
146 146
         }
147 147
 
148 148
     }//end processTokenWithinScope()
@@ -160,19 +160,19 @@  discard block
 block discarded – undo
160 160
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
161 161
      *                  the rest of the file.
162 162
      */
163
-    final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
163
+    final protected function processTokenOutsideScope( File $phpcsFile, $stackPtr )
164 164
     {
165 165
         $tokens = $phpcsFile->getTokens();
166 166
         // These variables are not member vars.
167
-        if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
168
-            return $this->processVariable($phpcsFile, $stackPtr);
169
-        } else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
170
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
167
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_VARIABLE ) {
168
+            return $this->processVariable( $phpcsFile, $stackPtr );
169
+        } else if ( $tokens[ $stackPtr ][ 'code' ] === T_DOUBLE_QUOTED_STRING
170
+            || $tokens[ $stackPtr ][ 'code' ] === T_HEREDOC
171 171
         ) {
172 172
             // Check to see if this string has a variable in it.
173 173
             $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
174
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
175
-                return $this->processVariableInString($phpcsFile, $stackPtr);
174
+            if ( preg_match( $pattern, $tokens[ $stackPtr ][ 'content' ] ) !== 0 ) {
175
+                return $this->processVariableInString( $phpcsFile, $stackPtr );
176 176
             }
177 177
         }
178 178
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
192 192
      *                  the rest of the file.
193 193
      */
194
-    abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
194
+    abstract protected function processMemberVar( File $phpcsFile, $stackPtr );
195 195
 
196 196
 
197 197
     /**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
207 207
      *                  the rest of the file.
208 208
      */
209
-    abstract protected function processVariable(File $phpcsFile, $stackPtr);
209
+    abstract protected function processVariable( File $phpcsFile, $stackPtr );
210 210
 
211 211
 
212 212
     /**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
226 226
      *                  the rest of the file.
227 227
      */
228
-    abstract protected function processVariableInString(File $phpcsFile, $stackPtr);
228
+    abstract protected function processVariableInString( File $phpcsFile, $stackPtr );
229 229
 
230 230
 
231 231
 }//end class
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@  discard block
 block discarded – undo
18 18
 use PHP_CodeSniffer\Files\File;
19 19
 use PHP_CodeSniffer\Util\Tokens;
20 20
 
21
-abstract class AbstractVariableSniff extends AbstractScopeSniff
22
-{
21
+abstract class AbstractVariableSniff extends AbstractScopeSniff {
23 22
 
24 23
 
25 24
     /**
@@ -48,8 +47,7 @@  discard block
 block discarded – undo
48 47
     /**
49 48
      * Constructs an AbstractVariableTest.
50 49
      */
51
-    public function __construct()
52
-    {
50
+    public function __construct() {
53 51
         $scopes = Tokens::$ooScopeTokens;
54 52
 
55 53
         $listen = [
@@ -76,8 +74,7 @@  discard block
 block discarded – undo
76 74
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
77 75
      *                  the rest of the file.
78 76
      */
79
-    final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
80
-    {
77
+    final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) {
81 78
         $tokens = $phpcsFile->getTokens();
82 79
 
83 80
         if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
@@ -160,8 +157,7 @@  discard block
 block discarded – undo
160 157
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
161 158
      *                  the rest of the file.
162 159
      */
163
-    final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
164
-    {
160
+    final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
165 161
         $tokens = $phpcsFile->getTokens();
166 162
         // These variables are not member vars.
167 163
         if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	$var2;
57 57
 
58 58
 if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
59
-    $x === 'test'
59
+	$x === 'test'
60 60
 ) {}
61 61
 
62 62
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines true
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	$var1 + (bool)  $var2;
65 65
 
66 66
 if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
67
-    $x === 'test'
67
+	$x === 'test'
68 68
 ) {}
69 69
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false
70 70
 
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,95 +1,95 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$var = (int) $var2;
4 3
 $var = (int)$var2;
5
-$var = (int)  $var2;
4
+$var = (int)$var2;
5
+$var = (int)$var2;
6 6
 
7
-$var = (integer) $var2;
8 7
 $var = (integer)$var2;
9
-$var = (integer)  $var2;
8
+$var = (integer)$var2;
9
+$var = (integer)$var2;
10 10
 
11
-$var = (string) $var2;
12 11
 $var = (string)$var2;
13
-$var = (string)    $var2;
12
+$var = (string)$var2;
13
+$var = (string)$var2;
14 14
 
15
-$var = (float) $var2;
16 15
 $var = (float)$var2;
17
-$var = (float)  $var2;
16
+$var = (float)$var2;
17
+$var = (float)$var2;
18 18
 
19
-$var = (double) $var2;
20 19
 $var = (double)$var2;
21
-$var = (double)  $var2;
20
+$var = (double)$var2;
21
+$var = (double)$var2;
22 22
 
23
-$var = (real) $var2;
24 23
 $var = (real)$var2;
25
-$var = (real)  $var2;
24
+$var = (real)$var2;
25
+$var = (real)$var2;
26 26
 
27
-$var = (array) $var2;
28 27
 $var = (array)$var2;
29
-$var = (array)  $var2;
28
+$var = (array)$var2;
29
+$var = (array)$var2;
30 30
 
31
-$var = (bool) $var2;
32 31
 $var = (bool)$var2;
33
-$var = (bool)  $var2;
32
+$var = (bool)$var2;
33
+$var = (bool)$var2;
34 34
 
35
-$var = (boolean) $var2;
36 35
 $var = (boolean)$var2;
37
-$var = (boolean)  $var2;
36
+$var = (boolean)$var2;
37
+$var = (boolean)$var2;
38 38
 
39
-$var = (object) $var2;
40 39
 $var = (object)$var2;
41
-$var = (object)  $var2;
40
+$var = (object)$var2;
41
+$var = (object)$var2;
42 42
 
43
-$var = (unset) $var2;
44 43
 $var = (unset)$var2;
45
-$var = (unset)          $var2;
44
+$var = (unset)$var2;
45
+$var = (unset)$var2;
46 46
 
47 47
 $var = b"binary $foo";
48 48
 $var = b"binary string";
49 49
 $var = b'binary string';
50
-$var = (binary) $string;
50
+$var = (binary)$string;
51 51
 $var = (binary)$string;
52 52
 
53
-$var = (boolean) /* comment */ $var2;
53
+$var = (boolean)/* comment */ $var2;
54 54
 
55 55
 $var = (int)
56 56
 	$var2;
57 57
 
58
-if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
58
+if ( (string)// phpcs:ignore Standard.Cat.SniffName -- for reasons.
59 59
     $x === 'test'
60 60
 ) {}
61 61
 
62 62
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines true
63 63
 $var = (int)
64
-	$var1 + (bool)  $var2;
64
+	$var1 + (bool)$var2;
65 65
 
66
-if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
66
+if ( (string)// phpcs:ignore Standard.Cat.SniffName -- for reasons.
67 67
     $x === 'test'
68 68
 ) {}
69 69
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false
70 70
 
71 71
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 2
72
-$var = (int) $var2;
72
+$var = (int)$var2;
73 73
 $var = (string)$var2;
74
-$var = (array)  $var2;
75
-$var = (unset)        $var2;
76
-$var = (boolean) /* comment */ $var2;
74
+$var = (array)$var2;
75
+$var = (unset)$var2;
76
+$var = (boolean)/* comment */ $var2;
77 77
 
78 78
 $var = (integer)
79 79
 	$var2;
80 80
 
81 81
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 0
82
-$var = (int) $var2;
82
+$var = (int)$var2;
83 83
 $var = (string)$var2;
84
-$var = (array)  $var2;
85
-$var = (unset)        $var2;
86
-$var = (boolean) /* comment */ $var2;
84
+$var = (array)$var2;
85
+$var = (unset)$var2;
86
+$var = (boolean)/* comment */ $var2;
87 87
 
88 88
 $var = (integer)
89 89
 	$var2;
90 90
 
91 91
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines true
92 92
 $var = (int)
93
-	$var1 + (bool)  $var2;
93
+	$var1 + (bool)$var2;
94 94
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false
95 95
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 1
Please login to merge, or discard this patch.
Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc 3 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -83,122 +83,122 @@  discard block
 block discarded – undo
83 83
 
84 84
 class MyClass
85 85
 {
86
-    const MODE_DEBUG = 'debug';
87
-    const MODE_DEBUG2 = 'debug';
86
+	const MODE_DEBUG = 'debug';
87
+	const MODE_DEBUG2 = 'debug';
88 88
 
89
-    var $array[$test] = 'anything';
90
-    var $var          = 'anything';
89
+	var $array[$test] = 'anything';
90
+	var $var          = 'anything';
91 91
 
92
-    const MODE_DEBUG3  = 'debug';
93
-    public $array[$test]    = 'anything';
94
-    private $vara             = 'anything';
95
-    protected $array[($test + 1)] = 'anything';
96
-    var $array[($blah + (10 - $test))] = 'anything';
92
+	const MODE_DEBUG3  = 'debug';
93
+	public $array[$test]    = 'anything';
94
+	private $vara             = 'anything';
95
+	protected $array[($test + 1)] = 'anything';
96
+	var $array[($blah + (10 - $test))] = 'anything';
97 97
 }
98 98
 
99 99
 function myFunction($var=true)
100 100
 {
101
-    if ($strict === true) {
102
-        $length          = strlen($string);
103
-        $lastCharWasCaps = ($classFormat === false) ? false : true;
104
-
105
-        for ($i = 1; $i < $length; $i++) {
106
-            $isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
107
-            if ($isCaps === true && $lastCharWasCaps === true) {
108
-                return false;
109
-            }
110
-
111
-            $lastCharWasCaps = $isCaps;
112
-        }
113
-    }
101
+	if ($strict === true) {
102
+		$length          = strlen($string);
103
+		$lastCharWasCaps = ($classFormat === false) ? false : true;
104
+
105
+		for ($i = 1; $i < $length; $i++) {
106
+			$isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
107
+			if ($isCaps === true && $lastCharWasCaps === true) {
108
+				return false;
109
+			}
110
+
111
+			$lastCharWasCaps = $isCaps;
112
+		}
113
+	}
114 114
 }
115 115
 
116 116
 // Valid
117 117
 for ($i = 0; $i < 10; $i += 2) {
118
-    $i = ($i - 1);
118
+	$i = ($i - 1);
119 119
 }
120 120
 
121 121
 // Invalid
122 122
 foreach ($files as $file) {
123
-    $saves[$file] = array();
124
-    $contents = stripslashes(file_get_contents($file));
125
-    list($assetid, $time, $content) = explode("\n", $contents);
126
-    $saves[$file]['assetid'] = $assetid;
123
+	$saves[$file] = array();
124
+	$contents = stripslashes(file_get_contents($file));
125
+	list($assetid, $time, $content) = explode("\n", $contents);
126
+	$saves[$file]['assetid'] = $assetid;
127 127
 }
128 128
 
129 129
 $i = ($i - 10);
130 130
 $ip = ($i - 10);
131 131
 for ($i = 0; $i < 10; $i += 2) {
132
-    $i = ($i - 10);
132
+	$i = ($i - 10);
133 133
 }
134 134
 
135 135
 // Valid
136 136
 $variable = 12;
137 137
 $var      = a_very(long_line('that', 'contains'),
138
-                   a_bunch('of long', 'parameters'),
139
-                   'that_need to be aligned with the equal sign');
138
+				   a_bunch('of long', 'parameters'),
139
+				   'that_need to be aligned with the equal sign');
140 140
 $var2     = 12;
141 141
 
142 142
 // Valid
143 143
 $variable = 12;
144 144
 $var      = 'a very long line of text that contains '
145
-            .$someVar
146
-            .' and some other stuff that is too long to fit on one line';
145
+			.$someVar
146
+			.' and some other stuff that is too long to fit on one line';
147 147
 $var2     = 12;
148 148
 
149 149
 // Invalid
150 150
 $variable = 12;
151 151
 $var      = a_very(long_line('that', 'contains'),
152
-                   a_bunch('of long', 'parameters'),
153
-                   'that_need to be aligned with the equal sign');
152
+				   a_bunch('of long', 'parameters'),
153
+				   'that_need to be aligned with the equal sign');
154 154
 $var2 = 12;
155 155
 
156 156
 // Invalid
157 157
 $variable = 12;
158 158
 $var      = 'a very long line of text that contains '
159
-            .$someVar
160
-            .' and some other stuff that is too long to fit on one line';
159
+			.$someVar
160
+			.' and some other stuff that is too long to fit on one line';
161 161
 $var2 = 12;
162 162
 
163 163
 // Valid
164 164
 $variable = 12;
165 165
 $var     .= 'a very long line of text that contains '
166
-            .$someVar
167
-            .' and some other stuff that is too long to fit on one line';
166
+			.$someVar
167
+			.' and some other stuff that is too long to fit on one line';
168 168
 $var2     = 12;
169 169
 
170 170
 // Valid
171 171
 $variable += 12;
172 172
 $var      .= 'a very long line of text that contains '
173
-            .$someVar
174
-            .' and some other stuff that is too long to fit on one line';
173
+			.$someVar
174
+			.' and some other stuff that is too long to fit on one line';
175 175
 $var2      = 12;
176 176
 
177 177
 // Invalid
178 178
 $variable  = 12;
179 179
 $var      .= 'a very long line of text that contains '
180
-            .$someVar
181
-            .' and some other stuff that is too long to fit on one line';
180
+			.$someVar
181
+			.' and some other stuff that is too long to fit on one line';
182 182
 $var2      = 12;
183 183
 
184 184
 // Valid
185 185
 $error = false;
186 186
 while (list($h, $f) = getKeyAndValue($handle)) {
187
-    $error = true;
187
+	$error = true;
188 188
 }
189 189
 
190 190
 // Valid
191 191
 $value = false;
192 192
 function blah ($value = true) {
193
-    $value = false;
194
-    if ($value === true) {
195
-        $value = false;
196
-    }
193
+	$value = false;
194
+	if ($value === true) {
195
+		$value = false;
196
+	}
197 197
 }
198 198
 
199 199
 if (TRUE) {
200
-    $args = array('foo' => 'foo');
201
-    $res  = 'bar';
200
+	$args = array('foo' => 'foo');
201
+	$res  = 'bar';
202 202
 }
203 203
 
204 204
 // phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 8
@@ -234,140 +234,140 @@  discard block
 block discarded – undo
234 234
 $foo = $moooo = 'foo';
235 235
 
236 236
 $foobarbaz = array_map(
237
-    function ($n) {
238
-        return $n * $n;
239
-    },
240
-    [1, 2, 3]
237
+	function ($n) {
238
+		return $n * $n;
239
+	},
240
+	[1, 2, 3]
241 241
 );
242 242
 $foo       = 5;
243 243
 
244 244
 $loggerResult = $util->setLogger(new class {
245
-    public function log($msg)
246
-    {
247
-        echo $msg;
248
-    }
245
+	public function log($msg)
246
+	{
247
+		echo $msg;
248
+	}
249 249
 });
250 250
 $foo          = 5;
251 251
 
252 252
 $foo = array(
253
-    'a' => 'b',
253
+	'a' => 'b',
254 254
 );
255 255
 $barbar = 'bar';
256 256
 
257 257
 $foo = array(
258
-    // Some comment.
259
-    'a' => 'b',
258
+	// Some comment.
259
+	'a' => 'b',
260 260
 );
261 261
 $barbar = 'bar';
262 262
 
263 263
 $foo = [
264
-    // phpcs:ignore Standard.Category.Sniff.Code -- for reasons.
265
-    'a' => 'b',
264
+	// phpcs:ignore Standard.Category.Sniff.Code -- for reasons.
265
+	'a' => 'b',
266 266
 ];
267 267
 $barbar = 'bar';
268 268
 
269 269
 $foo = [
270 270
 
271
-    'a' => 'b',
271
+	'a' => 'b',
272 272
 ];
273 273
 $barbar = 'bar';
274 274
 
275 275
 function buildForm(FormBuilderInterface $builder, array $options)
276 276
 {
277
-    $transformer = new ContractTransformer($options['contracts']);
278
-    $types       = ['support.contact.question' => ContactData::QUESTION];
277
+	$transformer = new ContractTransformer($options['contracts']);
278
+	$types       = ['support.contact.question' => ContactData::QUESTION];
279 279
 
280
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
280
+	[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
281 281
 }
282 282
 
283 283
 function buildForm(FormBuilderInterface $builder, array $options)
284 284
 {
285
-    $transformer                                    = new ContractTransformer($options['contracts']);
286
-    $types                                          = ['support.contact.question' => ContactData::QUESTION];
287
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
285
+	$transformer                                    = new ContractTransformer($options['contracts']);
286
+	$types                                          = ['support.contact.question' => ContactData::QUESTION];
287
+	[$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
288 288
 }
289 289
 
290 290
 $loggerResult = $util->setLogger(new class {
291
-    public function log($msg)
292
-    {
293
-        $a = $msg;
294
-        $foobar = $msg;
295
-        $foo = function() {
296
-            $a = $msg;
297
-            $foobar = $msg;
298
-            $loggerResult = $util->setLogger(new class {
299
-                public function log($msg)
300
-                {
301
-                    $a = $msg;
302
-                    $foobar = $msg;
303
-                    $foo = function() {
304
-                        foo(function() {
305
-                            foo(function() {
306
-                                echo 'hi';
307
-                            });
308
-                            $a = $msg;
309
-                            $foobar = $msg;
310
-
311
-                            $foo = function() {
312
-
313
-                                $foo = 1;
314
-                                $barbar=2;
315
-                            };
316
-                            $barbar = function() {
317
-                                $foo    = 1;
318
-                                $barbar = 2;
319
-                            };
320
-                        });
321
-                        $a = $msg;
322
-                        $foobar      = $msg;
323
-                    };
324
-                    $bar = $msg;
325
-                }
326
-
327
-                public function log2($msg)
328
-                {
329
-                    $a = $msg;
330
-                    $foobar = $msg;
331
-                    $foo = function() {
332
-                        foo(function() {
333
-                            foo(function() {
334
-                                echo 'hi';
335
-                            });
336
-                            $a = $msg;
337
-                            $foobar = $msg;
338
-
339
-                            $foo = function() {
340
-
341
-                                $foo = 1;
342
-                                $barbar=2;
343
-                            };
344
-                            $barbar = function() {
345
-                                $foo    = 1;
346
-                                $barbar = 2;
347
-                            };
348
-                        });
349
-                        $a = $msg;
350
-                        $foobar      = $msg;
351
-                    };
352
-                    $bar = $msg;
353
-                }
354
-            });
355
-            $foo          = 5;
356
-        };
357
-        $bar = $msg;
358
-    }
291
+	public function log($msg)
292
+	{
293
+		$a = $msg;
294
+		$foobar = $msg;
295
+		$foo = function() {
296
+			$a = $msg;
297
+			$foobar = $msg;
298
+			$loggerResult = $util->setLogger(new class {
299
+				public function log($msg)
300
+				{
301
+					$a = $msg;
302
+					$foobar = $msg;
303
+					$foo = function() {
304
+						foo(function() {
305
+							foo(function() {
306
+								echo 'hi';
307
+							});
308
+							$a = $msg;
309
+							$foobar = $msg;
310
+
311
+							$foo = function() {
312
+
313
+								$foo = 1;
314
+								$barbar=2;
315
+							};
316
+							$barbar = function() {
317
+								$foo    = 1;
318
+								$barbar = 2;
319
+							};
320
+						});
321
+						$a = $msg;
322
+						$foobar      = $msg;
323
+					};
324
+					$bar = $msg;
325
+				}
326
+
327
+				public function log2($msg)
328
+				{
329
+					$a = $msg;
330
+					$foobar = $msg;
331
+					$foo = function() {
332
+						foo(function() {
333
+							foo(function() {
334
+								echo 'hi';
335
+							});
336
+							$a = $msg;
337
+							$foobar = $msg;
338
+
339
+							$foo = function() {
340
+
341
+								$foo = 1;
342
+								$barbar=2;
343
+							};
344
+							$barbar = function() {
345
+								$foo    = 1;
346
+								$barbar = 2;
347
+							};
348
+						});
349
+						$a = $msg;
350
+						$foobar      = $msg;
351
+					};
352
+					$bar = $msg;
353
+				}
354
+			});
355
+			$foo          = 5;
356
+		};
357
+		$bar = $msg;
358
+	}
359 359
 });
360 360
 $foo          = 5;
361 361
 
362 362
 $foo = [
363
-    0 => function () {
364
-        $foo = 'foo';
365
-        $barbar = 'bar';
366
-    },
367
-    1 => function () {
368
-        $foo    = 'foo';
369
-        $barbar = 'bar';
370
-    },
363
+	0 => function () {
364
+		$foo = 'foo';
365
+		$barbar = 'bar';
366
+	},
367
+	1 => function () {
368
+		$foo    = 'foo';
369
+		$barbar = 'bar';
370
+	},
371 371
 ];
372 372
 
373 373
 $abc = 'something';
@@ -375,31 +375,31 @@  discard block
 block discarded – undo
375 375
 $defghi = 'longer something';
376 376
 
377 377
 function foo() {
378
-    $foo = 'foo';
379
-    $bar = 'bar';
380
-    ?>
378
+	$foo = 'foo';
379
+	$bar = 'bar';
380
+	?>
381 381
 
382 382
     <div>
383 383
         <?php
384
-        $foo = 'foo';
385
-        $bar = 'bar';
386
-        ?>
384
+		$foo = 'foo';
385
+		$bar = 'bar';
386
+		?>
387 387
     </div>
388 388
     <?php
389 389
 }
390 390
 
391 391
 $foo = new Foo([
392
-    $a = new Bar(),
393
-    $b = new Bar(),
392
+	$a = new Bar(),
393
+	$b = new Bar(),
394 394
 ]);
395 395
 
396 396
 $foo = new Foo([
397
-    $a = new Bar(),
398
-    $b    = new Bar(),
399
-    $c  = new Bar(),
397
+	$a = new Bar(),
398
+	$b    = new Bar(),
399
+	$c  = new Bar(),
400 400
 ]);
401 401
 $foofoo   = new Foo([
402
-    $a = new Bar(),
403
-    $b = new Bar(),
404
-    $c = new Bar(),
402
+	$a = new Bar(),
403
+	$b = new Bar(),
404
+	$c = new Bar(),
405 405
 ]);
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
 // Invalid
36 36
 $var1    .= 'var1';
37
-$var10.= 'var1';
37
+$var10 .= 'var1';
38 38
 $var100 .= 'var1';
39 39
 $var1000 .= 'var1';
40 40
 
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
 // Invalid
48 48
 $var1    = 'var1';
49
-$var10   .= 'var1';
49
+$var10 .= 'var1';
50 50
 $var100  = 'var1';
51
-$var1000.= 'var1';
51
+$var1000 .= 'var1';
52 52
 
53 53
 // Valid
54 54
 $var1  .= 'var1';
@@ -68,43 +68,43 @@  discard block
 block discarded – undo
68 68
 $var = 100;
69 69
 
70 70
 // InValid
71
-$var  = 100;
71
+$var = 100;
72 72
 
73 73
 $commentStart = $phpcsFile->findPrevious();
74 74
 $commentEnd   = $this->_phpcsFile;
75 75
 $expected    .= '...';
76 76
 
77 77
 // Invalid
78
-$this->okButton    = new Button();
78
+$this->okButton = new Button();
79 79
 $content = new MyClass();
80 80
 
81 81
 
82
-$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
82
+$GLOBALS[ '_PEAR_ERRORSTACK_SINGLETON' ] = array();
83 83
 
84 84
 class MyClass
85 85
 {
86 86
     const MODE_DEBUG = 'debug';
87 87
     const MODE_DEBUG2 = 'debug';
88 88
 
89
-    var $array[$test] = 'anything';
89
+    var $array[ $test ] = 'anything';
90 90
     var $var          = 'anything';
91 91
 
92
-    const MODE_DEBUG3  = 'debug';
93
-    public $array[$test]    = 'anything';
94
-    private $vara             = 'anything';
95
-    protected $array[($test + 1)] = 'anything';
96
-    var $array[($blah + (10 - $test))] = 'anything';
92
+    const MODE_DEBUG3 = 'debug';
93
+    public $array[ $test ] = 'anything';
94
+    private $vara = 'anything';
95
+    protected $array[ ( $test + 1 ) ] = 'anything';
96
+    var $array[ ( $blah + ( 10 - $test ) ) ] = 'anything';
97 97
 }
98 98
 
99
-function myFunction($var=true)
99
+function myFunction( $var = true )
100 100
 {
101
-    if ($strict === true) {
102
-        $length          = strlen($string);
103
-        $lastCharWasCaps = ($classFormat === false) ? false : true;
101
+    if ( $strict === true ) {
102
+        $length          = strlen( $string );
103
+        $lastCharWasCaps = ( $classFormat === false ) ? false : true;
104 104
 
105
-        for ($i = 1; $i < $length; $i++) {
106
-            $isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
107
-            if ($isCaps === true && $lastCharWasCaps === true) {
105
+        for ( $i = 1; $i < $length; $i++ ) {
106
+            $isCaps = ( strtoupper( $string{$i}) === $string{$i}) ? true : false;
107
+            if ( $isCaps === true && $lastCharWasCaps === true ) {
108 108
                 return false;
109 109
             }
110 110
 
@@ -114,29 +114,29 @@  discard block
 block discarded – undo
114 114
 }
115 115
 
116 116
 // Valid
117
-for ($i = 0; $i < 10; $i += 2) {
118
-    $i = ($i - 1);
117
+for ( $i = 0; $i < 10; $i += 2 ) {
118
+    $i = ( $i - 1 );
119 119
 }
120 120
 
121 121
 // Invalid
122
-foreach ($files as $file) {
123
-    $saves[$file] = array();
124
-    $contents = stripslashes(file_get_contents($file));
125
-    list($assetid, $time, $content) = explode("\n", $contents);
126
-    $saves[$file]['assetid'] = $assetid;
122
+foreach ( $files as $file ) {
123
+    $saves[ $file ] = array();
124
+    $contents = stripslashes( file_get_contents( $file ) );
125
+    list( $assetid, $time, $content ) = explode( "\n", $contents );
126
+    $saves[ $file ][ 'assetid' ] = $assetid;
127 127
 }
128 128
 
129
-$i = ($i - 10);
130
-$ip = ($i - 10);
131
-for ($i = 0; $i < 10; $i += 2) {
132
-    $i = ($i - 10);
129
+$i = ( $i - 10 );
130
+$ip = ( $i - 10 );
131
+for ( $i = 0; $i < 10; $i += 2 ) {
132
+    $i = ( $i - 10 );
133 133
 }
134 134
 
135 135
 // Valid
136 136
 $variable = 12;
137
-$var      = a_very(long_line('that', 'contains'),
138
-                   a_bunch('of long', 'parameters'),
139
-                   'that_need to be aligned with the equal sign');
137
+$var      = a_very( long_line( 'that', 'contains' ),
138
+                   a_bunch( 'of long', 'parameters' ),
139
+                   'that_need to be aligned with the equal sign' );
140 140
 $var2     = 12;
141 141
 
142 142
 // Valid
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 
149 149
 // Invalid
150 150
 $variable = 12;
151
-$var      = a_very(long_line('that', 'contains'),
152
-                   a_bunch('of long', 'parameters'),
153
-                   'that_need to be aligned with the equal sign');
151
+$var      = a_very( long_line( 'that', 'contains' ),
152
+                   a_bunch( 'of long', 'parameters' ),
153
+                   'that_need to be aligned with the equal sign' );
154 154
 $var2 = 12;
155 155
 
156 156
 // Invalid
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
 
184 184
 // Valid
185 185
 $error = false;
186
-while (list($h, $f) = getKeyAndValue($handle)) {
186
+while ( list( $h, $f ) = getKeyAndValue( $handle ) ) {
187 187
     $error = true;
188 188
 }
189 189
 
190 190
 // Valid
191 191
 $value = false;
192
-function blah ($value = true) {
192
+function blah( $value = true ) {
193 193
     $value = false;
194
-    if ($value === true) {
194
+    if ( $value === true ) {
195 195
         $value = false;
196 196
     }
197 197
 }
198 198
 
199
-if (TRUE) {
200
-    $args = array('foo' => 'foo');
199
+if ( TRUE ) {
200
+    $args = array( 'foo' => 'foo' );
201 201
     $res  = 'bar';
202 202
 }
203 203
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 
218 218
 // phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000
219 219
 
220
-$filterQuery = SquizRoadmap::getSearchQueryFilter($searchParams);
221
-Channels::addToBasket('itemid', $filterQuery);
222
-$query   = DAL::getDALQuery('SquizRoadmapItem', 'getItemIds');
223
-$results = DAL::getAssoc($query, 0);
220
+$filterQuery = SquizRoadmap::getSearchQueryFilter( $searchParams );
221
+Channels::addToBasket( 'itemid', $filterQuery );
222
+$query   = DAL::getDALQuery( 'SquizRoadmapItem', 'getItemIds' );
223
+$results = DAL::getAssoc( $query, 0 );
224 224
 
225
-$path  = BaseSystem::getDataDir('SquizRoadmap').'/items/';
226
-$path .= FileSystem::getHashDir($itemid).'/'.$itemid;
225
+$path  = BaseSystem::getDataDir( 'SquizRoadmap' ) . '/items/';
226
+$path .= FileSystem::getHashDir( $itemid ) . '/' . $itemid;
227 227
 
228 228
 $contents  .= 'if (';
229 229
 $conditions = array();
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 $foo = $moooo = 'foo';
235 235
 
236 236
 $foobarbaz = array_map(
237
-    function ($n) {
237
+    function( $n ) {
238 238
         return $n * $n;
239 239
     },
240
-    [1, 2, 3]
240
+    [ 1, 2, 3 ]
241 241
 );
242
-$foo       = 5;
242
+$foo = 5;
243 243
 
244
-$loggerResult = $util->setLogger(new class {
245
-    public function log($msg)
244
+$loggerResult = $util->setLogger( new class {
245
+    public function log( $msg )
246 246
     {
247 247
         echo $msg;
248 248
     }
249 249
 });
250
-$foo          = 5;
250
+$foo = 5;
251 251
 
252 252
 $foo = array(
253 253
     'a' => 'b',
@@ -272,37 +272,37 @@  discard block
 block discarded – undo
272 272
 ];
273 273
 $barbar = 'bar';
274 274
 
275
-function buildForm(FormBuilderInterface $builder, array $options)
275
+function buildForm( FormBuilderInterface $builder, array $options )
276 276
 {
277
-    $transformer = new ContractTransformer($options['contracts']);
278
-    $types       = ['support.contact.question' => ContactData::QUESTION];
277
+    $transformer = new ContractTransformer( $options[ 'contracts' ] );
278
+    $types       = [ 'support.contact.question' => ContactData::QUESTION ];
279 279
 
280
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
280
+    [ $important, $questions, $incidents, $requests ] = $this->createContractBuckets( $options[ 'contracts' ] );
281 281
 }
282 282
 
283
-function buildForm(FormBuilderInterface $builder, array $options)
283
+function buildForm( FormBuilderInterface $builder, array $options )
284 284
 {
285
-    $transformer                                    = new ContractTransformer($options['contracts']);
286
-    $types                                          = ['support.contact.question' => ContactData::QUESTION];
287
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
285
+    $transformer                                    = new ContractTransformer( $options[ 'contracts' ] );
286
+    $types                                          = [ 'support.contact.question' => ContactData::QUESTION ];
287
+    [ $important, $questions, $incidents, $requests ] = $this->createContractBuckets( $options[ 'contracts' ] );
288 288
 }
289 289
 
290
-$loggerResult = $util->setLogger(new class {
291
-    public function log($msg)
290
+$loggerResult = $util->setLogger( new class {
291
+    public function log( $msg )
292 292
     {
293 293
         $a = $msg;
294 294
         $foobar = $msg;
295 295
         $foo = function() {
296 296
             $a = $msg;
297 297
             $foobar = $msg;
298
-            $loggerResult = $util->setLogger(new class {
299
-                public function log($msg)
298
+            $loggerResult = $util->setLogger( new class {
299
+                public function log( $msg )
300 300
                 {
301 301
                     $a = $msg;
302 302
                     $foobar = $msg;
303 303
                     $foo = function() {
304
-                        foo(function() {
305
-                            foo(function() {
304
+                        foo( function() {
305
+                            foo( function() {
306 306
                                 echo 'hi';
307 307
                             });
308 308
                             $a = $msg;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                             $foo = function() {
312 312
 
313 313
                                 $foo = 1;
314
-                                $barbar=2;
314
+                                $barbar = 2;
315 315
                             };
316 316
                             $barbar = function() {
317 317
                                 $foo    = 1;
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
                             };
320 320
                         });
321 321
                         $a = $msg;
322
-                        $foobar      = $msg;
322
+                        $foobar = $msg;
323 323
                     };
324 324
                     $bar = $msg;
325 325
                 }
326 326
 
327
-                public function log2($msg)
327
+                public function log2( $msg )
328 328
                 {
329 329
                     $a = $msg;
330 330
                     $foobar = $msg;
331 331
                     $foo = function() {
332
-                        foo(function() {
333
-                            foo(function() {
332
+                        foo( function() {
333
+                            foo( function() {
334 334
                                 echo 'hi';
335 335
                             });
336 336
                             $a = $msg;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
                             $foo = function() {
340 340
 
341 341
                                 $foo = 1;
342
-                                $barbar=2;
342
+                                $barbar = 2;
343 343
                             };
344 344
                             $barbar = function() {
345 345
                                 $foo    = 1;
@@ -347,31 +347,31 @@  discard block
 block discarded – undo
347 347
                             };
348 348
                         });
349 349
                         $a = $msg;
350
-                        $foobar      = $msg;
350
+                        $foobar = $msg;
351 351
                     };
352 352
                     $bar = $msg;
353 353
                 }
354 354
             });
355
-            $foo          = 5;
355
+            $foo = 5;
356 356
         };
357 357
         $bar = $msg;
358 358
     }
359 359
 });
360
-$foo          = 5;
360
+$foo = 5;
361 361
 
362 362
 $foo = [
363
-    0 => function () {
363
+    0 => function() {
364 364
         $foo = 'foo';
365 365
         $barbar = 'bar';
366 366
     },
367
-    1 => function () {
367
+    1 => function() {
368 368
         $foo    = 'foo';
369 369
         $barbar = 'bar';
370 370
     },
371 371
 ];
372 372
 
373 373
 $abc = 'something';
374
-if ($foo) {}
374
+if ( $foo ) {}
375 375
 $defghi = 'longer something';
376 376
 
377 377
 function foo() {
@@ -388,18 +388,18 @@  discard block
 block discarded – undo
388 388
     <?php
389 389
 }
390 390
 
391
-$foo = new Foo([
391
+$foo = new Foo( [
392 392
     $a = new Bar(),
393 393
     $b = new Bar(),
394
-]);
394
+] );
395 395
 
396
-$foo = new Foo([
396
+$foo = new Foo( [
397 397
     $a = new Bar(),
398 398
     $b    = new Bar(),
399
-    $c  = new Bar(),
400
-]);
401
-$foofoo   = new Foo([
399
+    $c = new Bar(),
400
+] );
401
+$foofoo   = new Foo( [
402 402
     $a = new Bar(),
403 403
     $b = new Bar(),
404 404
     $c = new Bar(),
405
-]);
405
+] );
Please login to merge, or discard this patch.
Braces   +8 added lines, -16 removed lines patch added patch discarded remove patch
@@ -81,8 +81,7 @@  discard block
 block discarded – undo
81 81
 
82 82
 $GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
83 83
 
84
-class MyClass
85
-{
84
+class MyClass {
86 85
     const MODE_DEBUG = 'debug';
87 86
     const MODE_DEBUG2 = 'debug';
88 87
 
@@ -96,8 +95,7 @@  discard block
 block discarded – undo
96 95
     var $array[($blah + (10 - $test))] = 'anything';
97 96
 }
98 97
 
99
-function myFunction($var=true)
100
-{
98
+function myFunction($var=true) {
101 99
     if ($strict === true) {
102 100
         $length          = strlen($string);
103 101
         $lastCharWasCaps = ($classFormat === false) ? false : true;
@@ -242,8 +240,7 @@  discard block
 block discarded – undo
242 240
 $foo       = 5;
243 241
 
244 242
 $loggerResult = $util->setLogger(new class {
245
-    public function log($msg)
246
-    {
243
+    public function log($msg) {
247 244
         echo $msg;
248 245
     }
249 246
 });
@@ -272,32 +269,28 @@  discard block
 block discarded – undo
272 269
 ];
273 270
 $barbar = 'bar';
274 271
 
275
-function buildForm(FormBuilderInterface $builder, array $options)
276
-{
272
+function buildForm(FormBuilderInterface $builder, array $options) {
277 273
     $transformer = new ContractTransformer($options['contracts']);
278 274
     $types       = ['support.contact.question' => ContactData::QUESTION];
279 275
 
280 276
     [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
281 277
 }
282 278
 
283
-function buildForm(FormBuilderInterface $builder, array $options)
284
-{
279
+function buildForm(FormBuilderInterface $builder, array $options) {
285 280
     $transformer                                    = new ContractTransformer($options['contracts']);
286 281
     $types                                          = ['support.contact.question' => ContactData::QUESTION];
287 282
     [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
288 283
 }
289 284
 
290 285
 $loggerResult = $util->setLogger(new class {
291
-    public function log($msg)
292
-    {
286
+    public function log($msg) {
293 287
         $a = $msg;
294 288
         $foobar = $msg;
295 289
         $foo = function() {
296 290
             $a = $msg;
297 291
             $foobar = $msg;
298 292
             $loggerResult = $util->setLogger(new class {
299
-                public function log($msg)
300
-                {
293
+                public function log($msg) {
301 294
                     $a = $msg;
302 295
                     $foobar = $msg;
303 296
                     $foo = function() {
@@ -324,8 +317,7 @@  discard block
 block discarded – undo
324 317
                     $bar = $msg;
325 318
                 }
326 319
 
327
-                public function log2($msg)
328
-                {
320
+                public function log2($msg) {
329 321
                     $a = $msg;
330 322
                     $foobar = $msg;
331 323
                     $foo = function() {
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.php 3 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -15,58 +15,58 @@
 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 [
29
-            3  => 1,
30
-            5  => 1,
31
-            7  => 1,
32
-            9  => 1,
33
-            11 => 1,
34
-            13 => 1,
35
-            15 => 1,
36
-            17 => 1,
37
-            19 => 1,
38
-            21 => 1,
39
-            23 => 1,
40
-            25 => 1,
41
-            27 => 1,
42
-            29 => 1,
43
-            31 => 1,
44
-            33 => 1,
45
-            35 => 1,
46
-            37 => 1,
47
-            39 => 1,
48
-            41 => 1,
49
-            43 => 1,
50
-            45 => 1,
51
-            50 => 1,
52
-        ];
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
+			3  => 1,
30
+			5  => 1,
31
+			7  => 1,
32
+			9  => 1,
33
+			11 => 1,
34
+			13 => 1,
35
+			15 => 1,
36
+			17 => 1,
37
+			19 => 1,
38
+			21 => 1,
39
+			23 => 1,
40
+			25 => 1,
41
+			27 => 1,
42
+			29 => 1,
43
+			31 => 1,
44
+			33 => 1,
45
+			35 => 1,
46
+			37 => 1,
47
+			39 => 1,
48
+			41 => 1,
49
+			43 => 1,
50
+			45 => 1,
51
+			50 => 1,
52
+		];
53 53
 
54
-    }//end getErrorList()
54
+	}//end getErrorList()
55 55
 
56 56
 
57
-    /**
58
-     * Returns the lines where warnings should occur.
59
-     *
60
-     * The key of the array should represent the line number and the value
61
-     * should represent the number of warnings that should occur on that line.
62
-     *
63
-     * @return array<int, int>
64
-     */
65
-    public function getWarningList()
66
-    {
67
-        return [];
57
+	/**
58
+	 * Returns the lines where warnings should occur.
59
+	 *
60
+	 * The key of the array should represent the line number and the value
61
+	 * should represent the number of warnings that should occur on that line.
62
+	 *
63
+	 * @return array<int, int>
64
+	 */
65
+	public function getWarningList()
66
+	{
67
+		return [];
68 68
 
69
-    }//end getWarningList()
69
+	}//end getWarningList()
70 70
 
71 71
 
72 72
 }//end class
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function getWarningList()
66 66
     {
67
-        return [];
67
+        return [ ];
68 68
 
69 69
     }//end getWarningList()
70 70
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
13 13
 
14
-class NoSpaceAfterCastUnitTest extends AbstractSniffUnitTest
15
-{
14
+class NoSpaceAfterCastUnitTest extends AbstractSniffUnitTest {
16 15
 
17 16
 
18 17
     /**
@@ -23,8 +22,7 @@  discard block
 block discarded – undo
23 22
      *
24 23
      * @return array<int, int>
25 24
      */
26
-    public function getErrorList()
27
-    {
25
+    public function getErrorList() {
28 26
         return [
29 27
             3  => 1,
30 28
             5  => 1,
@@ -62,8 +60,7 @@  discard block
 block discarded – undo
62 60
      *
63 61
      * @return array<int, int>
64 62
      */
65
-    public function getWarningList()
66
-    {
63
+    public function getWarningList() {
67 64
         return [];
68 65
 
69 66
     }//end getWarningList()
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/SpaceBeforeCastUnitTest.inc 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
 $var = array(
59 59
 	(bool) $a,
60 60
 	array(
61
-        (int) $b,
61
+		(int) $b,
62 62
 	),
63 63
 );
64 64
 
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$a = $a+(bool) $b;
4
-$a = function_call((bool) $b);
5
-if ((bool) $a ===(bool) $b) {}
3
+$a = $a + (bool)$b;
4
+$a = function_call( (bool)$b );
5
+if ( (bool)$a === (bool)$b ) {}
6 6
 
7
-$var = (int) $var2;
8
-$var =(int) $var2;
9
-$var =     (int) $var2;
7
+$var = (int)$var2;
8
+$var = (int)$var2;
9
+$var = (int)$var2;
10 10
 
11
-$var = (integer) $var2;
12
-$var =(integer) $var2;
13
-$var =    (integer) $var2;
11
+$var = (integer)$var2;
12
+$var = (integer)$var2;
13
+$var = (integer)$var2;
14 14
 
15
-$var = (string) $var2;
16
-$var =(string) $var2;
17
-$var =	 (string) $var2;
15
+$var = (string)$var2;
16
+$var = (string)$var2;
17
+$var = (string)$var2;
18 18
 
19
-$var = (float) $var2;
20
-$var =(float) $var2;
21
-$var =			 (float) $var2;
19
+$var = (float)$var2;
20
+$var = (float)$var2;
21
+$var = (float)$var2;
22 22
 
23
-$var = (double) $var2;
24
-$var =(double) $var2;
25
-$var =  (double) $var2;
23
+$var = (double)$var2;
24
+$var = (double)$var2;
25
+$var = (double)$var2;
26 26
 
27
-$var = (real) $var2;
28
-$var =(real) $var2;
29
-$var =    (real) $var2;
27
+$var = (real)$var2;
28
+$var = (real)$var2;
29
+$var = (real)$var2;
30 30
 
31
-$var = (array) $var2;
32
-$var =(array) $var2;
33
-$var =   (array) $var2;
31
+$var = (array)$var2;
32
+$var = (array)$var2;
33
+$var = (array)$var2;
34 34
 
35
-$var = (bool) $var2;
36
-$var =(bool) $var2;
37
-$var =    (bool) $var2;
35
+$var = (bool)$var2;
36
+$var = (bool)$var2;
37
+$var = (bool)$var2;
38 38
 
39
-$var = (boolean) $var2;
40
-$var =(boolean) $var2;
41
-$var =  (boolean) $var2;
39
+$var = (boolean)$var2;
40
+$var = (boolean)$var2;
41
+$var = (boolean)$var2;
42 42
 
43
-$var = (object) $var2;
44
-$var =(object) $var2;
45
-$var =  (object) $var2;
43
+$var = (object)$var2;
44
+$var = (object)$var2;
45
+$var = (object)$var2;
46 46
 
47
-$var = (unset) $var2;
48
-$var =(unset) $var2;
49
-$var =   (unset) $var2;
47
+$var = (unset)$var2;
48
+$var = (unset)$var2;
49
+$var = (unset)$var2;
50 50
 
51 51
 $var = b"binary $foo";
52
-$var =b"binary string";
53
-$var =   b'binary string';
54
-$var = (binary) $string;
55
-$var =(binary) $string;
56
-$var =    (binary) $string;
52
+$var = b"binary string";
53
+$var = b'binary string';
54
+$var = (binary)$string;
55
+$var = (binary)$string;
56
+$var = (binary)$string;
57 57
 
58 58
 $var = array(
59
-	(bool) $a,
59
+	(bool)$a,
60 60
 	array(
61
-        (int) $b,
61
+        (int)$b,
62 62
 	),
63 63
 );
64 64
 
65
-(bool) $a ? echo $b : echo $c;
65
+(bool)$a ? echo $b : echo $c;
Please login to merge, or discard this patch.
Standards/Generic/Tests/Formatting/DisallowMultipleStatementsUnitTest.php 3 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,40 +15,40 @@
 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 [
29
-            2  => 1,
30
-            6  => 1,
31
-            7  => 1,
32
-            8  => 2,
33
-            16 => 2,
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
+			2  => 1,
30
+			6  => 1,
31
+			7  => 1,
32
+			8  => 2,
33
+			16 => 2,
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
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
13 13
 
14
-class DisallowMultipleStatementsUnitTest extends AbstractSniffUnitTest
15
-{
14
+class DisallowMultipleStatementsUnitTest extends AbstractSniffUnitTest {
16 15
 
17 16
 
18 17
     /**
@@ -23,8 +22,7 @@  discard block
 block discarded – undo
23 22
      *
24 23
      * @return array<int, int>
25 24
      */
26
-    public function getErrorList()
27
-    {
25
+    public function getErrorList() {
28 26
         return [
29 27
             2  => 1,
30 28
             6  => 1,
@@ -44,8 +42,7 @@  discard block
 block discarded – undo
44 42
      *
45 43
      * @return array<int, int>
46 44
      */
47
-    public function getWarningList()
48
-    {
45
+    public function getWarningList() {
49 46
         return [];
50 47
 
51 48
     }//end getWarningList()
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function getWarningList()
66 66
     {
67
-        return [];
67
+        return [ ];
68 68
 
69 69
     }//end getWarningList()
70 70
 
Please login to merge, or discard this patch.