Completed
Pull Request — develop (#1492)
by Zack
15:57
created
Sniffs/FunctionDeclarations/ForbiddenParametersWithSameNameSniff.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -29,58 +29,58 @@
 block discarded – undo
29 29
 class ForbiddenParametersWithSameNameSniff extends Sniff
30 30
 {
31 31
 
32
-    /**
33
-     * Returns an array of tokens this test wants to listen for.
34
-     *
35
-     * @return array
36
-     */
37
-    public function register()
38
-    {
39
-        return array(
40
-            \T_FUNCTION,
41
-            \T_CLOSURE,
42
-        );
43
-    }
32
+	/**
33
+	 * Returns an array of tokens this test wants to listen for.
34
+	 *
35
+	 * @return array
36
+	 */
37
+	public function register()
38
+	{
39
+		return array(
40
+			\T_FUNCTION,
41
+			\T_CLOSURE,
42
+		);
43
+	}
44 44
 
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
-     * @param int                   $stackPtr  The position of the current token
50
-     *                                         in the stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        if ($this->supportsAbove('7.0') === false) {
57
-            return;
58
-        }
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
49
+	 * @param int                   $stackPtr  The position of the current token
50
+	 *                                         in the stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		if ($this->supportsAbove('7.0') === false) {
57
+			return;
58
+		}
59 59
 
60
-        $tokens = $phpcsFile->getTokens();
61
-        $token  = $tokens[$stackPtr];
62
-        // Skip function without body.
63
-        if (isset($token['scope_opener']) === false) {
64
-            return;
65
-        }
60
+		$tokens = $phpcsFile->getTokens();
61
+		$token  = $tokens[$stackPtr];
62
+		// Skip function without body.
63
+		if (isset($token['scope_opener']) === false) {
64
+			return;
65
+		}
66 66
 
67
-        // Get all parameters from method signature.
68
-        $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
69
-        if (empty($parameters) || \is_array($parameters) === false) {
70
-            return;
71
-        }
67
+		// Get all parameters from method signature.
68
+		$parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
69
+		if (empty($parameters) || \is_array($parameters) === false) {
70
+			return;
71
+		}
72 72
 
73
-        $paramNames = array();
74
-        foreach ($parameters as $param) {
75
-            $paramNames[] = strtolower($param['name']);
76
-        }
73
+		$paramNames = array();
74
+		foreach ($parameters as $param) {
75
+			$paramNames[] = strtolower($param['name']);
76
+		}
77 77
 
78
-        if (\count($paramNames) !== \count(array_unique($paramNames))) {
79
-            $phpcsFile->addError(
80
-                'Functions can not have multiple parameters with the same name since PHP 7.0',
81
-                $stackPtr,
82
-                'Found'
83
-            );
84
-        }
85
-    }
78
+		if (\count($paramNames) !== \count(array_unique($paramNames))) {
79
+			$phpcsFile->addError(
80
+				'Functions can not have multiple parameters with the same name since PHP 7.0',
81
+				$stackPtr,
82
+				'Found'
83
+			);
84
+		}
85
+	}
86 86
 }
Please login to merge, or discard this patch.
Sniffs/FunctionDeclarations/NewExceptionsFromToStringSniff.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -25,76 +25,76 @@
 block discarded – undo
25 25
 class NewExceptionsFromToStringSniff extends Sniff
26 26
 {
27 27
 
28
-    /**
29
-     * Valid scopes for the __toString() method to live in.
30
-     *
31
-     * @since 9.2.0
32
-     *
33
-     * @var array
34
-     */
35
-    public $ooScopeTokens = array(
36
-        'T_CLASS'      => true,
37
-        'T_TRAIT'      => true,
38
-        'T_ANON_CLASS' => true,
39
-    );
28
+	/**
29
+	 * Valid scopes for the __toString() method to live in.
30
+	 *
31
+	 * @since 9.2.0
32
+	 *
33
+	 * @var array
34
+	 */
35
+	public $ooScopeTokens = array(
36
+		'T_CLASS'      => true,
37
+		'T_TRAIT'      => true,
38
+		'T_ANON_CLASS' => true,
39
+	);
40 40
 
41
-    /**
42
-     * Returns an array of tokens this test wants to listen for.
43
-     *
44
-     * @since 9.2.0
45
-     *
46
-     * @return array
47
-     */
48
-    public function register()
49
-    {
50
-        return array(\T_FUNCTION);
51
-    }
41
+	/**
42
+	 * Returns an array of tokens this test wants to listen for.
43
+	 *
44
+	 * @since 9.2.0
45
+	 *
46
+	 * @return array
47
+	 */
48
+	public function register()
49
+	{
50
+		return array(\T_FUNCTION);
51
+	}
52 52
 
53
-    /**
54
-     * Processes this test, when one of its tokens is encountered.
55
-     *
56
-     * @since 9.2.0
57
-     *
58
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
-     * @param int                   $stackPtr  The position of the current token
60
-     *                                         in the stack passed in $tokens.
61
-     *
62
-     * @return void
63
-     */
64
-    public function process(File $phpcsFile, $stackPtr)
65
-    {
66
-        if ($this->supportsBelow('7.3') === false) {
67
-            return;
68
-        }
53
+	/**
54
+	 * Processes this test, when one of its tokens is encountered.
55
+	 *
56
+	 * @since 9.2.0
57
+	 *
58
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
+	 * @param int                   $stackPtr  The position of the current token
60
+	 *                                         in the stack passed in $tokens.
61
+	 *
62
+	 * @return void
63
+	 */
64
+	public function process(File $phpcsFile, $stackPtr)
65
+	{
66
+		if ($this->supportsBelow('7.3') === false) {
67
+			return;
68
+		}
69 69
 
70
-        $tokens = $phpcsFile->getTokens();
71
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
72
-            // Abstract function, interface function, live coding or parse error.
73
-            return;
74
-        }
70
+		$tokens = $phpcsFile->getTokens();
71
+		if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
72
+			// Abstract function, interface function, live coding or parse error.
73
+			return;
74
+		}
75 75
 
76
-        $functionName = $phpcsFile->getDeclarationName($stackPtr);
77
-        if (strtolower($functionName) !== '__tostring') {
78
-            // Not the right function.
79
-            return;
80
-        }
76
+		$functionName = $phpcsFile->getDeclarationName($stackPtr);
77
+		if (strtolower($functionName) !== '__tostring') {
78
+			// Not the right function.
79
+			return;
80
+		}
81 81
 
82
-        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) {
83
-            // Function, not method.
84
-            return;
85
-        }
82
+		if ($this->validDirectScope($phpcsFile, $stackPtr, $this->ooScopeTokens) === false) {
83
+			// Function, not method.
84
+			return;
85
+		}
86 86
 
87
-        $hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']);
87
+		$hasThrow = $phpcsFile->findNext(\T_THROW, ($tokens[$stackPtr]['scope_opener'] + 1), $tokens[$stackPtr]['scope_closer']);
88 88
 
89
-        if ($hasThrow === false) {
90
-            // No exception is being thrown.
91
-            return;
92
-        }
89
+		if ($hasThrow === false) {
90
+			// No exception is being thrown.
91
+			return;
92
+		}
93 93
 
94
-        $phpcsFile->addError(
95
-            'Throwing exceptions from __toString() was not allowed prior to PHP 7.4',
96
-            $hasThrow,
97
-            'Found'
98
-        );
99
-    }
94
+		$phpcsFile->addError(
95
+			'Throwing exceptions from __toString() was not allowed prior to PHP 7.4',
96
+			$hasThrow,
97
+			'Found'
98
+		);
99
+	}
100 100
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/FunctionDeclarations/NewClosureSniff.php 1 patch
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -28,210 +28,210 @@
 block discarded – undo
28 28
  */
29 29
 class NewClosureSniff extends Sniff
30 30
 {
31
-    /**
32
-     * Returns an array of tokens this test wants to listen for.
33
-     *
34
-     * @return array
35
-     */
36
-    public function register()
37
-    {
38
-        return array(\T_CLOSURE);
39
-    }
40
-
41
-    /**
42
-     * Processes this test, when one of its tokens is encountered.
43
-     *
44
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
-     * @param int                   $stackPtr  The position of the current token
46
-     *                                         in the stack passed in $tokens.
47
-     *
48
-     * @return void
49
-     */
50
-    public function process(File $phpcsFile, $stackPtr)
51
-    {
52
-        if ($this->supportsBelow('5.2')) {
53
-            $phpcsFile->addError(
54
-                'Closures / anonymous functions are not available in PHP 5.2 or earlier',
55
-                $stackPtr,
56
-                'Found'
57
-            );
58
-        }
59
-
60
-        /*
31
+	/**
32
+	 * Returns an array of tokens this test wants to listen for.
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function register()
37
+	{
38
+		return array(\T_CLOSURE);
39
+	}
40
+
41
+	/**
42
+	 * Processes this test, when one of its tokens is encountered.
43
+	 *
44
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
+	 * @param int                   $stackPtr  The position of the current token
46
+	 *                                         in the stack passed in $tokens.
47
+	 *
48
+	 * @return void
49
+	 */
50
+	public function process(File $phpcsFile, $stackPtr)
51
+	{
52
+		if ($this->supportsBelow('5.2')) {
53
+			$phpcsFile->addError(
54
+				'Closures / anonymous functions are not available in PHP 5.2 or earlier',
55
+				$stackPtr,
56
+				'Found'
57
+			);
58
+		}
59
+
60
+		/*
61 61
          * Closures can only be declared as static since PHP 5.4.
62 62
          */
63
-        $isStatic = $this->isClosureStatic($phpcsFile, $stackPtr);
64
-        if ($this->supportsBelow('5.3') && $isStatic === true) {
65
-            $phpcsFile->addError(
66
-                'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier',
67
-                $stackPtr,
68
-                'StaticFound'
69
-            );
70
-        }
71
-
72
-        $tokens = $phpcsFile->getTokens();
73
-
74
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
75
-            // Live coding or parse error.
76
-            return;
77
-        }
78
-
79
-        $scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1);
80
-        $scopeEnd   = $tokens[$stackPtr]['scope_closer'];
81
-        $usesThis   = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
82
-
83
-        if ($this->supportsBelow('5.3')) {
84
-            /*
63
+		$isStatic = $this->isClosureStatic($phpcsFile, $stackPtr);
64
+		if ($this->supportsBelow('5.3') && $isStatic === true) {
65
+			$phpcsFile->addError(
66
+				'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier',
67
+				$stackPtr,
68
+				'StaticFound'
69
+			);
70
+		}
71
+
72
+		$tokens = $phpcsFile->getTokens();
73
+
74
+		if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
75
+			// Live coding or parse error.
76
+			return;
77
+		}
78
+
79
+		$scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1);
80
+		$scopeEnd   = $tokens[$stackPtr]['scope_closer'];
81
+		$usesThis   = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
82
+
83
+		if ($this->supportsBelow('5.3')) {
84
+			/*
85 85
              * Closures declared within classes only have access to $this since PHP 5.4.
86 86
              */
87
-            if ($usesThis !== false) {
88
-                $thisFound = $usesThis;
89
-                do {
90
-                    $phpcsFile->addError(
91
-                        'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier',
92
-                        $thisFound,
93
-                        'ThisFound'
94
-                    );
87
+			if ($usesThis !== false) {
88
+				$thisFound = $usesThis;
89
+				do {
90
+					$phpcsFile->addError(
91
+						'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier',
92
+						$thisFound,
93
+						'ThisFound'
94
+					);
95 95
 
96
-                    $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
96
+					$thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
97 97
 
98
-                } while ($thisFound !== false);
99
-            }
98
+				} while ($thisFound !== false);
99
+			}
100 100
 
101
-            /*
101
+			/*
102 102
              * Closures declared within classes only have access to self/parent/static since PHP 5.4.
103 103
              */
104
-            $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
104
+			$usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd);
105 105
 
106
-            if ($usesClassRef !== false) {
107
-                do {
108
-                    $phpcsFile->addError(
109
-                        'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier',
110
-                        $usesClassRef,
111
-                        'ClassRefFound',
112
-                        array(strtolower($tokens[$usesClassRef]['content']))
113
-                    );
106
+			if ($usesClassRef !== false) {
107
+				do {
108
+					$phpcsFile->addError(
109
+						'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier',
110
+						$usesClassRef,
111
+						'ClassRefFound',
112
+						array(strtolower($tokens[$usesClassRef]['content']))
113
+					);
114 114
 
115
-                    $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd);
115
+					$usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd);
116 116
 
117
-                } while ($usesClassRef !== false);
118
-            }
119
-        }
117
+				} while ($usesClassRef !== false);
118
+			}
119
+		}
120 120
 
121
-        /*
121
+		/*
122 122
          * Check for correct usage.
123 123
          */
124
-        if ($this->supportsAbove('5.4') && $usesThis !== false) {
124
+		if ($this->supportsAbove('5.4') && $usesThis !== false) {
125 125
 
126
-            $thisFound = $usesThis;
126
+			$thisFound = $usesThis;
127 127
 
128
-            do {
129
-                /*
128
+			do {
129
+				/*
130 130
                  * Closures only have access to $this if not declared as static.
131 131
                  */
132
-                if ($isStatic === true) {
133
-                    $phpcsFile->addError(
134
-                        'Closures / anonymous functions declared as static do not have access to $this',
135
-                        $thisFound,
136
-                        'ThisFoundInStatic'
137
-                    );
138
-                }
139
-
140
-                /*
132
+				if ($isStatic === true) {
133
+					$phpcsFile->addError(
134
+						'Closures / anonymous functions declared as static do not have access to $this',
135
+						$thisFound,
136
+						'ThisFoundInStatic'
137
+					);
138
+				}
139
+
140
+				/*
141 141
                  * Closures only have access to $this if used within a class context.
142 142
                  */
143
-                elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
144
-                    $phpcsFile->addWarning(
145
-                        'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.',
146
-                        $thisFound,
147
-                        'ThisFoundOutsideClass'
148
-                    );
149
-                }
150
-
151
-                $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
152
-
153
-            } while ($thisFound !== false);
154
-        }
155
-
156
-        // Prevent double reporting for nested closures.
157
-        return $scopeEnd;
158
-    }
159
-
160
-
161
-    /**
162
-     * Check whether the closure is declared as static.
163
-     *
164
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
165
-     * @param int                   $stackPtr  The position of the current token
166
-     *                                         in the stack passed in $tokens.
167
-     *
168
-     * @return bool
169
-     */
170
-    protected function isClosureStatic(File $phpcsFile, $stackPtr)
171
-    {
172
-        $tokens    = $phpcsFile->getTokens();
173
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
174
-
175
-        return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC);
176
-    }
177
-
178
-
179
-    /**
180
-     * Check if the code within a closure uses the $this variable.
181
-     *
182
-     * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
183
-     * @param int                   $startToken The position within the closure to continue searching from.
184
-     * @param int                   $endToken   The closure scope closer to stop searching at.
185
-     *
186
-     * @return int|false The stackPtr to the first $this usage if found or false if
187
-     *                   $this is not used.
188
-     */
189
-    protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
190
-    {
191
-        // Make sure the $startToken is valid.
192
-        if ($startToken >= $endToken) {
193
-            return false;
194
-        }
195
-
196
-        return $phpcsFile->findNext(
197
-            \T_VARIABLE,
198
-            $startToken,
199
-            $endToken,
200
-            false,
201
-            '$this'
202
-        );
203
-    }
204
-
205
-    /**
206
-     * Check if the code within a closure uses "self/parent/static".
207
-     *
208
-     * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
209
-     * @param int                   $startToken The position within the closure to continue searching from.
210
-     * @param int                   $endToken   The closure scope closer to stop searching at.
211
-     *
212
-     * @return int|false The stackPtr to the first classRef usage if found or false if
213
-     *                   they are not used.
214
-     */
215
-    protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
216
-    {
217
-        // Make sure the $startToken is valid.
218
-        if ($startToken >= $endToken) {
219
-            return false;
220
-        }
221
-
222
-        $tokens   = $phpcsFile->getTokens();
223
-        $classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken);
224
-
225
-        if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) {
226
-            return $classRef;
227
-        }
228
-
229
-        // T_STATIC, make sure it is used as a class reference.
230
-        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true);
231
-        if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) {
232
-            return false;
233
-        }
234
-
235
-        return $classRef;
236
-    }
143
+				elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) {
144
+					$phpcsFile->addWarning(
145
+						'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.',
146
+						$thisFound,
147
+						'ThisFoundOutsideClass'
148
+					);
149
+				}
150
+
151
+				$thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd);
152
+
153
+			} while ($thisFound !== false);
154
+		}
155
+
156
+		// Prevent double reporting for nested closures.
157
+		return $scopeEnd;
158
+	}
159
+
160
+
161
+	/**
162
+	 * Check whether the closure is declared as static.
163
+	 *
164
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
165
+	 * @param int                   $stackPtr  The position of the current token
166
+	 *                                         in the stack passed in $tokens.
167
+	 *
168
+	 * @return bool
169
+	 */
170
+	protected function isClosureStatic(File $phpcsFile, $stackPtr)
171
+	{
172
+		$tokens    = $phpcsFile->getTokens();
173
+		$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
174
+
175
+		return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC);
176
+	}
177
+
178
+
179
+	/**
180
+	 * Check if the code within a closure uses the $this variable.
181
+	 *
182
+	 * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
183
+	 * @param int                   $startToken The position within the closure to continue searching from.
184
+	 * @param int                   $endToken   The closure scope closer to stop searching at.
185
+	 *
186
+	 * @return int|false The stackPtr to the first $this usage if found or false if
187
+	 *                   $this is not used.
188
+	 */
189
+	protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken)
190
+	{
191
+		// Make sure the $startToken is valid.
192
+		if ($startToken >= $endToken) {
193
+			return false;
194
+		}
195
+
196
+		return $phpcsFile->findNext(
197
+			\T_VARIABLE,
198
+			$startToken,
199
+			$endToken,
200
+			false,
201
+			'$this'
202
+		);
203
+	}
204
+
205
+	/**
206
+	 * Check if the code within a closure uses "self/parent/static".
207
+	 *
208
+	 * @param \PHP_CodeSniffer_File $phpcsFile  The file being scanned.
209
+	 * @param int                   $startToken The position within the closure to continue searching from.
210
+	 * @param int                   $endToken   The closure scope closer to stop searching at.
211
+	 *
212
+	 * @return int|false The stackPtr to the first classRef usage if found or false if
213
+	 *                   they are not used.
214
+	 */
215
+	protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken)
216
+	{
217
+		// Make sure the $startToken is valid.
218
+		if ($startToken >= $endToken) {
219
+			return false;
220
+		}
221
+
222
+		$tokens   = $phpcsFile->getTokens();
223
+		$classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken);
224
+
225
+		if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) {
226
+			return $classRef;
227
+		}
228
+
229
+		// T_STATIC, make sure it is used as a class reference.
230
+		$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true);
231
+		if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) {
232
+			return false;
233
+		}
234
+
235
+		return $classRef;
236
+	}
237 237
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/FunctionDeclarations/NewNullableTypesSniff.php 1 patch
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -29,134 +29,134 @@
 block discarded – undo
29 29
  */
30 30
 class NewNullableTypesSniff extends Sniff
31 31
 {
32
-    /**
33
-     * Returns an array of tokens this test wants to listen for.
34
-     *
35
-     * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2
36
-     * as in that case we can't distinguish between parameter type hints and
37
-     * return type hints for the error message.}}
38
-     *
39
-     * @return array
40
-     */
41
-    public function register()
42
-    {
43
-        $tokens = array(
44
-            \T_FUNCTION,
45
-            \T_CLOSURE,
46
-        );
47
-
48
-        if (\defined('T_RETURN_TYPE')) {
49
-            $tokens[] = \T_RETURN_TYPE;
50
-        }
51
-
52
-        return $tokens;
53
-    }
54
-
55
-
56
-    /**
57
-     * Processes this test, when one of its tokens is encountered.
58
-     *
59
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
-     * @param int                   $stackPtr  The position of the current token
61
-     *                                         in the stack passed in $tokens.
62
-     *
63
-     * @return void
64
-     */
65
-    public function process(File $phpcsFile, $stackPtr)
66
-    {
67
-        if ($this->supportsBelow('7.0') === false) {
68
-            return;
69
-        }
70
-
71
-        $tokens    = $phpcsFile->getTokens();
72
-        $tokenCode = $tokens[$stackPtr]['code'];
73
-
74
-        if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) {
75
-            $this->processFunctionDeclaration($phpcsFile, $stackPtr);
76
-
77
-            // Deal with older PHPCS version which don't recognize return type hints
78
-            // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
79
-            $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
80
-            if ($returnTypeHint !== false) {
81
-                $this->processReturnType($phpcsFile, $returnTypeHint);
82
-            }
83
-        } else {
84
-            $this->processReturnType($phpcsFile, $stackPtr);
85
-        }
86
-    }
87
-
88
-
89
-    /**
90
-     * Process this test for function tokens.
91
-     *
92
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
93
-     * @param int                   $stackPtr  The position of the current token
94
-     *                                         in the stack passed in $tokens.
95
-     *
96
-     * @return void
97
-     */
98
-    protected function processFunctionDeclaration(File $phpcsFile, $stackPtr)
99
-    {
100
-        $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
101
-
102
-        if (empty($params) === false && \is_array($params)) {
103
-            foreach ($params as $param) {
104
-                if ($param['nullable_type'] === true) {
105
-                    $phpcsFile->addError(
106
-                        'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s',
107
-                        $param['token'],
108
-                        'typeDeclarationFound',
109
-                        array($param['type_hint'])
110
-                    );
111
-                }
112
-            }
113
-        }
114
-    }
115
-
116
-
117
-    /**
118
-     * Process this test for return type tokens.
119
-     *
120
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
121
-     * @param int                   $stackPtr  The position of the current token
122
-     *                                         in the stack passed in $tokens.
123
-     *
124
-     * @return void
125
-     */
126
-    protected function processReturnType(File $phpcsFile, $stackPtr)
127
-    {
128
-        $tokens = $phpcsFile->getTokens();
129
-
130
-        if (isset($tokens[($stackPtr - 1)]['code']) === false) {
131
-            return;
132
-        }
133
-
134
-        $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
135
-
136
-        // Deal with namespaced class names.
137
-        if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) {
138
-            $validTokens                  = Tokens::$emptyTokens;
139
-            $validTokens[\T_STRING]       = true;
140
-            $validTokens[\T_NS_SEPARATOR] = true;
141
-
142
-            $stackPtr--;
143
-
144
-            while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) {
145
-                $stackPtr--;
146
-            }
147
-
148
-            $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
149
-        }
150
-
151
-        // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN.
152
-        if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE')
153
-            || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN)
154
-        ) {
155
-            $phpcsFile->addError(
156
-                'Nullable return types are not supported in PHP 7.0 or earlier.',
157
-                $stackPtr,
158
-                'returnTypeFound'
159
-            );
160
-        }
161
-    }
32
+	/**
33
+	 * Returns an array of tokens this test wants to listen for.
34
+	 *
35
+	 * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2
36
+	 * as in that case we can't distinguish between parameter type hints and
37
+	 * return type hints for the error message.}}
38
+	 *
39
+	 * @return array
40
+	 */
41
+	public function register()
42
+	{
43
+		$tokens = array(
44
+			\T_FUNCTION,
45
+			\T_CLOSURE,
46
+		);
47
+
48
+		if (\defined('T_RETURN_TYPE')) {
49
+			$tokens[] = \T_RETURN_TYPE;
50
+		}
51
+
52
+		return $tokens;
53
+	}
54
+
55
+
56
+	/**
57
+	 * Processes this test, when one of its tokens is encountered.
58
+	 *
59
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
+	 * @param int                   $stackPtr  The position of the current token
61
+	 *                                         in the stack passed in $tokens.
62
+	 *
63
+	 * @return void
64
+	 */
65
+	public function process(File $phpcsFile, $stackPtr)
66
+	{
67
+		if ($this->supportsBelow('7.0') === false) {
68
+			return;
69
+		}
70
+
71
+		$tokens    = $phpcsFile->getTokens();
72
+		$tokenCode = $tokens[$stackPtr]['code'];
73
+
74
+		if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) {
75
+			$this->processFunctionDeclaration($phpcsFile, $stackPtr);
76
+
77
+			// Deal with older PHPCS version which don't recognize return type hints
78
+			// as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
79
+			$returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
80
+			if ($returnTypeHint !== false) {
81
+				$this->processReturnType($phpcsFile, $returnTypeHint);
82
+			}
83
+		} else {
84
+			$this->processReturnType($phpcsFile, $stackPtr);
85
+		}
86
+	}
87
+
88
+
89
+	/**
90
+	 * Process this test for function tokens.
91
+	 *
92
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
93
+	 * @param int                   $stackPtr  The position of the current token
94
+	 *                                         in the stack passed in $tokens.
95
+	 *
96
+	 * @return void
97
+	 */
98
+	protected function processFunctionDeclaration(File $phpcsFile, $stackPtr)
99
+	{
100
+		$params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
101
+
102
+		if (empty($params) === false && \is_array($params)) {
103
+			foreach ($params as $param) {
104
+				if ($param['nullable_type'] === true) {
105
+					$phpcsFile->addError(
106
+						'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s',
107
+						$param['token'],
108
+						'typeDeclarationFound',
109
+						array($param['type_hint'])
110
+					);
111
+				}
112
+			}
113
+		}
114
+	}
115
+
116
+
117
+	/**
118
+	 * Process this test for return type tokens.
119
+	 *
120
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
121
+	 * @param int                   $stackPtr  The position of the current token
122
+	 *                                         in the stack passed in $tokens.
123
+	 *
124
+	 * @return void
125
+	 */
126
+	protected function processReturnType(File $phpcsFile, $stackPtr)
127
+	{
128
+		$tokens = $phpcsFile->getTokens();
129
+
130
+		if (isset($tokens[($stackPtr - 1)]['code']) === false) {
131
+			return;
132
+		}
133
+
134
+		$previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
135
+
136
+		// Deal with namespaced class names.
137
+		if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) {
138
+			$validTokens                  = Tokens::$emptyTokens;
139
+			$validTokens[\T_STRING]       = true;
140
+			$validTokens[\T_NS_SEPARATOR] = true;
141
+
142
+			$stackPtr--;
143
+
144
+			while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) {
145
+				$stackPtr--;
146
+			}
147
+
148
+			$previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
149
+		}
150
+
151
+		// T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN.
152
+		if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE')
153
+			|| (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN)
154
+		) {
155
+			$phpcsFile->addError(
156
+				'Nullable return types are not supported in PHP 7.0 or earlier.',
157
+				$stackPtr,
158
+				'returnTypeFound'
159
+			);
160
+		}
161
+	}
162 162
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/FunctionDeclarations/NonStaticMagicMethodsSniff.php 1 patch
Indentation   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -28,151 +28,151 @@
 block discarded – undo
28 28
 class NonStaticMagicMethodsSniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * A list of PHP magic methods and their visibility and static requirements.
33
-     *
34
-     * Method names in the array should be all *lowercase*.
35
-     * Visibility can be either 'public', 'protected' or 'private'.
36
-     * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static.
37
-     * When a method does not have a specific requirement for either visibility or static,
38
-     * do *not* add the key.
39
-     *
40
-     * @var array(string)
41
-     */
42
-    protected $magicMethods = array(
43
-        '__get' => array(
44
-            'visibility' => 'public',
45
-            'static'     => false,
46
-        ),
47
-        '__set' => array(
48
-            'visibility' => 'public',
49
-            'static'     => false,
50
-        ),
51
-        '__isset' => array(
52
-            'visibility' => 'public',
53
-            'static'     => false,
54
-        ),
55
-        '__unset' => array(
56
-            'visibility' => 'public',
57
-            'static'     => false,
58
-        ),
59
-        '__call' => array(
60
-            'visibility' => 'public',
61
-            'static'     => false,
62
-        ),
63
-        '__callstatic' => array(
64
-            'visibility' => 'public',
65
-            'static'     => true,
66
-        ),
67
-        '__sleep' => array(
68
-            'visibility' => 'public',
69
-        ),
70
-        '__tostring' => array(
71
-            'visibility' => 'public',
72
-        ),
73
-        '__set_state' => array(
74
-            'static'     => true,
75
-        ),
76
-    );
77
-
78
-
79
-    /**
80
-     * Returns an array of tokens this test wants to listen for.
81
-     *
82
-     * @return array
83
-     */
84
-    public function register()
85
-    {
86
-        $targets = array(
87
-            \T_CLASS,
88
-            \T_INTERFACE,
89
-            \T_TRAIT,
90
-        );
91
-
92
-        if (\defined('T_ANON_CLASS')) {
93
-            $targets[] = \T_ANON_CLASS;
94
-        }
95
-
96
-        return $targets;
97
-    }
98
-
99
-
100
-    /**
101
-     * Processes this test, when one of its tokens is encountered.
102
-     *
103
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
104
-     * @param int                   $stackPtr  The position of the current token in the
105
-     *                                         stack passed in $tokens.
106
-     *
107
-     * @return void
108
-     */
109
-    public function process(File $phpcsFile, $stackPtr)
110
-    {
111
-        // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it.
112
-        if ($this->supportsAbove('5.3') === false) {
113
-            return;
114
-        }
115
-
116
-        $tokens = $phpcsFile->getTokens();
117
-
118
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
119
-            return;
120
-        }
121
-
122
-        $classScopeCloser = $tokens[$stackPtr]['scope_closer'];
123
-        $functionPtr      = $stackPtr;
124
-
125
-        // Find all the functions in this class or interface.
126
-        while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) {
127
-            /*
31
+	/**
32
+	 * A list of PHP magic methods and their visibility and static requirements.
33
+	 *
34
+	 * Method names in the array should be all *lowercase*.
35
+	 * Visibility can be either 'public', 'protected' or 'private'.
36
+	 * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static.
37
+	 * When a method does not have a specific requirement for either visibility or static,
38
+	 * do *not* add the key.
39
+	 *
40
+	 * @var array(string)
41
+	 */
42
+	protected $magicMethods = array(
43
+		'__get' => array(
44
+			'visibility' => 'public',
45
+			'static'     => false,
46
+		),
47
+		'__set' => array(
48
+			'visibility' => 'public',
49
+			'static'     => false,
50
+		),
51
+		'__isset' => array(
52
+			'visibility' => 'public',
53
+			'static'     => false,
54
+		),
55
+		'__unset' => array(
56
+			'visibility' => 'public',
57
+			'static'     => false,
58
+		),
59
+		'__call' => array(
60
+			'visibility' => 'public',
61
+			'static'     => false,
62
+		),
63
+		'__callstatic' => array(
64
+			'visibility' => 'public',
65
+			'static'     => true,
66
+		),
67
+		'__sleep' => array(
68
+			'visibility' => 'public',
69
+		),
70
+		'__tostring' => array(
71
+			'visibility' => 'public',
72
+		),
73
+		'__set_state' => array(
74
+			'static'     => true,
75
+		),
76
+	);
77
+
78
+
79
+	/**
80
+	 * Returns an array of tokens this test wants to listen for.
81
+	 *
82
+	 * @return array
83
+	 */
84
+	public function register()
85
+	{
86
+		$targets = array(
87
+			\T_CLASS,
88
+			\T_INTERFACE,
89
+			\T_TRAIT,
90
+		);
91
+
92
+		if (\defined('T_ANON_CLASS')) {
93
+			$targets[] = \T_ANON_CLASS;
94
+		}
95
+
96
+		return $targets;
97
+	}
98
+
99
+
100
+	/**
101
+	 * Processes this test, when one of its tokens is encountered.
102
+	 *
103
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
104
+	 * @param int                   $stackPtr  The position of the current token in the
105
+	 *                                         stack passed in $tokens.
106
+	 *
107
+	 * @return void
108
+	 */
109
+	public function process(File $phpcsFile, $stackPtr)
110
+	{
111
+		// Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it.
112
+		if ($this->supportsAbove('5.3') === false) {
113
+			return;
114
+		}
115
+
116
+		$tokens = $phpcsFile->getTokens();
117
+
118
+		if (isset($tokens[$stackPtr]['scope_closer']) === false) {
119
+			return;
120
+		}
121
+
122
+		$classScopeCloser = $tokens[$stackPtr]['scope_closer'];
123
+		$functionPtr      = $stackPtr;
124
+
125
+		// Find all the functions in this class or interface.
126
+		while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) {
127
+			/*
128 128
              * Get the scope closer for this function in order to know how
129 129
              * to advance to the next function.
130 130
              * If no body of function (e.g. for interfaces), there is
131 131
              * no closing curly brace; advance the pointer differently.
132 132
              */
133
-            if (isset($tokens[$functionToken]['scope_closer'])) {
134
-                $scopeCloser = $tokens[$functionToken]['scope_closer'];
135
-            } else {
136
-                $scopeCloser = ($functionToken + 1);
137
-            }
138
-
139
-            $methodName   = $phpcsFile->getDeclarationName($functionToken);
140
-            $methodNameLc = strtolower($methodName);
141
-            if (isset($this->magicMethods[$methodNameLc]) === false) {
142
-                $functionPtr = $scopeCloser;
143
-                continue;
144
-            }
145
-
146
-            $methodProperties = $phpcsFile->getMethodProperties($functionToken);
147
-            $errorCodeBase    = $this->stringToErrorCode($methodNameLc);
148
-
149
-            if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) {
150
-                $error     = 'Visibility for magic method %s must be %s. Found: %s';
151
-                $errorCode = $errorCodeBase . 'MethodVisibility';
152
-                $data      = array(
153
-                    $methodName,
154
-                    $this->magicMethods[$methodNameLc]['visibility'],
155
-                    $methodProperties['scope'],
156
-                );
157
-
158
-                $phpcsFile->addError($error, $functionToken, $errorCode, $data);
159
-            }
160
-
161
-            if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) {
162
-                $error     = 'Magic method %s cannot be defined as static.';
163
-                $errorCode = $errorCodeBase . 'MethodStatic';
164
-                $data      = array($methodName);
165
-
166
-                if ($this->magicMethods[$methodNameLc]['static'] === true) {
167
-                    $error     = 'Magic method %s must be defined as static.';
168
-                    $errorCode = $errorCodeBase . 'MethodNonStatic';
169
-                }
170
-
171
-                $phpcsFile->addError($error, $functionToken, $errorCode, $data);
172
-            }
173
-
174
-            // Advance to next function.
175
-            $functionPtr = $scopeCloser;
176
-        }
177
-    }
133
+			if (isset($tokens[$functionToken]['scope_closer'])) {
134
+				$scopeCloser = $tokens[$functionToken]['scope_closer'];
135
+			} else {
136
+				$scopeCloser = ($functionToken + 1);
137
+			}
138
+
139
+			$methodName   = $phpcsFile->getDeclarationName($functionToken);
140
+			$methodNameLc = strtolower($methodName);
141
+			if (isset($this->magicMethods[$methodNameLc]) === false) {
142
+				$functionPtr = $scopeCloser;
143
+				continue;
144
+			}
145
+
146
+			$methodProperties = $phpcsFile->getMethodProperties($functionToken);
147
+			$errorCodeBase    = $this->stringToErrorCode($methodNameLc);
148
+
149
+			if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) {
150
+				$error     = 'Visibility for magic method %s must be %s. Found: %s';
151
+				$errorCode = $errorCodeBase . 'MethodVisibility';
152
+				$data      = array(
153
+					$methodName,
154
+					$this->magicMethods[$methodNameLc]['visibility'],
155
+					$methodProperties['scope'],
156
+				);
157
+
158
+				$phpcsFile->addError($error, $functionToken, $errorCode, $data);
159
+			}
160
+
161
+			if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) {
162
+				$error     = 'Magic method %s cannot be defined as static.';
163
+				$errorCode = $errorCodeBase . 'MethodStatic';
164
+				$data      = array($methodName);
165
+
166
+				if ($this->magicMethods[$methodNameLc]['static'] === true) {
167
+					$error     = 'Magic method %s must be defined as static.';
168
+					$errorCode = $errorCodeBase . 'MethodNonStatic';
169
+				}
170
+
171
+				$phpcsFile->addError($error, $functionToken, $errorCode, $data);
172
+			}
173
+
174
+			// Advance to next function.
175
+			$functionPtr = $scopeCloser;
176
+		}
177
+	}
178 178
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/Extensions/RemovedExtensionsSniff.php 1 patch
Indentation   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -26,292 +26,292 @@
 block discarded – undo
26 26
  */
27 27
 class RemovedExtensionsSniff extends AbstractRemovedFeatureSniff
28 28
 {
29
-    /**
30
-     * A list of functions to whitelist, if any.
31
-     *
32
-     * This is intended for projects using functions which start with the same
33
-     * prefix as one of the removed extensions.
34
-     *
35
-     * This property can be set from the ruleset, like so:
36
-     * <rule ref="PHPCompatibility.Extensions.RemovedExtensions">
37
-     *   <properties>
38
-     *     <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" />
39
-     *   </properties>
40
-     * </rule>
41
-     *
42
-     * @var array
43
-     */
44
-    public $functionWhitelist;
29
+	/**
30
+	 * A list of functions to whitelist, if any.
31
+	 *
32
+	 * This is intended for projects using functions which start with the same
33
+	 * prefix as one of the removed extensions.
34
+	 *
35
+	 * This property can be set from the ruleset, like so:
36
+	 * <rule ref="PHPCompatibility.Extensions.RemovedExtensions">
37
+	 *   <properties>
38
+	 *     <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" />
39
+	 *   </properties>
40
+	 * </rule>
41
+	 *
42
+	 * @var array
43
+	 */
44
+	public $functionWhitelist;
45 45
 
46
-    /**
47
-     * A list of removed extensions with their alternative, if any
48
-     *
49
-     * The array lists : version number with false (deprecated) and true (removed).
50
-     * If's sufficient to list the first version where the extension was deprecated/removed.
51
-     *
52
-     * @var array(string|null)
53
-     */
54
-    protected $removedExtensions = array(
55
-        'activescript' => array(
56
-            '5.1' => true,
57
-            'alternative' => 'pecl/activescript',
58
-        ),
59
-        'cpdf' => array(
60
-            '5.1' => true,
61
-            'alternative' => 'pecl/pdflib',
62
-        ),
63
-        'dbase' => array(
64
-            '5.3' => true,
65
-            'alternative' => null,
66
-        ),
67
-        'dbx' => array(
68
-            '5.1' => true,
69
-            'alternative' => 'pecl/dbx',
70
-        ),
71
-        'dio' => array(
72
-            '5.1' => true,
73
-            'alternative' => 'pecl/dio',
74
-        ),
75
-        'ereg' => array(
76
-            '5.3' => false,
77
-            '7.0' => true,
78
-            'alternative' => 'pcre',
79
-        ),
80
-        'fam' => array(
81
-            '5.1' => true,
82
-            'alternative' => null,
83
-        ),
84
-        'fbsql' => array(
85
-            '5.3' => true,
86
-            'alternative' => null,
87
-        ),
88
-        'fdf' => array(
89
-            '5.3' => true,
90
-            'alternative' => 'pecl/fdf',
91
-        ),
92
-        'filepro' => array(
93
-            '5.2' => true,
94
-            'alternative' => null,
95
-        ),
96
-        'hw_api' => array(
97
-            '5.2' => true,
98
-            'alternative' => null,
99
-        ),
100
-        'ibase' => array(
101
-            '7.4' => true,
102
-            'alternative' => 'pecl/ibase',
103
-        ),
104
-        'ingres' => array(
105
-            '5.1' => true,
106
-            'alternative' => 'pecl/ingres',
107
-        ),
108
-        'ircg' => array(
109
-            '5.1' => true,
110
-            'alternative' => null,
111
-        ),
112
-        'mcrypt' => array(
113
-            '7.1' => false,
114
-            '7.2' => true,
115
-            'alternative' => 'openssl (preferred) or pecl/mcrypt once available',
116
-        ),
117
-        'mcve' => array(
118
-            '5.1' => true,
119
-            'alternative' => 'pecl/mcve',
120
-        ),
121
-        'ming' => array(
122
-            '5.3' => true,
123
-            'alternative' => 'pecl/ming',
124
-        ),
125
-        'mnogosearch' => array(
126
-            '5.1' => true,
127
-            'alternative' => null,
128
-        ),
129
-        'msql' => array(
130
-            '5.3' => true,
131
-            'alternative' => null,
132
-        ),
133
-        'mssql' => array(
134
-            '7.0' => true,
135
-            'alternative' => null,
136
-        ),
137
-        'mysql_' => array(
138
-            '5.5' => false,
139
-            '7.0' => true,
140
-            'alternative' => 'mysqli',
141
-        ),
142
-        'ncurses' => array(
143
-            '5.3' => true,
144
-            'alternative' => 'pecl/ncurses',
145
-        ),
146
-        'oracle' => array(
147
-            '5.1' => true,
148
-            'alternative' => 'oci8 or pdo_oci',
149
-        ),
150
-        'ovrimos' => array(
151
-            '5.1' => true,
152
-            'alternative' => null,
153
-        ),
154
-        'pfpro_' => array(
155
-            '5.1' => true,
156
-            'alternative' => null,
157
-        ),
158
-        'sqlite' => array(
159
-            '5.4' => true,
160
-            'alternative' => null,
161
-        ),
162
-        // Has to be before `sybase` as otherwise it will never match.
163
-        'sybase_ct' => array(
164
-            '7.0' => true,
165
-            'alternative' => null,
166
-        ),
167
-        'sybase' => array(
168
-            '5.3' => true,
169
-            'alternative' => 'sybase_ct',
170
-        ),
171
-        'w32api' => array(
172
-            '5.1' => true,
173
-            'alternative' => 'pecl/ffi',
174
-        ),
175
-        'wddx' => array(
176
-            '7.4' => true,
177
-            'alternative' => 'pecl/wddx',
178
-        ),
179
-        'yp' => array(
180
-            '5.1' => true,
181
-            'alternative' => null,
182
-        ),
183
-    );
46
+	/**
47
+	 * A list of removed extensions with their alternative, if any
48
+	 *
49
+	 * The array lists : version number with false (deprecated) and true (removed).
50
+	 * If's sufficient to list the first version where the extension was deprecated/removed.
51
+	 *
52
+	 * @var array(string|null)
53
+	 */
54
+	protected $removedExtensions = array(
55
+		'activescript' => array(
56
+			'5.1' => true,
57
+			'alternative' => 'pecl/activescript',
58
+		),
59
+		'cpdf' => array(
60
+			'5.1' => true,
61
+			'alternative' => 'pecl/pdflib',
62
+		),
63
+		'dbase' => array(
64
+			'5.3' => true,
65
+			'alternative' => null,
66
+		),
67
+		'dbx' => array(
68
+			'5.1' => true,
69
+			'alternative' => 'pecl/dbx',
70
+		),
71
+		'dio' => array(
72
+			'5.1' => true,
73
+			'alternative' => 'pecl/dio',
74
+		),
75
+		'ereg' => array(
76
+			'5.3' => false,
77
+			'7.0' => true,
78
+			'alternative' => 'pcre',
79
+		),
80
+		'fam' => array(
81
+			'5.1' => true,
82
+			'alternative' => null,
83
+		),
84
+		'fbsql' => array(
85
+			'5.3' => true,
86
+			'alternative' => null,
87
+		),
88
+		'fdf' => array(
89
+			'5.3' => true,
90
+			'alternative' => 'pecl/fdf',
91
+		),
92
+		'filepro' => array(
93
+			'5.2' => true,
94
+			'alternative' => null,
95
+		),
96
+		'hw_api' => array(
97
+			'5.2' => true,
98
+			'alternative' => null,
99
+		),
100
+		'ibase' => array(
101
+			'7.4' => true,
102
+			'alternative' => 'pecl/ibase',
103
+		),
104
+		'ingres' => array(
105
+			'5.1' => true,
106
+			'alternative' => 'pecl/ingres',
107
+		),
108
+		'ircg' => array(
109
+			'5.1' => true,
110
+			'alternative' => null,
111
+		),
112
+		'mcrypt' => array(
113
+			'7.1' => false,
114
+			'7.2' => true,
115
+			'alternative' => 'openssl (preferred) or pecl/mcrypt once available',
116
+		),
117
+		'mcve' => array(
118
+			'5.1' => true,
119
+			'alternative' => 'pecl/mcve',
120
+		),
121
+		'ming' => array(
122
+			'5.3' => true,
123
+			'alternative' => 'pecl/ming',
124
+		),
125
+		'mnogosearch' => array(
126
+			'5.1' => true,
127
+			'alternative' => null,
128
+		),
129
+		'msql' => array(
130
+			'5.3' => true,
131
+			'alternative' => null,
132
+		),
133
+		'mssql' => array(
134
+			'7.0' => true,
135
+			'alternative' => null,
136
+		),
137
+		'mysql_' => array(
138
+			'5.5' => false,
139
+			'7.0' => true,
140
+			'alternative' => 'mysqli',
141
+		),
142
+		'ncurses' => array(
143
+			'5.3' => true,
144
+			'alternative' => 'pecl/ncurses',
145
+		),
146
+		'oracle' => array(
147
+			'5.1' => true,
148
+			'alternative' => 'oci8 or pdo_oci',
149
+		),
150
+		'ovrimos' => array(
151
+			'5.1' => true,
152
+			'alternative' => null,
153
+		),
154
+		'pfpro_' => array(
155
+			'5.1' => true,
156
+			'alternative' => null,
157
+		),
158
+		'sqlite' => array(
159
+			'5.4' => true,
160
+			'alternative' => null,
161
+		),
162
+		// Has to be before `sybase` as otherwise it will never match.
163
+		'sybase_ct' => array(
164
+			'7.0' => true,
165
+			'alternative' => null,
166
+		),
167
+		'sybase' => array(
168
+			'5.3' => true,
169
+			'alternative' => 'sybase_ct',
170
+		),
171
+		'w32api' => array(
172
+			'5.1' => true,
173
+			'alternative' => 'pecl/ffi',
174
+		),
175
+		'wddx' => array(
176
+			'7.4' => true,
177
+			'alternative' => 'pecl/wddx',
178
+		),
179
+		'yp' => array(
180
+			'5.1' => true,
181
+			'alternative' => null,
182
+		),
183
+	);
184 184
 
185
-    /**
186
-     * Returns an array of tokens this test wants to listen for.
187
-     *
188
-     * @return array
189
-     */
190
-    public function register()
191
-    {
192
-        // Handle case-insensitivity of function names.
193
-        $this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions);
185
+	/**
186
+	 * Returns an array of tokens this test wants to listen for.
187
+	 *
188
+	 * @return array
189
+	 */
190
+	public function register()
191
+	{
192
+		// Handle case-insensitivity of function names.
193
+		$this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions);
194 194
 
195
-        return array(\T_STRING);
196
-    }
195
+		return array(\T_STRING);
196
+	}
197 197
 
198
-    /**
199
-     * Processes this test, when one of its tokens is encountered.
200
-     *
201
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
202
-     * @param int                   $stackPtr  The position of the current token in the
203
-     *                                         stack passed in $tokens.
204
-     *
205
-     * @return void
206
-     */
207
-    public function process(File $phpcsFile, $stackPtr)
208
-    {
209
-        $tokens = $phpcsFile->getTokens();
198
+	/**
199
+	 * Processes this test, when one of its tokens is encountered.
200
+	 *
201
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
202
+	 * @param int                   $stackPtr  The position of the current token in the
203
+	 *                                         stack passed in $tokens.
204
+	 *
205
+	 * @return void
206
+	 */
207
+	public function process(File $phpcsFile, $stackPtr)
208
+	{
209
+		$tokens = $phpcsFile->getTokens();
210 210
 
211
-        // Find the next non-empty token.
212
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
211
+		// Find the next non-empty token.
212
+		$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
213 213
 
214
-        if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) {
215
-            // Not a function call.
216
-            return;
217
-        }
214
+		if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) {
215
+			// Not a function call.
216
+			return;
217
+		}
218 218
 
219
-        if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
220
-            // Not a function call.
221
-            return;
222
-        }
219
+		if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {
220
+			// Not a function call.
221
+			return;
222
+		}
223 223
 
224
-        // Find the previous non-empty token.
225
-        $search   = Tokens::$emptyTokens;
226
-        $search[] = \T_BITWISE_AND;
227
-        $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true);
228
-        if ($tokens[$previous]['code'] === \T_FUNCTION) {
229
-            // It's a function definition, not a function call.
230
-            return;
231
-        }
224
+		// Find the previous non-empty token.
225
+		$search   = Tokens::$emptyTokens;
226
+		$search[] = \T_BITWISE_AND;
227
+		$previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true);
228
+		if ($tokens[$previous]['code'] === \T_FUNCTION) {
229
+			// It's a function definition, not a function call.
230
+			return;
231
+		}
232 232
 
233
-        if ($tokens[$previous]['code'] === \T_NEW) {
234
-            // We are creating an object, not calling a function.
235
-            return;
236
-        }
233
+		if ($tokens[$previous]['code'] === \T_NEW) {
234
+			// We are creating an object, not calling a function.
235
+			return;
236
+		}
237 237
 
238
-        if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) {
239
-            // We are calling a method of an object.
240
-            return;
241
-        }
238
+		if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) {
239
+			// We are calling a method of an object.
240
+			return;
241
+		}
242 242
 
243
-        $function   = $tokens[$stackPtr]['content'];
244
-        $functionLc = strtolower($function);
243
+		$function   = $tokens[$stackPtr]['content'];
244
+		$functionLc = strtolower($function);
245 245
 
246
-        if ($this->isWhiteListed($functionLc) === true) {
247
-            // Function is whitelisted.
248
-            return;
249
-        }
246
+		if ($this->isWhiteListed($functionLc) === true) {
247
+			// Function is whitelisted.
248
+			return;
249
+		}
250 250
 
251
-        foreach ($this->removedExtensions as $extension => $versionList) {
252
-            if (strpos($functionLc, $extension) === 0) {
253
-                $itemInfo = array(
254
-                    'name'   => $extension,
255
-                );
256
-                $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
257
-                break;
258
-            }
259
-        }
260
-    }
251
+		foreach ($this->removedExtensions as $extension => $versionList) {
252
+			if (strpos($functionLc, $extension) === 0) {
253
+				$itemInfo = array(
254
+					'name'   => $extension,
255
+				);
256
+				$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
257
+				break;
258
+			}
259
+		}
260
+	}
261 261
 
262 262
 
263
-    /**
264
-     * Is the current function being checked whitelisted ?
265
-     *
266
-     * Parsing the list late as it may be provided as a property, but also inline.
267
-     *
268
-     * @param string $content Content of the current token.
269
-     *
270
-     * @return bool
271
-     */
272
-    protected function isWhiteListed($content)
273
-    {
274
-        if (isset($this->functionWhitelist) === false) {
275
-            return false;
276
-        }
263
+	/**
264
+	 * Is the current function being checked whitelisted ?
265
+	 *
266
+	 * Parsing the list late as it may be provided as a property, but also inline.
267
+	 *
268
+	 * @param string $content Content of the current token.
269
+	 *
270
+	 * @return bool
271
+	 */
272
+	protected function isWhiteListed($content)
273
+	{
274
+		if (isset($this->functionWhitelist) === false) {
275
+			return false;
276
+		}
277 277
 
278
-        if (\is_string($this->functionWhitelist) === true) {
279
-            if (strpos($this->functionWhitelist, ',') !== false) {
280
-                $this->functionWhitelist = explode(',', $this->functionWhitelist);
281
-            } else {
282
-                $this->functionWhitelist = (array) $this->functionWhitelist;
283
-            }
284
-        }
278
+		if (\is_string($this->functionWhitelist) === true) {
279
+			if (strpos($this->functionWhitelist, ',') !== false) {
280
+				$this->functionWhitelist = explode(',', $this->functionWhitelist);
281
+			} else {
282
+				$this->functionWhitelist = (array) $this->functionWhitelist;
283
+			}
284
+		}
285 285
 
286
-        if (\is_array($this->functionWhitelist) === true) {
287
-            $this->functionWhitelist = array_map('strtolower', $this->functionWhitelist);
288
-            return \in_array($content, $this->functionWhitelist, true);
289
-        }
286
+		if (\is_array($this->functionWhitelist) === true) {
287
+			$this->functionWhitelist = array_map('strtolower', $this->functionWhitelist);
288
+			return \in_array($content, $this->functionWhitelist, true);
289
+		}
290 290
 
291
-        return false;
292
-    }
291
+		return false;
292
+	}
293 293
 
294 294
 
295
-    /**
296
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
297
-     *
298
-     * @param array $itemInfo Base information about the item.
299
-     *
300
-     * @return array Version and other information about the item.
301
-     */
302
-    public function getItemArray(array $itemInfo)
303
-    {
304
-        return $this->removedExtensions[$itemInfo['name']];
305
-    }
295
+	/**
296
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
297
+	 *
298
+	 * @param array $itemInfo Base information about the item.
299
+	 *
300
+	 * @return array Version and other information about the item.
301
+	 */
302
+	public function getItemArray(array $itemInfo)
303
+	{
304
+		return $this->removedExtensions[$itemInfo['name']];
305
+	}
306 306
 
307 307
 
308
-    /**
309
-     * Get the error message template for this sniff.
310
-     *
311
-     * @return string
312
-     */
313
-    protected function getErrorMsgTemplate()
314
-    {
315
-        return "Extension '%s' is ";
316
-    }
308
+	/**
309
+	 * Get the error message template for this sniff.
310
+	 *
311
+	 * @return string
312
+	 */
313
+	protected function getErrorMsgTemplate()
314
+	{
315
+		return "Extension '%s' is ";
316
+	}
317 317
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/UseDeclarations/NewGroupUseDeclarationsSniff.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -26,80 +26,80 @@
 block discarded – undo
26 26
  */
27 27
 class NewGroupUseDeclarationsSniff extends Sniff
28 28
 {
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        if (\defined('T_OPEN_USE_GROUP')) {
37
-            return array(\T_OPEN_USE_GROUP);
38
-        } else {
39
-            return array(\T_USE);
40
-        }
41
-    }
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		if (\defined('T_OPEN_USE_GROUP')) {
37
+			return array(\T_OPEN_USE_GROUP);
38
+		} else {
39
+			return array(\T_USE);
40
+		}
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * Processes this test, when one of its tokens is encountered.
46
-     *
47
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
-     * @param int                   $stackPtr  The position of the current token in
49
-     *                                         the stack passed in $tokens.
50
-     *
51
-     * @return void
52
-     */
53
-    public function process(File $phpcsFile, $stackPtr)
54
-    {
55
-        if ($this->supportsBelow('7.1') === false) {
56
-            return;
57
-        }
44
+	/**
45
+	 * Processes this test, when one of its tokens is encountered.
46
+	 *
47
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
48
+	 * @param int                   $stackPtr  The position of the current token in
49
+	 *                                         the stack passed in $tokens.
50
+	 *
51
+	 * @return void
52
+	 */
53
+	public function process(File $phpcsFile, $stackPtr)
54
+	{
55
+		if ($this->supportsBelow('7.1') === false) {
56
+			return;
57
+		}
58 58
 
59
-        $tokens = $phpcsFile->getTokens();
60
-        $token  = $tokens[$stackPtr];
59
+		$tokens = $phpcsFile->getTokens();
60
+		$token  = $tokens[$stackPtr];
61 61
 
62
-        // Deal with PHPCS pre-2.6.0.
63
-        if ($token['code'] === \T_USE) {
64
-            $hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true);
65
-            if ($hasCurlyBrace === false) {
66
-                return;
67
-            }
62
+		// Deal with PHPCS pre-2.6.0.
63
+		if ($token['code'] === \T_USE) {
64
+			$hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true);
65
+			if ($hasCurlyBrace === false) {
66
+				return;
67
+			}
68 68
 
69
-            $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true);
70
-            if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) {
71
-                return;
72
-            }
69
+			$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true);
70
+			if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) {
71
+				return;
72
+			}
73 73
 
74
-            $stackPtr = $hasCurlyBrace;
75
-        }
74
+			$stackPtr = $hasCurlyBrace;
75
+		}
76 76
 
77
-        // Still here ? In that case, it is a group use statement.
78
-        if ($this->supportsBelow('5.6') === true) {
79
-            $phpcsFile->addError(
80
-                'Group use declarations are not allowed in PHP 5.6 or earlier',
81
-                $stackPtr,
82
-                'Found'
83
-            );
84
-        }
77
+		// Still here ? In that case, it is a group use statement.
78
+		if ($this->supportsBelow('5.6') === true) {
79
+			$phpcsFile->addError(
80
+				'Group use declarations are not allowed in PHP 5.6 or earlier',
81
+				$stackPtr,
82
+				'Found'
83
+			);
84
+		}
85 85
 
86
-        $closers = array(\T_CLOSE_CURLY_BRACKET);
87
-        if (\defined('T_CLOSE_USE_GROUP')) {
88
-            $closers[] = \T_CLOSE_USE_GROUP;
89
-        }
86
+		$closers = array(\T_CLOSE_CURLY_BRACKET);
87
+		if (\defined('T_CLOSE_USE_GROUP')) {
88
+			$closers[] = \T_CLOSE_USE_GROUP;
89
+		}
90 90
 
91
-        $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true);
92
-        if ($closeCurly === false) {
93
-            return;
94
-        }
91
+		$closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true);
92
+		if ($closeCurly === false) {
93
+			return;
94
+		}
95 95
 
96
-        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true);
97
-        if ($tokens[$prevToken]['code'] === \T_COMMA) {
98
-            $phpcsFile->addError(
99
-                'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier',
100
-                $prevToken,
101
-                'TrailingCommaFound'
102
-            );
103
-        }
104
-    }
96
+		$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true);
97
+		if ($tokens[$prevToken]['code'] === \T_COMMA) {
98
+			$phpcsFile->addError(
99
+				'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier',
100
+				$prevToken,
101
+				'TrailingCommaFound'
102
+			);
103
+		}
104
+	}
105 105
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/UseDeclarations/NewUseConstFunctionSniff.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -31,72 +31,72 @@
 block discarded – undo
31 31
 class NewUseConstFunctionSniff extends Sniff
32 32
 {
33 33
 
34
-    /**
35
-     * A list of keywords that can follow use statements.
36
-     *
37
-     * @var array(string => string)
38
-     */
39
-    protected $validUseNames = array(
40
-        'const'    => true,
41
-        'function' => true,
42
-    );
34
+	/**
35
+	 * A list of keywords that can follow use statements.
36
+	 *
37
+	 * @var array(string => string)
38
+	 */
39
+	protected $validUseNames = array(
40
+		'const'    => true,
41
+		'function' => true,
42
+	);
43 43
 
44
-    /**
45
-     * Returns an array of tokens this test wants to listen for.
46
-     *
47
-     * @return array
48
-     */
49
-    public function register()
50
-    {
51
-        return array(\T_USE);
52
-    }
44
+	/**
45
+	 * Returns an array of tokens this test wants to listen for.
46
+	 *
47
+	 * @return array
48
+	 */
49
+	public function register()
50
+	{
51
+		return array(\T_USE);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Processes this test, when one of its tokens is encountered.
57
-     *
58
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
-     * @param int                   $stackPtr  The position of the current token in the
60
-     *                                         stack passed in $tokens.
61
-     *
62
-     * @return void
63
-     */
64
-    public function process(File $phpcsFile, $stackPtr)
65
-    {
66
-        if ($this->supportsBelow('5.5') !== true) {
67
-            return;
68
-        }
55
+	/**
56
+	 * Processes this test, when one of its tokens is encountered.
57
+	 *
58
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
+	 * @param int                   $stackPtr  The position of the current token in the
60
+	 *                                         stack passed in $tokens.
61
+	 *
62
+	 * @return void
63
+	 */
64
+	public function process(File $phpcsFile, $stackPtr)
65
+	{
66
+		if ($this->supportsBelow('5.5') !== true) {
67
+			return;
68
+		}
69 69
 
70
-        $tokens = $phpcsFile->getTokens();
70
+		$tokens = $phpcsFile->getTokens();
71 71
 
72
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
73
-        if ($nextNonEmpty === false) {
74
-            // Live coding.
75
-            return;
76
-        }
72
+		$nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
73
+		if ($nextNonEmpty === false) {
74
+			// Live coding.
75
+			return;
76
+		}
77 77
 
78
-        if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) {
79
-            // Not a `use const` or `use function` statement.
80
-            return;
81
-        }
78
+		if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) {
79
+			// Not a `use const` or `use function` statement.
80
+			return;
81
+		}
82 82
 
83
-        // `use const` and `use function` have to be followed by the function/constant name.
84
-        $functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
85
-        if ($functionOrConstName === false
86
-            // Identifies as T_AS or T_STRING, this covers both.
87
-            || ($tokens[$functionOrConstName]['content'] === 'as'
88
-            || $tokens[$functionOrConstName]['code'] === \T_COMMA)
89
-        ) {
90
-            // Live coding or incorrect use of reserved keyword, but that is
91
-            // covered by the ForbiddenNames sniff.
92
-            return;
93
-        }
83
+		// `use const` and `use function` have to be followed by the function/constant name.
84
+		$functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true);
85
+		if ($functionOrConstName === false
86
+			// Identifies as T_AS or T_STRING, this covers both.
87
+			|| ($tokens[$functionOrConstName]['content'] === 'as'
88
+			|| $tokens[$functionOrConstName]['code'] === \T_COMMA)
89
+		) {
90
+			// Live coding or incorrect use of reserved keyword, but that is
91
+			// covered by the ForbiddenNames sniff.
92
+			return;
93
+		}
94 94
 
95
-        // Still here ? In that case we have encountered a `use const` or `use function` statement.
96
-        $phpcsFile->addError(
97
-            'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.',
98
-            $nextNonEmpty,
99
-            'Found'
100
-        );
101
-    }
95
+		// Still here ? In that case we have encountered a `use const` or `use function` statement.
96
+		$phpcsFile->addError(
97
+			'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.',
98
+			$nextNonEmpty,
99
+			'Found'
100
+		);
101
+	}
102 102
 }
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/TypeCasts/RemovedTypeCastsSniff.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -21,107 +21,107 @@
 block discarded – undo
21 21
  */
22 22
 class RemovedTypeCastsSniff extends AbstractRemovedFeatureSniff
23 23
 {
24
-    /**
25
-     * A list of deprecated and removed type casts with their alternatives.
26
-     *
27
-     * The array lists : version number with false (deprecated) or true (removed) and an alternative function.
28
-     * If no alternative exists, it is NULL, i.e, the function should just not be used.
29
-     *
30
-     * @var array(string => array(string => bool|string|null))
31
-     */
32
-    protected $deprecatedTypeCasts = array(
33
-        'T_UNSET_CAST' => array(
34
-            '7.2'         => false,
35
-            'alternative' => 'unset()',
36
-            'description' => 'unset',
37
-        ),
38
-    );
39
-
40
-
41
-    /**
42
-     * Returns an array of tokens this test wants to listen for.
43
-     *
44
-     * @return array
45
-     */
46
-    public function register()
47
-    {
48
-        $tokens = array();
49
-        foreach ($this->deprecatedTypeCasts as $token => $versions) {
50
-            $tokens[] = constant($token);
51
-        }
52
-
53
-        return $tokens;
54
-    }
55
-
56
-
57
-    /**
58
-     * Processes this test, when one of its tokens is encountered.
59
-     *
60
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
-     * @param int                   $stackPtr  The position of the current token in
62
-     *                                         the stack passed in $tokens.
63
-     *
64
-     * @return void
65
-     */
66
-    public function process(File $phpcsFile, $stackPtr)
67
-    {
68
-        $tokens    = $phpcsFile->getTokens();
69
-        $tokenType = $tokens[$stackPtr]['type'];
70
-
71
-        $itemInfo = array(
72
-            'name'        => $tokenType,
73
-            'description' => $this->deprecatedTypeCasts[$tokenType]['description'],
74
-        );
75
-        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
76
-    }
77
-
78
-
79
-    /**
80
-     * Get an array of the non-PHP-version array keys used in a sub-array.
81
-     *
82
-     * @return array
83
-     */
84
-    protected function getNonVersionArrayKeys()
85
-    {
86
-        return array('description', 'alternative');
87
-    }
88
-
89
-    /**
90
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
91
-     *
92
-     * @param array $itemInfo Base information about the item.
93
-     *
94
-     * @return array Version and other information about the item.
95
-     */
96
-    public function getItemArray(array $itemInfo)
97
-    {
98
-        return $this->deprecatedTypeCasts[$itemInfo['name']];
99
-    }
100
-
101
-
102
-    /**
103
-     * Get the error message template for this sniff.
104
-     *
105
-     * @return string
106
-     */
107
-    protected function getErrorMsgTemplate()
108
-    {
109
-        return 'The %s cast is ';
110
-    }
111
-
112
-
113
-    /**
114
-     * Filter the error data before it's passed to PHPCS.
115
-     *
116
-     * @param array $data      The error data array which was created.
117
-     * @param array $itemInfo  Base information about the item this error message applies to.
118
-     * @param array $errorInfo Detail information about an item this error message applies to.
119
-     *
120
-     * @return array
121
-     */
122
-    protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
123
-    {
124
-        $data[0] = $itemInfo['description'];
125
-        return $data;
126
-    }
24
+	/**
25
+	 * A list of deprecated and removed type casts with their alternatives.
26
+	 *
27
+	 * The array lists : version number with false (deprecated) or true (removed) and an alternative function.
28
+	 * If no alternative exists, it is NULL, i.e, the function should just not be used.
29
+	 *
30
+	 * @var array(string => array(string => bool|string|null))
31
+	 */
32
+	protected $deprecatedTypeCasts = array(
33
+		'T_UNSET_CAST' => array(
34
+			'7.2'         => false,
35
+			'alternative' => 'unset()',
36
+			'description' => 'unset',
37
+		),
38
+	);
39
+
40
+
41
+	/**
42
+	 * Returns an array of tokens this test wants to listen for.
43
+	 *
44
+	 * @return array
45
+	 */
46
+	public function register()
47
+	{
48
+		$tokens = array();
49
+		foreach ($this->deprecatedTypeCasts as $token => $versions) {
50
+			$tokens[] = constant($token);
51
+		}
52
+
53
+		return $tokens;
54
+	}
55
+
56
+
57
+	/**
58
+	 * Processes this test, when one of its tokens is encountered.
59
+	 *
60
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
61
+	 * @param int                   $stackPtr  The position of the current token in
62
+	 *                                         the stack passed in $tokens.
63
+	 *
64
+	 * @return void
65
+	 */
66
+	public function process(File $phpcsFile, $stackPtr)
67
+	{
68
+		$tokens    = $phpcsFile->getTokens();
69
+		$tokenType = $tokens[$stackPtr]['type'];
70
+
71
+		$itemInfo = array(
72
+			'name'        => $tokenType,
73
+			'description' => $this->deprecatedTypeCasts[$tokenType]['description'],
74
+		);
75
+		$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Get an array of the non-PHP-version array keys used in a sub-array.
81
+	 *
82
+	 * @return array
83
+	 */
84
+	protected function getNonVersionArrayKeys()
85
+	{
86
+		return array('description', 'alternative');
87
+	}
88
+
89
+	/**
90
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
91
+	 *
92
+	 * @param array $itemInfo Base information about the item.
93
+	 *
94
+	 * @return array Version and other information about the item.
95
+	 */
96
+	public function getItemArray(array $itemInfo)
97
+	{
98
+		return $this->deprecatedTypeCasts[$itemInfo['name']];
99
+	}
100
+
101
+
102
+	/**
103
+	 * Get the error message template for this sniff.
104
+	 *
105
+	 * @return string
106
+	 */
107
+	protected function getErrorMsgTemplate()
108
+	{
109
+		return 'The %s cast is ';
110
+	}
111
+
112
+
113
+	/**
114
+	 * Filter the error data before it's passed to PHPCS.
115
+	 *
116
+	 * @param array $data      The error data array which was created.
117
+	 * @param array $itemInfo  Base information about the item this error message applies to.
118
+	 * @param array $errorInfo Detail information about an item this error message applies to.
119
+	 *
120
+	 * @return array
121
+	 */
122
+	protected function filterErrorData(array $data, array $itemInfo, array $errorInfo)
123
+	{
124
+		$data[0] = $itemInfo['description'];
125
+		return $data;
126
+	}
127 127
 }
Please login to merge, or discard this patch.