GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 699b70...879176 )
by Chris
13:23
created
Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php 3 patches
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 
16 16
 if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
17
-    throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
17
+	 throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
18 18
 }
19 19
 
20 20
 /**
@@ -35,187 +35,187 @@  discard block
 block discarded – undo
35 35
 class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
36 36
 {
37 37
 
38
-    /**
39
-     * A list of all PHP magic methods.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $magicMethods = array(
44
-                               'construct'  => true,
45
-                               'destruct'   => true,
46
-                               'call'       => true,
47
-                               'callstatic' => true,
48
-                               'get'        => true,
49
-                               'set'        => true,
50
-                               'isset'      => true,
51
-                               'unset'      => true,
52
-                               'sleep'      => true,
53
-                               'wakeup'     => true,
54
-                               'tostring'   => true,
55
-                               'set_state'  => true,
56
-                               'clone'      => true,
57
-                               'invoke'     => true,
58
-                               'debuginfo'  => true,
59
-                              );
60
-
61
-    /**
62
-     * A list of all PHP non-magic methods starting with a double underscore.
63
-     *
64
-     * These come from PHP modules such as SOAPClient.
65
-     *
66
-     * @var array
67
-     */
68
-    protected $methodsDoubleUnderscore = array(
69
-                                          'soapcall'               => true,
70
-                                          'getlastrequest'         => true,
71
-                                          'getlastresponse'        => true,
72
-                                          'getlastrequestheaders'  => true,
73
-                                          'getlastresponseheaders' => true,
74
-                                          'getfunctions'           => true,
75
-                                          'gettypes'               => true,
76
-                                          'dorequest'              => true,
77
-                                          'setcookie'              => true,
78
-                                          'setlocation'            => true,
79
-                                          'setsoapheaders'         => true,
80
-                                         );
81
-
82
-    /**
83
-     * A list of all PHP magic functions.
84
-     *
85
-     * @var array
86
-     */
87
-    protected $magicFunctions = array('autoload' => true);
88
-
89
-    /**
90
-     * If TRUE, the string must not have two capital letters next to each other.
91
-     *
92
-     * @var bool
93
-     */
94
-    public $strict = true;
95
-
96
-
97
-    /**
98
-     * Constructs a Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff.
99
-     */
100
-    public function __construct()
101
-    {
102
-        parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true);
103
-
104
-    }//end __construct()
105
-
106
-
107
-    /**
108
-     * Processes the tokens within the scope.
109
-     *
110
-     * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
111
-     * @param int                  $stackPtr  The position where this token was
112
-     *                                        found.
113
-     * @param int                  $currScope The position of the current scope.
114
-     *
115
-     * @return void
116
-     */
117
-    protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
118
-    {
119
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
120
-        if ($methodName === null) {
121
-            // Ignore closures.
122
-            return;
123
-        }
124
-
125
-        $className = $phpcsFile->getDeclarationName($currScope);
126
-        $errorData = array($className.'::'.$methodName);
127
-
128
-        // Is this a magic method. i.e., is prefixed with "__" ?
129
-        if (preg_match('|^__|', $methodName) !== 0) {
130
-            $magicPart = strtolower(substr($methodName, 2));
131
-            if (isset($this->magicMethods[$magicPart]) === false
132
-                && isset($this->methodsDoubleUnderscore[$magicPart]) === false
133
-            ) {
134
-                $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
135
-                $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
136
-            }
137
-
138
-            return;
139
-        }
140
-
141
-        // PHP4 constructors are allowed to break our rules.
142
-        if ($methodName === $className) {
143
-            return;
144
-        }
145
-
146
-        // PHP4 destructors are allowed to break our rules.
147
-        if ($methodName === '_'.$className) {
148
-            return;
149
-        }
150
-
151
-        // Ignore first underscore in methods prefixed with "_".
152
-        $methodName = ltrim($methodName, '_');
153
-
154
-        $methodProps = $phpcsFile->getMethodProperties($stackPtr);
155
-        if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) {
156
-            if ($methodProps['scope_specified'] === true) {
157
-                $error = '%s method name "%s" is not in camel caps format';
158
-                $data  = array(
159
-                          ucfirst($methodProps['scope']),
160
-                          $errorData[0],
161
-                         );
162
-                $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
163
-            } else {
164
-                $error = 'Method name "%s" is not in camel caps format';
165
-                $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
166
-            }
167
-
168
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
169
-            return;
170
-        } else {
171
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
172
-        }
173
-
174
-    }//end processTokenWithinScope()
175
-
176
-
177
-    /**
178
-     * Processes the tokens outside the scope.
179
-     *
180
-     * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
181
-     * @param int                  $stackPtr  The position where this token was
182
-     *                                        found.
183
-     *
184
-     * @return void
185
-     */
186
-    protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
187
-    {
188
-        $functionName = $phpcsFile->getDeclarationName($stackPtr);
189
-        if ($functionName === null) {
190
-            // Ignore closures.
191
-            return;
192
-        }
193
-
194
-        $errorData = array($functionName);
195
-
196
-        // Is this a magic function. i.e., it is prefixed with "__".
197
-        if (preg_match('|^__|', $functionName) !== 0) {
198
-            $magicPart = strtolower(substr($functionName, 2));
199
-            if (isset($this->magicFunctions[$magicPart]) === false) {
200
-                 $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
201
-                 $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
202
-            }
203
-
204
-            return;
205
-        }
206
-
207
-        // Ignore first underscore in functions prefixed with "_".
208
-        $functionName = ltrim($functionName, '_');
209
-
210
-        if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, $this->strict) === false) {
211
-            $error = 'Function name "%s" is not in camel caps format';
212
-            $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
213
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase function name', 'no');
214
-        } else {
215
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
216
-        }
217
-
218
-    }//end processTokenOutsideScope()
38
+	 /**
39
+	  * A list of all PHP magic methods.
40
+	  *
41
+	  * @var array
42
+	  */
43
+	 protected $magicMethods = array(
44
+										 'construct'  => true,
45
+										 'destruct'   => true,
46
+										 'call'       => true,
47
+										 'callstatic' => true,
48
+										 'get'        => true,
49
+										 'set'        => true,
50
+										 'isset'      => true,
51
+										 'unset'      => true,
52
+										 'sleep'      => true,
53
+										 'wakeup'     => true,
54
+										 'tostring'   => true,
55
+										 'set_state'  => true,
56
+										 'clone'      => true,
57
+										 'invoke'     => true,
58
+										 'debuginfo'  => true,
59
+										);
60
+
61
+	 /**
62
+	  * A list of all PHP non-magic methods starting with a double underscore.
63
+	  *
64
+	  * These come from PHP modules such as SOAPClient.
65
+	  *
66
+	  * @var array
67
+	  */
68
+	 protected $methodsDoubleUnderscore = array(
69
+														'soapcall'               => true,
70
+														'getlastrequest'         => true,
71
+														'getlastresponse'        => true,
72
+														'getlastrequestheaders'  => true,
73
+														'getlastresponseheaders' => true,
74
+														'getfunctions'           => true,
75
+														'gettypes'               => true,
76
+														'dorequest'              => true,
77
+														'setcookie'              => true,
78
+														'setlocation'            => true,
79
+														'setsoapheaders'         => true,
80
+													  );
81
+
82
+	 /**
83
+	  * A list of all PHP magic functions.
84
+	  *
85
+	  * @var array
86
+	  */
87
+	 protected $magicFunctions = array('autoload' => true);
88
+
89
+	 /**
90
+	  * If TRUE, the string must not have two capital letters next to each other.
91
+	  *
92
+	  * @var bool
93
+	  */
94
+	 public $strict = true;
95
+
96
+
97
+	 /**
98
+	  * Constructs a Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff.
99
+	  */
100
+	 public function __construct()
101
+	 {
102
+		  parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true);
103
+
104
+	 }//end __construct()
105
+
106
+
107
+	 /**
108
+	  * Processes the tokens within the scope.
109
+	  *
110
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
111
+	  * @param int                  $stackPtr  The position where this token was
112
+	  *                                        found.
113
+	  * @param int                  $currScope The position of the current scope.
114
+	  *
115
+	  * @return void
116
+	  */
117
+	 protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
118
+	 {
119
+		  $methodName = $phpcsFile->getDeclarationName($stackPtr);
120
+		  if ($methodName === null) {
121
+				// Ignore closures.
122
+				return;
123
+		  }
124
+
125
+		  $className = $phpcsFile->getDeclarationName($currScope);
126
+		  $errorData = array($className.'::'.$methodName);
127
+
128
+		  // Is this a magic method. i.e., is prefixed with "__" ?
129
+		  if (preg_match('|^__|', $methodName) !== 0) {
130
+				$magicPart = strtolower(substr($methodName, 2));
131
+				if (isset($this->magicMethods[$magicPart]) === false
132
+					 && isset($this->methodsDoubleUnderscore[$magicPart]) === false
133
+				) {
134
+					 $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
135
+					 $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
136
+				}
137
+
138
+				return;
139
+		  }
140
+
141
+		  // PHP4 constructors are allowed to break our rules.
142
+		  if ($methodName === $className) {
143
+				return;
144
+		  }
145
+
146
+		  // PHP4 destructors are allowed to break our rules.
147
+		  if ($methodName === '_'.$className) {
148
+				return;
149
+		  }
150
+
151
+		  // Ignore first underscore in methods prefixed with "_".
152
+		  $methodName = ltrim($methodName, '_');
153
+
154
+		  $methodProps = $phpcsFile->getMethodProperties($stackPtr);
155
+		  if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) {
156
+				if ($methodProps['scope_specified'] === true) {
157
+					 $error = '%s method name "%s" is not in camel caps format';
158
+					 $data  = array(
159
+								  ucfirst($methodProps['scope']),
160
+								  $errorData[0],
161
+								 );
162
+					 $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
163
+				} else {
164
+					 $error = 'Method name "%s" is not in camel caps format';
165
+					 $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
166
+				}
167
+
168
+				$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
169
+				return;
170
+		  } else {
171
+				$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
172
+		  }
173
+
174
+	 }//end processTokenWithinScope()
175
+
176
+
177
+	 /**
178
+	  * Processes the tokens outside the scope.
179
+	  *
180
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being processed.
181
+	  * @param int                  $stackPtr  The position where this token was
182
+	  *                                        found.
183
+	  *
184
+	  * @return void
185
+	  */
186
+	 protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
187
+	 {
188
+		  $functionName = $phpcsFile->getDeclarationName($stackPtr);
189
+		  if ($functionName === null) {
190
+				// Ignore closures.
191
+				return;
192
+		  }
193
+
194
+		  $errorData = array($functionName);
195
+
196
+		  // Is this a magic function. i.e., it is prefixed with "__".
197
+		  if (preg_match('|^__|', $functionName) !== 0) {
198
+				$magicPart = strtolower(substr($functionName, 2));
199
+				if (isset($this->magicFunctions[$magicPart]) === false) {
200
+					  $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
201
+					  $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
202
+				}
203
+
204
+				return;
205
+		  }
206
+
207
+		  // Ignore first underscore in functions prefixed with "_".
208
+		  $functionName = ltrim($functionName, '_');
209
+
210
+		  if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, $this->strict) === false) {
211
+				$error = 'Function name "%s" is not in camel caps format';
212
+				$phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
213
+				$phpcsFile->recordMetric($stackPtr, 'CamelCase function name', 'no');
214
+		  } else {
215
+				$phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
216
+		  }
217
+
218
+	 }//end processTokenOutsideScope()
219 219
 
220 220
 
221 221
 }//end class
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
  * @link      http://pear.php.net/package/PHP_CodeSniffer
14 14
  */
15 15
 
16
-if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
17
-    throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found');
16
+if ( class_exists( 'PHP_CodeSniffer_Standards_AbstractScopeSniff', true ) === false ) {
17
+    throw new PHP_CodeSniffer_Exception( 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found' );
18 18
 }
19 19
 
20 20
 /**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      *
85 85
      * @var array
86 86
      */
87
-    protected $magicFunctions = array('autoload' => true);
87
+    protected $magicFunctions = array( 'autoload' => true );
88 88
 
89 89
     /**
90 90
      * If TRUE, the string must not have two capital letters next to each other.
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function __construct()
101 101
     {
102
-        parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true);
102
+        parent::__construct( array( T_CLASS, T_INTERFACE, T_TRAIT ), array( T_FUNCTION ), true );
103 103
 
104 104
     }//end __construct()
105 105
 
@@ -114,61 +114,61 @@  discard block
 block discarded – undo
114 114
      *
115 115
      * @return void
116 116
      */
117
-    protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
117
+    protected function processTokenWithinScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope )
118 118
     {
119
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
120
-        if ($methodName === null) {
119
+        $methodName = $phpcsFile->getDeclarationName( $stackPtr );
120
+        if ( $methodName === null ) {
121 121
             // Ignore closures.
122 122
             return;
123 123
         }
124 124
 
125
-        $className = $phpcsFile->getDeclarationName($currScope);
126
-        $errorData = array($className.'::'.$methodName);
125
+        $className = $phpcsFile->getDeclarationName( $currScope );
126
+        $errorData = array( $className . '::' . $methodName );
127 127
 
128 128
         // Is this a magic method. i.e., is prefixed with "__" ?
129
-        if (preg_match('|^__|', $methodName) !== 0) {
130
-            $magicPart = strtolower(substr($methodName, 2));
131
-            if (isset($this->magicMethods[$magicPart]) === false
132
-                && isset($this->methodsDoubleUnderscore[$magicPart]) === false
129
+        if ( preg_match( '|^__|', $methodName ) !== 0 ) {
130
+            $magicPart = strtolower( substr( $methodName, 2 ) );
131
+            if ( isset( $this->magicMethods[ $magicPart ] ) === false
132
+                && isset( $this->methodsDoubleUnderscore[ $magicPart ] ) === false
133 133
             ) {
134 134
                 $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
135
-                $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
135
+                $phpcsFile->addError( $error, $stackPtr, 'MethodDoubleUnderscore', $errorData );
136 136
             }
137 137
 
138 138
             return;
139 139
         }
140 140
 
141 141
         // PHP4 constructors are allowed to break our rules.
142
-        if ($methodName === $className) {
142
+        if ( $methodName === $className ) {
143 143
             return;
144 144
         }
145 145
 
146 146
         // PHP4 destructors are allowed to break our rules.
147
-        if ($methodName === '_'.$className) {
147
+        if ( $methodName === '_' . $className ) {
148 148
             return;
149 149
         }
150 150
 
151 151
         // Ignore first underscore in methods prefixed with "_".
152
-        $methodName = ltrim($methodName, '_');
152
+        $methodName = ltrim( $methodName, '_' );
153 153
 
154
-        $methodProps = $phpcsFile->getMethodProperties($stackPtr);
155
-        if (PHP_CodeSniffer::isCamelCaps($methodName, false, true, $this->strict) === false) {
156
-            if ($methodProps['scope_specified'] === true) {
154
+        $methodProps = $phpcsFile->getMethodProperties( $stackPtr );
155
+        if ( PHP_CodeSniffer::isCamelCaps( $methodName, false, true, $this->strict ) === false ) {
156
+            if ( $methodProps[ 'scope_specified' ] === true ) {
157 157
                 $error = '%s method name "%s" is not in camel caps format';
158 158
                 $data  = array(
159
-                          ucfirst($methodProps['scope']),
160
-                          $errorData[0],
159
+                          ucfirst( $methodProps[ 'scope' ] ),
160
+                          $errorData[ 0 ],
161 161
                          );
162
-                $phpcsFile->addError($error, $stackPtr, 'ScopeNotCamelCaps', $data);
162
+                $phpcsFile->addError( $error, $stackPtr, 'ScopeNotCamelCaps', $data );
163 163
             } else {
164 164
                 $error = 'Method name "%s" is not in camel caps format';
165
-                $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
165
+                $phpcsFile->addError( $error, $stackPtr, 'NotCamelCaps', $errorData );
166 166
             }
167 167
 
168
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'no');
168
+            $phpcsFile->recordMetric( $stackPtr, 'CamelCase method name', 'no' );
169 169
             return;
170 170
         } else {
171
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
171
+            $phpcsFile->recordMetric( $stackPtr, 'CamelCase method name', 'yes' );
172 172
         }
173 173
 
174 174
     }//end processTokenWithinScope()
@@ -183,36 +183,36 @@  discard block
 block discarded – undo
183 183
      *
184 184
      * @return void
185 185
      */
186
-    protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
186
+    protected function processTokenOutsideScope( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
187 187
     {
188
-        $functionName = $phpcsFile->getDeclarationName($stackPtr);
189
-        if ($functionName === null) {
188
+        $functionName = $phpcsFile->getDeclarationName( $stackPtr );
189
+        if ( $functionName === null ) {
190 190
             // Ignore closures.
191 191
             return;
192 192
         }
193 193
 
194
-        $errorData = array($functionName);
194
+        $errorData = array( $functionName );
195 195
 
196 196
         // Is this a magic function. i.e., it is prefixed with "__".
197
-        if (preg_match('|^__|', $functionName) !== 0) {
198
-            $magicPart = strtolower(substr($functionName, 2));
199
-            if (isset($this->magicFunctions[$magicPart]) === false) {
197
+        if ( preg_match( '|^__|', $functionName ) !== 0 ) {
198
+            $magicPart = strtolower( substr( $functionName, 2 ) );
199
+            if ( isset( $this->magicFunctions[ $magicPart ] ) === false ) {
200 200
                  $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
201
-                 $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
201
+                 $phpcsFile->addError( $error, $stackPtr, 'FunctionDoubleUnderscore', $errorData );
202 202
             }
203 203
 
204 204
             return;
205 205
         }
206 206
 
207 207
         // Ignore first underscore in functions prefixed with "_".
208
-        $functionName = ltrim($functionName, '_');
208
+        $functionName = ltrim( $functionName, '_' );
209 209
 
210
-        if (PHP_CodeSniffer::isCamelCaps($functionName, false, true, $this->strict) === false) {
210
+        if ( PHP_CodeSniffer::isCamelCaps( $functionName, false, true, $this->strict ) === false ) {
211 211
             $error = 'Function name "%s" is not in camel caps format';
212
-            $phpcsFile->addError($error, $stackPtr, 'NotCamelCaps', $errorData);
213
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase function name', 'no');
212
+            $phpcsFile->addError( $error, $stackPtr, 'NotCamelCaps', $errorData );
213
+            $phpcsFile->recordMetric( $stackPtr, 'CamelCase function name', 'no' );
214 214
         } else {
215
-            $phpcsFile->recordMetric($stackPtr, 'CamelCase method name', 'yes');
215
+            $phpcsFile->recordMetric( $stackPtr, 'CamelCase method name', 'yes' );
216 216
         }
217 217
 
218 218
     }//end processTokenOutsideScope()
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,8 +32,7 @@  discard block
 block discarded – undo
32 32
  * @version   Release: @package_version@
33 33
  * @link      http://pear.php.net/package/PHP_CodeSniffer
34 34
  */
35
-class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
36
-{
35
+class Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff {
37 36
 
38 37
     /**
39 38
      * A list of all PHP magic methods.
@@ -97,8 +96,7 @@  discard block
 block discarded – undo
97 96
     /**
98 97
      * Constructs a Generic_Sniffs_NamingConventions_CamelCapsFunctionNameSniff.
99 98
      */
100
-    public function __construct()
101
-    {
99
+    public function __construct() {
102 100
         parent::__construct(array(T_CLASS, T_INTERFACE, T_TRAIT), array(T_FUNCTION), true);
103 101
 
104 102
     }//end __construct()
@@ -114,8 +112,7 @@  discard block
 block discarded – undo
114 112
      *
115 113
      * @return void
116 114
      */
117
-    protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
118
-    {
115
+    protected function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope) {
119 116
         $methodName = $phpcsFile->getDeclarationName($stackPtr);
120 117
         if ($methodName === null) {
121 118
             // Ignore closures.
@@ -183,8 +180,7 @@  discard block
 block discarded – undo
183 180
      *
184 181
      * @return void
185 182
      */
186
-    protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
187
-    {
183
+    protected function processTokenOutsideScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
188 184
         $functionName = $phpcsFile->getDeclarationName($stackPtr);
189 185
         if ($functionName === null) {
190 186
             // Ignore closures.
Please login to merge, or discard this patch.
Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php 3 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -31,157 +31,157 @@
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(T_STRING);
42
-
43
-    }//end register()
44
-
45
-
46
-    /**
47
-     * Processes this test, when one of its tokens is encountered.
48
-     *
49
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
-     * @param int                  $stackPtr  The position of the current token in the
51
-     *                                        stack passed in $tokens.
52
-     *
53
-     * @return void
54
-     */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
57
-        $tokens    = $phpcsFile->getTokens();
58
-        $constName = $tokens[$stackPtr]['content'];
59
-
60
-        // If this token is in a heredoc, ignore it.
61
-        if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
62
-            return;
63
-        }
64
-
65
-        // Special case for PHP 5.5 class name resolution.
66
-        if (strtolower($constName) === 'class'
67
-            && $tokens[($stackPtr - 1)]['code'] === T_DOUBLE_COLON
68
-        ) {
69
-            return;
70
-        }
71
-
72
-        // Special case for PHPUnit.
73
-        if ($constName === 'PHPUnit_MAIN_METHOD') {
74
-            return;
75
-        }
76
-
77
-        // If the next non-whitespace token after this token
78
-        // is not an opening parenthesis then it is not a function call.
79
-        for ($openBracket = ($stackPtr + 1); $openBracket < $phpcsFile->numTokens; $openBracket++) {
80
-            if ($tokens[$openBracket]['code'] !== T_WHITESPACE) {
81
-                break;
82
-            }
83
-        }
84
-
85
-        if ($openBracket === $phpcsFile->numTokens) {
86
-            return;
87
-        }
88
-
89
-        if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
90
-            $functionKeyword = $phpcsFile->findPrevious(
91
-                array(
92
-                 T_WHITESPACE,
93
-                 T_COMMA,
94
-                 T_COMMENT,
95
-                 T_STRING,
96
-                 T_NS_SEPARATOR,
97
-                ),
98
-                ($stackPtr - 1),
99
-                null,
100
-                true
101
-            );
102
-
103
-            if ($tokens[$functionKeyword]['code'] !== T_CONST) {
104
-                return;
105
-            }
106
-
107
-            // This is a class constant.
108
-            if (strtoupper($constName) !== $constName) {
109
-                if (strtolower($constName) === $constName) {
110
-                    $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
111
-                } else {
112
-                    $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
113
-                }
114
-
115
-                $error = 'Class constants must be uppercase; expected %s but found %s';
116
-                $data  = array(
117
-                          strtoupper($constName),
118
-                          $constName,
119
-                         );
120
-                $phpcsFile->addError($error, $stackPtr, 'ClassConstantNotUpperCase', $data);
121
-            } else {
122
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
123
-            }
124
-
125
-            return;
126
-        }//end if
127
-
128
-        if (strtolower($constName) !== 'define') {
129
-            return;
130
-        }
131
-
132
-        /*
34
+	 /**
35
+	  * Returns an array of tokens this test wants to listen for.
36
+	  *
37
+	  * @return array
38
+	  */
39
+	 public function register()
40
+	 {
41
+		  return array(T_STRING);
42
+
43
+	 }//end register()
44
+
45
+
46
+	 /**
47
+	  * Processes this test, when one of its tokens is encountered.
48
+	  *
49
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
+	  * @param int                  $stackPtr  The position of the current token in the
51
+	  *                                        stack passed in $tokens.
52
+	  *
53
+	  * @return void
54
+	  */
55
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
+	 {
57
+		  $tokens    = $phpcsFile->getTokens();
58
+		  $constName = $tokens[$stackPtr]['content'];
59
+
60
+		  // If this token is in a heredoc, ignore it.
61
+		  if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
62
+				return;
63
+		  }
64
+
65
+		  // Special case for PHP 5.5 class name resolution.
66
+		  if (strtolower($constName) === 'class'
67
+				&& $tokens[($stackPtr - 1)]['code'] === T_DOUBLE_COLON
68
+		  ) {
69
+				return;
70
+		  }
71
+
72
+		  // Special case for PHPUnit.
73
+		  if ($constName === 'PHPUnit_MAIN_METHOD') {
74
+				return;
75
+		  }
76
+
77
+		  // If the next non-whitespace token after this token
78
+		  // is not an opening parenthesis then it is not a function call.
79
+		  for ($openBracket = ($stackPtr + 1); $openBracket < $phpcsFile->numTokens; $openBracket++) {
80
+				if ($tokens[$openBracket]['code'] !== T_WHITESPACE) {
81
+					 break;
82
+				}
83
+		  }
84
+
85
+		  if ($openBracket === $phpcsFile->numTokens) {
86
+				return;
87
+		  }
88
+
89
+		  if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
90
+				$functionKeyword = $phpcsFile->findPrevious(
91
+					 array(
92
+					  T_WHITESPACE,
93
+					  T_COMMA,
94
+					  T_COMMENT,
95
+					  T_STRING,
96
+					  T_NS_SEPARATOR,
97
+					 ),
98
+					 ($stackPtr - 1),
99
+					 null,
100
+					 true
101
+				);
102
+
103
+				if ($tokens[$functionKeyword]['code'] !== T_CONST) {
104
+					 return;
105
+				}
106
+
107
+				// This is a class constant.
108
+				if (strtoupper($constName) !== $constName) {
109
+					 if (strtolower($constName) === $constName) {
110
+						  $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
111
+					 } else {
112
+						  $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
113
+					 }
114
+
115
+					 $error = 'Class constants must be uppercase; expected %s but found %s';
116
+					 $data  = array(
117
+								  strtoupper($constName),
118
+								  $constName,
119
+								 );
120
+					 $phpcsFile->addError($error, $stackPtr, 'ClassConstantNotUpperCase', $data);
121
+				} else {
122
+					 $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
123
+				}
124
+
125
+				return;
126
+		  }//end if
127
+
128
+		  if (strtolower($constName) !== 'define') {
129
+				return;
130
+		  }
131
+
132
+		  /*
133 133
             This may be a "define" function call.
134 134
         */
135 135
 
136
-        // Make sure this is not a method call.
137
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
138
-        if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR
139
-            || $tokens[$prev]['code'] === T_DOUBLE_COLON
140
-        ) {
141
-            return;
142
-        }
143
-
144
-        // The next non-whitespace token must be the constant name.
145
-        $constPtr = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
146
-        if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
147
-            return;
148
-        }
149
-
150
-        $constName = $tokens[$constPtr]['content'];
151
-
152
-        // Check for constants like self::CONSTANT.
153
-        $prefix   = '';
154
-        $splitPos = strpos($constName, '::');
155
-        if ($splitPos !== false) {
156
-            $prefix    = substr($constName, 0, ($splitPos + 2));
157
-            $constName = substr($constName, ($splitPos + 2));
158
-        }
159
-
160
-        // Strip namesspace from constant like /foo/bar/CONSTANT.
161
-        $splitPos = strrpos($constName, '\\');
162
-        if ($splitPos !== false) {
163
-            $prefix    = substr($constName, 0, ($splitPos + 1));
164
-            $constName = substr($constName, ($splitPos + 1));
165
-        }
166
-
167
-        if (strtoupper($constName) !== $constName) {
168
-            if (strtolower($constName) === $constName) {
169
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
170
-            } else {
171
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
172
-            }
173
-
174
-            $error = 'Constants must be uppercase; expected %s but found %s';
175
-            $data  = array(
176
-                      $prefix.strtoupper($constName),
177
-                      $prefix.$constName,
178
-                     );
179
-            $phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
180
-        } else {
181
-            $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
182
-        }
183
-
184
-    }//end process()
136
+		  // Make sure this is not a method call.
137
+		  $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
138
+		  if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR
139
+				|| $tokens[$prev]['code'] === T_DOUBLE_COLON
140
+		  ) {
141
+				return;
142
+		  }
143
+
144
+		  // The next non-whitespace token must be the constant name.
145
+		  $constPtr = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
146
+		  if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
147
+				return;
148
+		  }
149
+
150
+		  $constName = $tokens[$constPtr]['content'];
151
+
152
+		  // Check for constants like self::CONSTANT.
153
+		  $prefix   = '';
154
+		  $splitPos = strpos($constName, '::');
155
+		  if ($splitPos !== false) {
156
+				$prefix    = substr($constName, 0, ($splitPos + 2));
157
+				$constName = substr($constName, ($splitPos + 2));
158
+		  }
159
+
160
+		  // Strip namesspace from constant like /foo/bar/CONSTANT.
161
+		  $splitPos = strrpos($constName, '\\');
162
+		  if ($splitPos !== false) {
163
+				$prefix    = substr($constName, 0, ($splitPos + 1));
164
+				$constName = substr($constName, ($splitPos + 1));
165
+		  }
166
+
167
+		  if (strtoupper($constName) !== $constName) {
168
+				if (strtolower($constName) === $constName) {
169
+					 $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
170
+				} else {
171
+					 $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
172
+				}
173
+
174
+				$error = 'Constants must be uppercase; expected %s but found %s';
175
+				$data  = array(
176
+							 $prefix.strtoupper($constName),
177
+							 $prefix.$constName,
178
+							);
179
+				$phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
180
+		  } else {
181
+				$phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
182
+		  }
183
+
184
+	 }//end process()
185 185
 
186 186
 
187 187
 }//end class
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(T_STRING);
41
+        return array( T_STRING );
42 42
 
43 43
     }//end register()
44 44
 
@@ -52,41 +52,41 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
56 56
     {
57 57
         $tokens    = $phpcsFile->getTokens();
58
-        $constName = $tokens[$stackPtr]['content'];
58
+        $constName = $tokens[ $stackPtr ][ 'content' ];
59 59
 
60 60
         // If this token is in a heredoc, ignore it.
61
-        if ($phpcsFile->hasCondition($stackPtr, T_START_HEREDOC) === true) {
61
+        if ( $phpcsFile->hasCondition( $stackPtr, T_START_HEREDOC ) === true ) {
62 62
             return;
63 63
         }
64 64
 
65 65
         // Special case for PHP 5.5 class name resolution.
66
-        if (strtolower($constName) === 'class'
67
-            && $tokens[($stackPtr - 1)]['code'] === T_DOUBLE_COLON
66
+        if ( strtolower( $constName ) === 'class'
67
+            && $tokens[ ( $stackPtr - 1 ) ][ 'code' ] === T_DOUBLE_COLON
68 68
         ) {
69 69
             return;
70 70
         }
71 71
 
72 72
         // Special case for PHPUnit.
73
-        if ($constName === 'PHPUnit_MAIN_METHOD') {
73
+        if ( $constName === 'PHPUnit_MAIN_METHOD' ) {
74 74
             return;
75 75
         }
76 76
 
77 77
         // If the next non-whitespace token after this token
78 78
         // is not an opening parenthesis then it is not a function call.
79
-        for ($openBracket = ($stackPtr + 1); $openBracket < $phpcsFile->numTokens; $openBracket++) {
80
-            if ($tokens[$openBracket]['code'] !== T_WHITESPACE) {
79
+        for ( $openBracket = ( $stackPtr + 1 ); $openBracket < $phpcsFile->numTokens; $openBracket++ ) {
80
+            if ( $tokens[ $openBracket ][ 'code' ] !== T_WHITESPACE ) {
81 81
                 break;
82 82
             }
83 83
         }
84 84
 
85
-        if ($openBracket === $phpcsFile->numTokens) {
85
+        if ( $openBracket === $phpcsFile->numTokens ) {
86 86
             return;
87 87
         }
88 88
 
89
-        if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
89
+        if ( $tokens[ $openBracket ][ 'code' ] !== T_OPEN_PARENTHESIS ) {
90 90
             $functionKeyword = $phpcsFile->findPrevious(
91 91
                 array(
92 92
                  T_WHITESPACE,
@@ -95,37 +95,37 @@  discard block
 block discarded – undo
95 95
                  T_STRING,
96 96
                  T_NS_SEPARATOR,
97 97
                 ),
98
-                ($stackPtr - 1),
98
+                ( $stackPtr - 1 ),
99 99
                 null,
100 100
                 true
101 101
             );
102 102
 
103
-            if ($tokens[$functionKeyword]['code'] !== T_CONST) {
103
+            if ( $tokens[ $functionKeyword ][ 'code' ] !== T_CONST ) {
104 104
                 return;
105 105
             }
106 106
 
107 107
             // This is a class constant.
108
-            if (strtoupper($constName) !== $constName) {
109
-                if (strtolower($constName) === $constName) {
110
-                    $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
108
+            if ( strtoupper( $constName ) !== $constName ) {
109
+                if ( strtolower( $constName ) === $constName ) {
110
+                    $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'lower' );
111 111
                 } else {
112
-                    $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
112
+                    $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'mixed' );
113 113
                 }
114 114
 
115 115
                 $error = 'Class constants must be uppercase; expected %s but found %s';
116 116
                 $data  = array(
117
-                          strtoupper($constName),
117
+                          strtoupper( $constName ),
118 118
                           $constName,
119 119
                          );
120
-                $phpcsFile->addError($error, $stackPtr, 'ClassConstantNotUpperCase', $data);
120
+                $phpcsFile->addError( $error, $stackPtr, 'ClassConstantNotUpperCase', $data );
121 121
             } else {
122
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
122
+                $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'upper' );
123 123
             }
124 124
 
125 125
             return;
126 126
         }//end if
127 127
 
128
-        if (strtolower($constName) !== 'define') {
128
+        if ( strtolower( $constName ) !== 'define' ) {
129 129
             return;
130 130
         }
131 131
 
@@ -134,51 +134,51 @@  discard block
 block discarded – undo
134 134
         */
135 135
 
136 136
         // Make sure this is not a method call.
137
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
138
-        if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR
139
-            || $tokens[$prev]['code'] === T_DOUBLE_COLON
137
+        $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
138
+        if ( $tokens[ $prev ][ 'code' ] === T_OBJECT_OPERATOR
139
+            || $tokens[ $prev ][ 'code' ] === T_DOUBLE_COLON
140 140
         ) {
141 141
             return;
142 142
         }
143 143
 
144 144
         // The next non-whitespace token must be the constant name.
145
-        $constPtr = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
146
-        if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
145
+        $constPtr = $phpcsFile->findNext( T_WHITESPACE, ( $openBracket + 1 ), null, true );
146
+        if ( $tokens[ $constPtr ][ 'code' ] !== T_CONSTANT_ENCAPSED_STRING ) {
147 147
             return;
148 148
         }
149 149
 
150
-        $constName = $tokens[$constPtr]['content'];
150
+        $constName = $tokens[ $constPtr ][ 'content' ];
151 151
 
152 152
         // Check for constants like self::CONSTANT.
153 153
         $prefix   = '';
154
-        $splitPos = strpos($constName, '::');
155
-        if ($splitPos !== false) {
156
-            $prefix    = substr($constName, 0, ($splitPos + 2));
157
-            $constName = substr($constName, ($splitPos + 2));
154
+        $splitPos = strpos( $constName, '::' );
155
+        if ( $splitPos !== false ) {
156
+            $prefix    = substr( $constName, 0, ( $splitPos + 2 ) );
157
+            $constName = substr( $constName, ( $splitPos + 2 ) );
158 158
         }
159 159
 
160 160
         // Strip namesspace from constant like /foo/bar/CONSTANT.
161
-        $splitPos = strrpos($constName, '\\');
162
-        if ($splitPos !== false) {
163
-            $prefix    = substr($constName, 0, ($splitPos + 1));
164
-            $constName = substr($constName, ($splitPos + 1));
161
+        $splitPos = strrpos( $constName, '\\' );
162
+        if ( $splitPos !== false ) {
163
+            $prefix    = substr( $constName, 0, ( $splitPos + 1 ) );
164
+            $constName = substr( $constName, ( $splitPos + 1 ) );
165 165
         }
166 166
 
167
-        if (strtoupper($constName) !== $constName) {
168
-            if (strtolower($constName) === $constName) {
169
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
167
+        if ( strtoupper( $constName ) !== $constName ) {
168
+            if ( strtolower( $constName ) === $constName ) {
169
+                $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'lower' );
170 170
             } else {
171
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
171
+                $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'mixed' );
172 172
             }
173 173
 
174 174
             $error = 'Constants must be uppercase; expected %s but found %s';
175 175
             $data  = array(
176
-                      $prefix.strtoupper($constName),
177
-                      $prefix.$constName,
176
+                      $prefix . strtoupper( $constName ),
177
+                      $prefix . $constName,
178 178
                      );
179
-            $phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
179
+            $phpcsFile->addError( $error, $stackPtr, 'ConstantNotUpperCase', $data );
180 180
         } else {
181
-            $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
181
+            $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'upper' );
182 182
         }
183 183
 
184 184
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Generic_Sniffs_NamingConventions_UpperCaseConstantNameSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
 
34 33
     /**
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(T_STRING);
42 40
 
43 41
     }//end register()
@@ -52,8 +50,7 @@  discard block
 block discarded – undo
52 50
      *
53 51
      * @return void
54 52
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
53
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
57 54
         $tokens    = $phpcsFile->getTokens();
58 55
         $constName = $tokens[$stackPtr]['content'];
59 56
 
Please login to merge, or discard this patch.
Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php 3 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -14,8 +14,8 @@  discard block
 block discarded – undo
14 14
  */
15 15
 
16 16
 if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
17
-    $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
18
-    throw new PHP_CodeSniffer_Exception($error);
17
+	 $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
18
+	 throw new PHP_CodeSniffer_Exception($error);
19 19
 }
20 20
 
21 21
 /**
@@ -34,115 +34,115 @@  discard block
 block discarded – undo
34 34
 class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
35 35
 {
36 36
 
37
-    /**
38
-     * The name of the class we are currently checking.
39
-     *
40
-     * @var string
41
-     */
42
-    private $_currentClass = '';
43
-
44
-    /**
45
-     * A list of functions in the current class.
46
-     *
47
-     * @var string[]
48
-     */
49
-    private $_functionList = array();
50
-
51
-
52
-    /**
53
-     * Constructs the test with the tokens it wishes to listen for.
54
-     */
55
-    public function __construct()
56
-    {
57
-        parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
58
-
59
-    }//end __construct()
60
-
61
-
62
-    /**
63
-     * Processes this test when one of its tokens is encountered.
64
-     *
65
-     * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
66
-     * @param int                  $stackPtr  The position of the current token
67
-     *                                        in the stack passed in $tokens.
68
-     * @param int                  $currScope A pointer to the start of the scope.
69
-     *
70
-     * @return void
71
-     */
72
-    protected function processTokenWithinScope(
73
-        PHP_CodeSniffer_File $phpcsFile,
74
-        $stackPtr,
75
-        $currScope
76
-    ) {
77
-        $className = $phpcsFile->getDeclarationName($currScope);
78
-        if ($className !== $this->_currentClass) {
79
-            $this->loadFunctionNamesInScope($phpcsFile, $currScope);
80
-            $this->_currentClass = $className;
81
-        }
82
-
83
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
84
-
85
-        if (strcasecmp($methodName, $className) === 0) {
86
-            if (in_array('__construct', $this->_functionList) === false) {
87
-                $error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
88
-                $phpcsFile->addError($error, $stackPtr, 'OldStyle');
89
-            }
90
-        } else if (strcasecmp($methodName, '__construct') !== 0) {
91
-            // Not a constructor.
92
-            return;
93
-        }
94
-
95
-        $tokens = $phpcsFile->getTokens();
96
-
97
-        $parentClassName = $phpcsFile->findExtendedClassName($currScope);
98
-        if ($parentClassName === false) {
99
-            return;
100
-        }
101
-
102
-        // Stop if the constructor doesn't have a body, like when it is abstract.
103
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
104
-            return;
105
-        }
106
-
107
-        $endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
108
-        $startIndex       = $stackPtr;
109
-        while (($doubleColonIndex = $phpcsFile->findNext(T_DOUBLE_COLON, $startIndex, $endFunctionIndex)) !== false) {
110
-            if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
111
-                && $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName
112
-            ) {
113
-                $error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
114
-                $phpcsFile->addError($error, ($doubleColonIndex + 1), 'OldStyleCall');
115
-            }
116
-
117
-            $startIndex = ($doubleColonIndex + 1);
118
-        }
119
-
120
-    }//end processTokenWithinScope()
121
-
122
-
123
-    /**
124
-     * Extracts all the function names found in the given scope.
125
-     *
126
-     * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
127
-     * @param int                  $currScope A pointer to the start of the scope.
128
-     *
129
-     * @return void
130
-     */
131
-    protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope)
132
-    {
133
-        $this->_functionList = array();
134
-        $tokens = $phpcsFile->getTokens();
135
-
136
-        for ($i = ($tokens[$currScope]['scope_opener'] + 1); $i < $tokens[$currScope]['scope_closer']; $i++) {
137
-            if ($tokens[$i]['code'] !== T_FUNCTION) {
138
-                continue;
139
-            }
140
-
141
-            $next = $phpcsFile->findNext(T_STRING, $i);
142
-            $this->_functionList[] = trim($tokens[$next]['content']);
143
-        }
144
-
145
-    }//end loadFunctionNamesInScope()
37
+	 /**
38
+	  * The name of the class we are currently checking.
39
+	  *
40
+	  * @var string
41
+	  */
42
+	 private $_currentClass = '';
43
+
44
+	 /**
45
+	  * A list of functions in the current class.
46
+	  *
47
+	  * @var string[]
48
+	  */
49
+	 private $_functionList = array();
50
+
51
+
52
+	 /**
53
+	  * Constructs the test with the tokens it wishes to listen for.
54
+	  */
55
+	 public function __construct()
56
+	 {
57
+		  parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
58
+
59
+	 }//end __construct()
60
+
61
+
62
+	 /**
63
+	  * Processes this test when one of its tokens is encountered.
64
+	  *
65
+	  * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
66
+	  * @param int                  $stackPtr  The position of the current token
67
+	  *                                        in the stack passed in $tokens.
68
+	  * @param int                  $currScope A pointer to the start of the scope.
69
+	  *
70
+	  * @return void
71
+	  */
72
+	 protected function processTokenWithinScope(
73
+		  PHP_CodeSniffer_File $phpcsFile,
74
+		  $stackPtr,
75
+		  $currScope
76
+	 ) {
77
+		  $className = $phpcsFile->getDeclarationName($currScope);
78
+		  if ($className !== $this->_currentClass) {
79
+				$this->loadFunctionNamesInScope($phpcsFile, $currScope);
80
+				$this->_currentClass = $className;
81
+		  }
82
+
83
+		  $methodName = $phpcsFile->getDeclarationName($stackPtr);
84
+
85
+		  if (strcasecmp($methodName, $className) === 0) {
86
+				if (in_array('__construct', $this->_functionList) === false) {
87
+					 $error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
88
+					 $phpcsFile->addError($error, $stackPtr, 'OldStyle');
89
+				}
90
+		  } else if (strcasecmp($methodName, '__construct') !== 0) {
91
+				// Not a constructor.
92
+				return;
93
+		  }
94
+
95
+		  $tokens = $phpcsFile->getTokens();
96
+
97
+		  $parentClassName = $phpcsFile->findExtendedClassName($currScope);
98
+		  if ($parentClassName === false) {
99
+				return;
100
+		  }
101
+
102
+		  // Stop if the constructor doesn't have a body, like when it is abstract.
103
+		  if (isset($tokens[$stackPtr]['scope_closer']) === false) {
104
+				return;
105
+		  }
106
+
107
+		  $endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
108
+		  $startIndex       = $stackPtr;
109
+		  while (($doubleColonIndex = $phpcsFile->findNext(T_DOUBLE_COLON, $startIndex, $endFunctionIndex)) !== false) {
110
+				if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
111
+					 && $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName
112
+				) {
113
+					 $error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
114
+					 $phpcsFile->addError($error, ($doubleColonIndex + 1), 'OldStyleCall');
115
+				}
116
+
117
+				$startIndex = ($doubleColonIndex + 1);
118
+		  }
119
+
120
+	 }//end processTokenWithinScope()
121
+
122
+
123
+	 /**
124
+	  * Extracts all the function names found in the given scope.
125
+	  *
126
+	  * @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
127
+	  * @param int                  $currScope A pointer to the start of the scope.
128
+	  *
129
+	  * @return void
130
+	  */
131
+	 protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope)
132
+	 {
133
+		  $this->_functionList = array();
134
+		  $tokens = $phpcsFile->getTokens();
135
+
136
+		  for ($i = ($tokens[$currScope]['scope_opener'] + 1); $i < $tokens[$currScope]['scope_closer']; $i++) {
137
+				if ($tokens[$i]['code'] !== T_FUNCTION) {
138
+					 continue;
139
+				}
140
+
141
+				$next = $phpcsFile->findNext(T_STRING, $i);
142
+				$this->_functionList[] = trim($tokens[$next]['content']);
143
+		  }
144
+
145
+	 }//end loadFunctionNamesInScope()
146 146
 
147 147
 
148 148
 }//end class
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
  * @link      http://pear.php.net/package/PHP_CodeSniffer
14 14
  */
15 15
 
16
-if (class_exists('PHP_CodeSniffer_Standards_AbstractScopeSniff', true) === false) {
16
+if ( class_exists( 'PHP_CodeSniffer_Standards_AbstractScopeSniff', true ) === false ) {
17 17
     $error = 'Class PHP_CodeSniffer_Standards_AbstractScopeSniff not found';
18
-    throw new PHP_CodeSniffer_Exception($error);
18
+    throw new PHP_CodeSniffer_Exception( $error );
19 19
 }
20 20
 
21 21
 /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function __construct()
56 56
     {
57
-        parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
57
+        parent::__construct( array( T_CLASS, T_INTERFACE ), array( T_FUNCTION ), true );
58 58
 
59 59
     }//end __construct()
60 60
 
@@ -74,47 +74,47 @@  discard block
 block discarded – undo
74 74
         $stackPtr,
75 75
         $currScope
76 76
     ) {
77
-        $className = $phpcsFile->getDeclarationName($currScope);
78
-        if ($className !== $this->_currentClass) {
79
-            $this->loadFunctionNamesInScope($phpcsFile, $currScope);
77
+        $className = $phpcsFile->getDeclarationName( $currScope );
78
+        if ( $className !== $this->_currentClass ) {
79
+            $this->loadFunctionNamesInScope( $phpcsFile, $currScope );
80 80
             $this->_currentClass = $className;
81 81
         }
82 82
 
83
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
83
+        $methodName = $phpcsFile->getDeclarationName( $stackPtr );
84 84
 
85
-        if (strcasecmp($methodName, $className) === 0) {
86
-            if (in_array('__construct', $this->_functionList) === false) {
85
+        if ( strcasecmp( $methodName, $className ) === 0 ) {
86
+            if ( in_array( '__construct', $this->_functionList ) === false ) {
87 87
                 $error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
88
-                $phpcsFile->addError($error, $stackPtr, 'OldStyle');
88
+                $phpcsFile->addError( $error, $stackPtr, 'OldStyle' );
89 89
             }
90
-        } else if (strcasecmp($methodName, '__construct') !== 0) {
90
+        } else if ( strcasecmp( $methodName, '__construct' ) !== 0 ) {
91 91
             // Not a constructor.
92 92
             return;
93 93
         }
94 94
 
95 95
         $tokens = $phpcsFile->getTokens();
96 96
 
97
-        $parentClassName = $phpcsFile->findExtendedClassName($currScope);
98
-        if ($parentClassName === false) {
97
+        $parentClassName = $phpcsFile->findExtendedClassName( $currScope );
98
+        if ( $parentClassName === false ) {
99 99
             return;
100 100
         }
101 101
 
102 102
         // Stop if the constructor doesn't have a body, like when it is abstract.
103
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
103
+        if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
104 104
             return;
105 105
         }
106 106
 
107
-        $endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
107
+        $endFunctionIndex = $tokens[ $stackPtr ][ 'scope_closer' ];
108 108
         $startIndex       = $stackPtr;
109
-        while (($doubleColonIndex = $phpcsFile->findNext(T_DOUBLE_COLON, $startIndex, $endFunctionIndex)) !== false) {
110
-            if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
111
-                && $tokens[($doubleColonIndex + 1)]['content'] === $parentClassName
109
+        while ( ( $doubleColonIndex = $phpcsFile->findNext( T_DOUBLE_COLON, $startIndex, $endFunctionIndex ) ) !== false ) {
110
+            if ( $tokens[ ( $doubleColonIndex + 1 ) ][ 'code' ] === T_STRING
111
+                && $tokens[ ( $doubleColonIndex + 1 ) ][ 'content' ] === $parentClassName
112 112
             ) {
113 113
                 $error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
114
-                $phpcsFile->addError($error, ($doubleColonIndex + 1), 'OldStyleCall');
114
+                $phpcsFile->addError( $error, ( $doubleColonIndex + 1 ), 'OldStyleCall' );
115 115
             }
116 116
 
117
-            $startIndex = ($doubleColonIndex + 1);
117
+            $startIndex = ( $doubleColonIndex + 1 );
118 118
         }
119 119
 
120 120
     }//end processTokenWithinScope()
@@ -128,18 +128,18 @@  discard block
 block discarded – undo
128 128
      *
129 129
      * @return void
130 130
      */
131
-    protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope)
131
+    protected function loadFunctionNamesInScope( PHP_CodeSniffer_File $phpcsFile, $currScope )
132 132
     {
133 133
         $this->_functionList = array();
134 134
         $tokens = $phpcsFile->getTokens();
135 135
 
136
-        for ($i = ($tokens[$currScope]['scope_opener'] + 1); $i < $tokens[$currScope]['scope_closer']; $i++) {
137
-            if ($tokens[$i]['code'] !== T_FUNCTION) {
136
+        for ( $i = ( $tokens[ $currScope ][ 'scope_opener' ] + 1 ); $i < $tokens[ $currScope ][ 'scope_closer' ]; $i++ ) {
137
+            if ( $tokens[ $i ][ 'code' ] !== T_FUNCTION ) {
138 138
                 continue;
139 139
             }
140 140
 
141
-            $next = $phpcsFile->findNext(T_STRING, $i);
142
-            $this->_functionList[] = trim($tokens[$next]['content']);
141
+            $next = $phpcsFile->findNext( T_STRING, $i );
142
+            $this->_functionList[ ] = trim( $tokens[ $next ][ 'content' ] );
143 143
         }
144 144
 
145 145
     }//end loadFunctionNamesInScope()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -31,8 +31,7 @@  discard block
 block discarded – undo
31 31
  * @version  Release: @package_version@
32 32
  * @link     http://pear.php.net/package/PHP_CodeSniffer
33 33
  */
34
-class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff
35
-{
34
+class Generic_Sniffs_NamingConventions_ConstructorNameSniff extends PHP_CodeSniffer_Standards_AbstractScopeSniff {
36 35
 
37 36
     /**
38 37
      * The name of the class we are currently checking.
@@ -52,8 +51,7 @@  discard block
 block discarded – undo
52 51
     /**
53 52
      * Constructs the test with the tokens it wishes to listen for.
54 53
      */
55
-    public function __construct()
56
-    {
54
+    public function __construct() {
57 55
         parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
58 56
 
59 57
     }//end __construct()
@@ -128,8 +126,7 @@  discard block
 block discarded – undo
128 126
      *
129 127
      * @return void
130 128
      */
131
-    protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope)
132
-    {
129
+    protected function loadFunctionNamesInScope(PHP_CodeSniffer_File $phpcsFile, $currScope) {
133 130
         $this->_functionList = array();
134 131
         $tokens = $phpcsFile->getTokens();
135 132
 
Please login to merge, or discard this patch.
CodeSniffer/Standards/Generic/Sniffs/Classes/DuplicateClassNameSniff.php 3 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -26,102 +26,102 @@
 block discarded – undo
26 26
 class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_Sniff
27 27
 {
28 28
 
29
-    /**
30
-     * List of classes that have been found during checking.
31
-     *
32
-     * @var array
33
-     */
34
-    public $foundClasses = array();
35
-
36
-
37
-    /**
38
-     * Registers the tokens that this sniff wants to listen for.
39
-     *
40
-     * @return int[]
41
-     */
42
-    public function register()
43
-    {
44
-        return array(T_OPEN_TAG);
45
-
46
-    }//end register()
47
-
48
-
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
-     * @param int                  $stackPtr  The position of the current token
54
-     *                                        in the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
60
-        $tokens = $phpcsFile->getTokens();
61
-
62
-        $namespace  = '';
63
-        $findTokens = array(
64
-                       T_CLASS,
65
-                       T_INTERFACE,
66
-                       T_NAMESPACE,
67
-                       T_CLOSE_TAG,
68
-                      );
69
-
70
-        $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
71
-        while ($stackPtr !== false) {
72
-            if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) {
73
-                // We can stop here. The sniff will continue from the next open
74
-                // tag when PHPCS reaches that token, if there is one.
75
-                return;
76
-            }
77
-
78
-            // Keep track of what namespace we are in.
79
-            if ($tokens[$stackPtr]['code'] === T_NAMESPACE) {
80
-                $nsEnd = $phpcsFile->findNext(
81
-                    array(
82
-                     T_NS_SEPARATOR,
83
-                     T_STRING,
84
-                     T_WHITESPACE,
85
-                    ),
86
-                    ($stackPtr + 1),
87
-                    null,
88
-                    true
89
-                );
90
-
91
-                $namespace = trim($phpcsFile->getTokensAsString(($stackPtr + 1), ($nsEnd - $stackPtr - 1)));
92
-                $stackPtr  = $nsEnd;
93
-            } else {
94
-                $nameToken = $phpcsFile->findNext(T_STRING, $stackPtr);
95
-                $name      = $tokens[$nameToken]['content'];
96
-                if ($namespace !== '') {
97
-                    $name = $namespace.'\\'.$name;
98
-                }
99
-
100
-                $compareName = strtolower($name);
101
-                if (isset($this->foundClasses[$compareName]) === true) {
102
-                    $type  = strtolower($tokens[$stackPtr]['content']);
103
-                    $file  = $this->foundClasses[$compareName]['file'];
104
-                    $line  = $this->foundClasses[$compareName]['line'];
105
-                    $error = 'Duplicate %s name "%s" found; first defined in %s on line %s';
106
-                    $data  = array(
107
-                              $type,
108
-                              $name,
109
-                              $file,
110
-                              $line,
111
-                             );
112
-                    $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
113
-                } else {
114
-                    $this->foundClasses[$compareName] = array(
115
-                                                         'file' => $phpcsFile->getFilename(),
116
-                                                         'line' => $tokens[$stackPtr]['line'],
117
-                                                        );
118
-                }
119
-            }//end if
120
-
121
-            $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
122
-        }//end while
123
-
124
-    }//end process()
29
+	 /**
30
+	  * List of classes that have been found during checking.
31
+	  *
32
+	  * @var array
33
+	  */
34
+	 public $foundClasses = array();
35
+
36
+
37
+	 /**
38
+	  * Registers the tokens that this sniff wants to listen for.
39
+	  *
40
+	  * @return int[]
41
+	  */
42
+	 public function register()
43
+	 {
44
+		  return array(T_OPEN_TAG);
45
+
46
+	 }//end register()
47
+
48
+
49
+	 /**
50
+	  * Processes this test, when one of its tokens is encountered.
51
+	  *
52
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
+	  * @param int                  $stackPtr  The position of the current token
54
+	  *                                        in the stack passed in $tokens.
55
+	  *
56
+	  * @return void
57
+	  */
58
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
+	 {
60
+		  $tokens = $phpcsFile->getTokens();
61
+
62
+		  $namespace  = '';
63
+		  $findTokens = array(
64
+							  T_CLASS,
65
+							  T_INTERFACE,
66
+							  T_NAMESPACE,
67
+							  T_CLOSE_TAG,
68
+							 );
69
+
70
+		  $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
71
+		  while ($stackPtr !== false) {
72
+				if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) {
73
+					 // We can stop here. The sniff will continue from the next open
74
+					 // tag when PHPCS reaches that token, if there is one.
75
+					 return;
76
+				}
77
+
78
+				// Keep track of what namespace we are in.
79
+				if ($tokens[$stackPtr]['code'] === T_NAMESPACE) {
80
+					 $nsEnd = $phpcsFile->findNext(
81
+						  array(
82
+							T_NS_SEPARATOR,
83
+							T_STRING,
84
+							T_WHITESPACE,
85
+						  ),
86
+						  ($stackPtr + 1),
87
+						  null,
88
+						  true
89
+					 );
90
+
91
+					 $namespace = trim($phpcsFile->getTokensAsString(($stackPtr + 1), ($nsEnd - $stackPtr - 1)));
92
+					 $stackPtr  = $nsEnd;
93
+				} else {
94
+					 $nameToken = $phpcsFile->findNext(T_STRING, $stackPtr);
95
+					 $name      = $tokens[$nameToken]['content'];
96
+					 if ($namespace !== '') {
97
+						  $name = $namespace.'\\'.$name;
98
+					 }
99
+
100
+					 $compareName = strtolower($name);
101
+					 if (isset($this->foundClasses[$compareName]) === true) {
102
+						  $type  = strtolower($tokens[$stackPtr]['content']);
103
+						  $file  = $this->foundClasses[$compareName]['file'];
104
+						  $line  = $this->foundClasses[$compareName]['line'];
105
+						  $error = 'Duplicate %s name "%s" found; first defined in %s on line %s';
106
+						  $data  = array(
107
+										$type,
108
+										$name,
109
+										$file,
110
+										$line,
111
+									  );
112
+						  $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
113
+					 } else {
114
+						  $this->foundClasses[$compareName] = array(
115
+																			'file' => $phpcsFile->getFilename(),
116
+																			'line' => $tokens[$stackPtr]['line'],
117
+																		  );
118
+					 }
119
+				}//end if
120
+
121
+				$stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
122
+		  }//end while
123
+
124
+	 }//end process()
125 125
 
126 126
 
127 127
 }//end class
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function register()
43 43
     {
44
-        return array(T_OPEN_TAG);
44
+        return array( T_OPEN_TAG );
45 45
 
46 46
     }//end register()
47 47
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return void
57 57
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
59 59
     {
60 60
         $tokens = $phpcsFile->getTokens();
61 61
 
@@ -67,41 +67,41 @@  discard block
 block discarded – undo
67 67
                        T_CLOSE_TAG,
68 68
                       );
69 69
 
70
-        $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
71
-        while ($stackPtr !== false) {
72
-            if ($tokens[$stackPtr]['code'] === T_CLOSE_TAG) {
70
+        $stackPtr = $phpcsFile->findNext( $findTokens, ( $stackPtr + 1 ) );
71
+        while ( $stackPtr !== false ) {
72
+            if ( $tokens[ $stackPtr ][ 'code' ] === T_CLOSE_TAG ) {
73 73
                 // We can stop here. The sniff will continue from the next open
74 74
                 // tag when PHPCS reaches that token, if there is one.
75 75
                 return;
76 76
             }
77 77
 
78 78
             // Keep track of what namespace we are in.
79
-            if ($tokens[$stackPtr]['code'] === T_NAMESPACE) {
79
+            if ( $tokens[ $stackPtr ][ 'code' ] === T_NAMESPACE ) {
80 80
                 $nsEnd = $phpcsFile->findNext(
81 81
                     array(
82 82
                      T_NS_SEPARATOR,
83 83
                      T_STRING,
84 84
                      T_WHITESPACE,
85 85
                     ),
86
-                    ($stackPtr + 1),
86
+                    ( $stackPtr + 1 ),
87 87
                     null,
88 88
                     true
89 89
                 );
90 90
 
91
-                $namespace = trim($phpcsFile->getTokensAsString(($stackPtr + 1), ($nsEnd - $stackPtr - 1)));
91
+                $namespace = trim( $phpcsFile->getTokensAsString( ( $stackPtr + 1 ), ( $nsEnd - $stackPtr - 1 ) ) );
92 92
                 $stackPtr  = $nsEnd;
93 93
             } else {
94
-                $nameToken = $phpcsFile->findNext(T_STRING, $stackPtr);
95
-                $name      = $tokens[$nameToken]['content'];
96
-                if ($namespace !== '') {
97
-                    $name = $namespace.'\\'.$name;
94
+                $nameToken = $phpcsFile->findNext( T_STRING, $stackPtr );
95
+                $name      = $tokens[ $nameToken ][ 'content' ];
96
+                if ( $namespace !== '' ) {
97
+                    $name = $namespace . '\\' . $name;
98 98
                 }
99 99
 
100
-                $compareName = strtolower($name);
101
-                if (isset($this->foundClasses[$compareName]) === true) {
102
-                    $type  = strtolower($tokens[$stackPtr]['content']);
103
-                    $file  = $this->foundClasses[$compareName]['file'];
104
-                    $line  = $this->foundClasses[$compareName]['line'];
100
+                $compareName = strtolower( $name );
101
+                if ( isset( $this->foundClasses[ $compareName ] ) === true ) {
102
+                    $type  = strtolower( $tokens[ $stackPtr ][ 'content' ] );
103
+                    $file  = $this->foundClasses[ $compareName ][ 'file' ];
104
+                    $line  = $this->foundClasses[ $compareName ][ 'line' ];
105 105
                     $error = 'Duplicate %s name "%s" found; first defined in %s on line %s';
106 106
                     $data  = array(
107 107
                               $type,
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
                               $file,
110 110
                               $line,
111 111
                              );
112
-                    $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
112
+                    $phpcsFile->addWarning( $error, $stackPtr, 'Found', $data );
113 113
                 } else {
114
-                    $this->foundClasses[$compareName] = array(
114
+                    $this->foundClasses[ $compareName ] = array(
115 115
                                                          'file' => $phpcsFile->getFilename(),
116
-                                                         'line' => $tokens[$stackPtr]['line'],
116
+                                                         'line' => $tokens[ $stackPtr ][ 'line' ],
117 117
                                                         );
118 118
                 }
119 119
             }//end if
120 120
 
121
-            $stackPtr = $phpcsFile->findNext($findTokens, ($stackPtr + 1));
121
+            $stackPtr = $phpcsFile->findNext( $findTokens, ( $stackPtr + 1 ) );
122 122
         }//end while
123 123
 
124 124
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
  * @version   Release: @package_version@
24 24
  * @link      http://pear.php.net/package/PHP_CodeSniffer
25 25
  */
26
-class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_Sniff
27
-{
26
+class Generic_Sniffs_Classes_DuplicateClassNameSniff implements PHP_CodeSniffer_Sniff {
28 27
 
29 28
     /**
30 29
      * List of classes that have been found during checking.
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
      *
40 39
      * @return int[]
41 40
      */
42
-    public function register()
43
-    {
41
+    public function register() {
44 42
         return array(T_OPEN_TAG);
45 43
 
46 44
     }//end register()
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
      *
56 54
      * @return void
57 55
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
56
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
60 57
         $tokens = $phpcsFile->getTokens();
61 58
 
62 59
         $namespace  = '';
Please login to merge, or discard this patch.
CodeSniffer/Standards/Generic/Sniffs/Classes/OpeningBraceSameLineSniff.php 3 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -34,108 +34,108 @@
 block discarded – undo
34 34
 {
35 35
 
36 36
 
37
-    /**
38
-     * Returns an array of tokens this test wants to listen for.
39
-     *
40
-     * @return array
41
-     */
42
-    public function register()
43
-    {
44
-        return array(
45
-                T_CLASS,
46
-                T_INTERFACE,
47
-                T_TRAIT,
48
-               );
49
-
50
-    }//end register()
51
-
52
-
53
-    /**
54
-     * Processes this test, when one of its tokens is encountered.
55
-     *
56
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
57
-     * @param int                  $stackPtr  The position of the current token in the
58
-     *                                        stack passed in $tokens.
59
-     *
60
-     * @return void
61
-     */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
-    {
64
-        $tokens           = $phpcsFile->getTokens();
65
-        $scope_identifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));
66
-        $errorData        = array(strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scope_identifier]['content']);
67
-
68
-        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
69
-            $error = 'Possible parse error: %s missing opening or closing brace';
70
-            $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
71
-            return;
72
-        }
73
-
74
-        $openingBrace = $tokens[$stackPtr]['scope_opener'];
75
-
76
-        // Is the brace on the same line as the class/interface/trait declaration ?
77
-        $lastClassLineToken = $phpcsFile->findPrevious(T_STRING, ($openingBrace - 1), $stackPtr);
78
-        $lastClassLine      = $tokens[$lastClassLineToken]['line'];
79
-        $braceLine          = $tokens[$openingBrace]['line'];
80
-        $lineDifference     = ($braceLine - $lastClassLine);
81
-
82
-        if ($lineDifference > 0) {
83
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');
84
-            $error = 'Opening brace should be on the same line as the declaration for %s';
85
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine', $errorData);
86
-            if ($fix === true) {
87
-                $phpcsFile->fixer->beginChangeset();
88
-                $phpcsFile->fixer->addContent($lastClassLineToken, ' {');
89
-                $phpcsFile->fixer->replaceToken($openingBrace, '');
90
-                $phpcsFile->fixer->endChangeset();
91
-            }
92
-        } else {
93
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
94
-        }
95
-
96
-        // Is the opening brace the last thing on the line ?
97
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
98
-        if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) {
99
-            if ($next === $tokens[$stackPtr]['scope_closer']) {
100
-                // Ignore empty classes.
101
-                return;
102
-            }
103
-
104
-            $error = 'Opening brace must be the last content on the line';
105
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
106
-            if ($fix === true) {
107
-                $phpcsFile->fixer->addNewline($openingBrace);
108
-            }
109
-        }
110
-
111
-        // Only continue checking if the opening brace looks good.
112
-        if ($lineDifference > 0) {
113
-            return;
114
-        }
115
-
116
-        // Is there precisely one space before the opening brace ?
117
-        if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) {
118
-            $length = 0;
119
-        } else if ($tokens[($openingBrace - 1)]['content'] === "\t") {
120
-            $length = '\t';
121
-        } else {
122
-            $length = strlen($tokens[($openingBrace - 1)]['content']);
123
-        }
124
-
125
-        if ($length !== 1) {
126
-            $error = 'Expected 1 space before opening brace; found %s';
127
-            $data  = array($length);
128
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data);
129
-            if ($fix === true) {
130
-                if ($length === 0 || $length === '\t') {
131
-                    $phpcsFile->fixer->addContentBefore($openingBrace, ' ');
132
-                } else {
133
-                    $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' ');
134
-                }
135
-            }
136
-        }
137
-
138
-    }//end process()
37
+	 /**
38
+	  * Returns an array of tokens this test wants to listen for.
39
+	  *
40
+	  * @return array
41
+	  */
42
+	 public function register()
43
+	 {
44
+		  return array(
45
+					 T_CLASS,
46
+					 T_INTERFACE,
47
+					 T_TRAIT,
48
+					);
49
+
50
+	 }//end register()
51
+
52
+
53
+	 /**
54
+	  * Processes this test, when one of its tokens is encountered.
55
+	  *
56
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
57
+	  * @param int                  $stackPtr  The position of the current token in the
58
+	  *                                        stack passed in $tokens.
59
+	  *
60
+	  * @return void
61
+	  */
62
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
+	 {
64
+		  $tokens           = $phpcsFile->getTokens();
65
+		  $scope_identifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));
66
+		  $errorData        = array(strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scope_identifier]['content']);
67
+
68
+		  if (isset($tokens[$stackPtr]['scope_opener']) === false) {
69
+				$error = 'Possible parse error: %s missing opening or closing brace';
70
+				$phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
71
+				return;
72
+		  }
73
+
74
+		  $openingBrace = $tokens[$stackPtr]['scope_opener'];
75
+
76
+		  // Is the brace on the same line as the class/interface/trait declaration ?
77
+		  $lastClassLineToken = $phpcsFile->findPrevious(T_STRING, ($openingBrace - 1), $stackPtr);
78
+		  $lastClassLine      = $tokens[$lastClassLineToken]['line'];
79
+		  $braceLine          = $tokens[$openingBrace]['line'];
80
+		  $lineDifference     = ($braceLine - $lastClassLine);
81
+
82
+		  if ($lineDifference > 0) {
83
+				$phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');
84
+				$error = 'Opening brace should be on the same line as the declaration for %s';
85
+				$fix   = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine', $errorData);
86
+				if ($fix === true) {
87
+					 $phpcsFile->fixer->beginChangeset();
88
+					 $phpcsFile->fixer->addContent($lastClassLineToken, ' {');
89
+					 $phpcsFile->fixer->replaceToken($openingBrace, '');
90
+					 $phpcsFile->fixer->endChangeset();
91
+				}
92
+		  } else {
93
+				$phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
94
+		  }
95
+
96
+		  // Is the opening brace the last thing on the line ?
97
+		  $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
98
+		  if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) {
99
+				if ($next === $tokens[$stackPtr]['scope_closer']) {
100
+					 // Ignore empty classes.
101
+					 return;
102
+				}
103
+
104
+				$error = 'Opening brace must be the last content on the line';
105
+				$fix   = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
106
+				if ($fix === true) {
107
+					 $phpcsFile->fixer->addNewline($openingBrace);
108
+				}
109
+		  }
110
+
111
+		  // Only continue checking if the opening brace looks good.
112
+		  if ($lineDifference > 0) {
113
+				return;
114
+		  }
115
+
116
+		  // Is there precisely one space before the opening brace ?
117
+		  if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) {
118
+				$length = 0;
119
+		  } else if ($tokens[($openingBrace - 1)]['content'] === "\t") {
120
+				$length = '\t';
121
+		  } else {
122
+				$length = strlen($tokens[($openingBrace - 1)]['content']);
123
+		  }
124
+
125
+		  if ($length !== 1) {
126
+				$error = 'Expected 1 space before opening brace; found %s';
127
+				$data  = array($length);
128
+				$fix   = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data);
129
+				if ($fix === true) {
130
+					 if ($length === 0 || $length === '\t') {
131
+						  $phpcsFile->fixer->addContentBefore($openingBrace, ' ');
132
+					 } else {
133
+						  $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' ');
134
+					 }
135
+				}
136
+		  }
137
+
138
+	 }//end process()
139 139
 
140 140
 
141 141
 }//end class
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -59,78 +59,78 @@
 block discarded – undo
59 59
      *
60 60
      * @return void
61 61
      */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
63 63
     {
64 64
         $tokens           = $phpcsFile->getTokens();
65
-        $scope_identifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));
66
-        $errorData        = array(strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scope_identifier]['content']);
65
+        $scope_identifier = $phpcsFile->findNext( T_STRING, ( $stackPtr + 1 ) );
66
+        $errorData        = array( strtolower( $tokens[ $stackPtr ][ 'content' ] ) . ' ' . $tokens[ $scope_identifier ][ 'content' ] );
67 67
 
68
-        if (isset($tokens[$stackPtr]['scope_opener']) === false) {
68
+        if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) {
69 69
             $error = 'Possible parse error: %s missing opening or closing brace';
70
-            $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
70
+            $phpcsFile->addWarning( $error, $stackPtr, 'MissingBrace', $errorData );
71 71
             return;
72 72
         }
73 73
 
74
-        $openingBrace = $tokens[$stackPtr]['scope_opener'];
74
+        $openingBrace = $tokens[ $stackPtr ][ 'scope_opener' ];
75 75
 
76 76
         // Is the brace on the same line as the class/interface/trait declaration ?
77
-        $lastClassLineToken = $phpcsFile->findPrevious(T_STRING, ($openingBrace - 1), $stackPtr);
78
-        $lastClassLine      = $tokens[$lastClassLineToken]['line'];
79
-        $braceLine          = $tokens[$openingBrace]['line'];
80
-        $lineDifference     = ($braceLine - $lastClassLine);
77
+        $lastClassLineToken = $phpcsFile->findPrevious( T_STRING, ( $openingBrace - 1 ), $stackPtr );
78
+        $lastClassLine      = $tokens[ $lastClassLineToken ][ 'line' ];
79
+        $braceLine          = $tokens[ $openingBrace ][ 'line' ];
80
+        $lineDifference     = ( $braceLine - $lastClassLine );
81 81
 
82
-        if ($lineDifference > 0) {
83
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');
82
+        if ( $lineDifference > 0 ) {
83
+            $phpcsFile->recordMetric( $stackPtr, 'Class opening brace placement', 'new line' );
84 84
             $error = 'Opening brace should be on the same line as the declaration for %s';
85
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'BraceOnNewLine', $errorData);
86
-            if ($fix === true) {
85
+            $fix   = $phpcsFile->addFixableError( $error, $openingBrace, 'BraceOnNewLine', $errorData );
86
+            if ( $fix === true ) {
87 87
                 $phpcsFile->fixer->beginChangeset();
88
-                $phpcsFile->fixer->addContent($lastClassLineToken, ' {');
89
-                $phpcsFile->fixer->replaceToken($openingBrace, '');
88
+                $phpcsFile->fixer->addContent( $lastClassLineToken, ' {' );
89
+                $phpcsFile->fixer->replaceToken( $openingBrace, '' );
90 90
                 $phpcsFile->fixer->endChangeset();
91 91
             }
92 92
         } else {
93
-            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
93
+            $phpcsFile->recordMetric( $stackPtr, 'Class opening brace placement', 'same line' );
94 94
         }
95 95
 
96 96
         // Is the opening brace the last thing on the line ?
97
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($openingBrace + 1), null, true);
98
-        if ($tokens[$next]['line'] === $tokens[$openingBrace]['line']) {
99
-            if ($next === $tokens[$stackPtr]['scope_closer']) {
97
+        $next = $phpcsFile->findNext( T_WHITESPACE, ( $openingBrace + 1 ), null, true );
98
+        if ( $tokens[ $next ][ 'line' ] === $tokens[ $openingBrace ][ 'line' ] ) {
99
+            if ( $next === $tokens[ $stackPtr ][ 'scope_closer' ] ) {
100 100
                 // Ignore empty classes.
101 101
                 return;
102 102
             }
103 103
 
104 104
             $error = 'Opening brace must be the last content on the line';
105
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'ContentAfterBrace');
106
-            if ($fix === true) {
107
-                $phpcsFile->fixer->addNewline($openingBrace);
105
+            $fix   = $phpcsFile->addFixableError( $error, $openingBrace, 'ContentAfterBrace' );
106
+            if ( $fix === true ) {
107
+                $phpcsFile->fixer->addNewline( $openingBrace );
108 108
             }
109 109
         }
110 110
 
111 111
         // Only continue checking if the opening brace looks good.
112
-        if ($lineDifference > 0) {
112
+        if ( $lineDifference > 0 ) {
113 113
             return;
114 114
         }
115 115
 
116 116
         // Is there precisely one space before the opening brace ?
117
-        if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) {
117
+        if ( $tokens[ ( $openingBrace - 1 ) ][ 'code' ] !== T_WHITESPACE ) {
118 118
             $length = 0;
119
-        } else if ($tokens[($openingBrace - 1)]['content'] === "\t") {
119
+        } else if ( $tokens[ ( $openingBrace - 1 ) ][ 'content' ] === "\t" ) {
120 120
             $length = '\t';
121 121
         } else {
122
-            $length = strlen($tokens[($openingBrace - 1)]['content']);
122
+            $length = strlen( $tokens[ ( $openingBrace - 1 ) ][ 'content' ] );
123 123
         }
124 124
 
125
-        if ($length !== 1) {
125
+        if ( $length !== 1 ) {
126 126
             $error = 'Expected 1 space before opening brace; found %s';
127
-            $data  = array($length);
128
-            $fix   = $phpcsFile->addFixableError($error, $openingBrace, 'SpaceBeforeBrace', $data);
129
-            if ($fix === true) {
130
-                if ($length === 0 || $length === '\t') {
131
-                    $phpcsFile->fixer->addContentBefore($openingBrace, ' ');
127
+            $data  = array( $length );
128
+            $fix   = $phpcsFile->addFixableError( $error, $openingBrace, 'SpaceBeforeBrace', $data );
129
+            if ( $fix === true ) {
130
+                if ( $length === 0 || $length === '\t' ) {
131
+                    $phpcsFile->fixer->addContentBefore( $openingBrace, ' ' );
132 132
                 } else {
133
-                    $phpcsFile->fixer->replaceToken(($openingBrace - 1), ' ');
133
+                    $phpcsFile->fixer->replaceToken( ( $openingBrace - 1 ), ' ' );
134 134
                 }
135 135
             }
136 136
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
  * @version   Release: @package_version@
31 31
  * @link      http://pear.php.net/package/PHP_CodeSniffer
32 32
  */
33
-class Generic_Sniffs_Classes_OpeningBraceSameLineSniff implements PHP_CodeSniffer_Sniff
34
-{
33
+class Generic_Sniffs_Classes_OpeningBraceSameLineSniff implements PHP_CodeSniffer_Sniff {
35 34
 
36 35
 
37 36
     /**
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
      *
40 39
      * @return array
41 40
      */
42
-    public function register()
43
-    {
41
+    public function register() {
44 42
         return array(
45 43
                 T_CLASS,
46 44
                 T_INTERFACE,
@@ -59,8 +57,7 @@  discard block
 block discarded – undo
59 57
      *
60 58
      * @return void
61 59
      */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
-    {
60
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
64 61
         $tokens           = $phpcsFile->getTokens();
65 62
         $scope_identifier = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));
66 63
         $errorData        = array(strtolower($tokens[$stackPtr]['content']).' '.$tokens[$scope_identifier]['content']);
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php 3 patches
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -30,335 +30,335 @@
 block discarded – undo
30 30
 class Squiz_Sniffs_Formatting_OperatorBracketSniff implements PHP_CodeSniffer_Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * A list of tokenizers this sniff supports.
35
-     *
36
-     * @var array
37
-     */
38
-    public $supportedTokenizers = array(
39
-                                   'PHP',
40
-                                   'JS',
41
-                                  );
42
-
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 PHP_CodeSniffer_Tokens::$operators;
52
-
53
-    }//end register()
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 in the
61
-     *                                        stack passed in $tokens.
62
-     *
63
-     * @return void
64
-     */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
-    {
67
-        $tokens = $phpcsFile->getTokens();
68
-
69
-        if ($phpcsFile->tokenizerType === 'JS' && $tokens[$stackPtr]['code'] === T_PLUS) {
70
-            // JavaScript uses the plus operator for string concatenation as well
71
-            // so we cannot accurately determine if it is a string concat or addition.
72
-            // So just ignore it.
73
-            return;
74
-        }
75
-
76
-        // If the & is a reference, then we don't want to check for brackets.
77
-        if ($tokens[$stackPtr]['code'] === T_BITWISE_AND && $phpcsFile->isReference($stackPtr) === true) {
78
-            return;
79
-        }
80
-
81
-        // There is one instance where brackets aren't needed, which involves
82
-        // the minus sign being used to assign a negative number to a variable.
83
-        if ($tokens[$stackPtr]['code'] === T_MINUS) {
84
-            // Check to see if we are trying to return -n.
85
-            $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
86
-            if ($tokens[$prev]['code'] === T_RETURN) {
87
-                return;
88
-            }
89
-
90
-            $number = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
-            if ($tokens[$number]['code'] === T_LNUMBER || $tokens[$number]['code'] === T_DNUMBER) {
92
-                $previous = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
93
-                if ($previous !== false) {
94
-                    $isAssignment = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens);
95
-                    $isEquality   = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$equalityTokens);
96
-                    $isComparison = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens);
97
-                    if ($isAssignment === true || $isEquality === true || $isComparison === true) {
98
-                        // This is a negative assignment or comparison.
99
-                        // We need to check that the minus and the number are
100
-                        // adjacent.
101
-                        if (($number - $stackPtr) !== 1) {
102
-                            $error = 'No space allowed between minus sign and number';
103
-                            $phpcsFile->addError($error, $stackPtr, 'SpacingAfterMinus');
104
-                        }
105
-
106
-                        return;
107
-                    }
108
-                }
109
-            }
110
-        }//end if
111
-
112
-        $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true, null, true);
113
-        if ($previousToken !== false) {
114
-            // A list of tokens that indicate that the token is not
115
-            // part of an arithmetic operation.
116
-            $invalidTokens = array(
117
-                              T_COMMA,
118
-                              T_COLON,
119
-                              T_OPEN_PARENTHESIS,
120
-                              T_OPEN_SQUARE_BRACKET,
121
-                              T_OPEN_SHORT_ARRAY,
122
-                              T_CASE,
123
-                             );
124
-
125
-            if (in_array($tokens[$previousToken]['code'], $invalidTokens) === true) {
126
-                return;
127
-            }
128
-        }
129
-
130
-        // Tokens that are allowed inside a bracketed operation.
131
-        $allowed = array(
132
-                    T_VARIABLE,
133
-                    T_LNUMBER,
134
-                    T_DNUMBER,
135
-                    T_STRING,
136
-                    T_WHITESPACE,
137
-                    T_THIS,
138
-                    T_SELF,
139
-                    T_OBJECT_OPERATOR,
140
-                    T_DOUBLE_COLON,
141
-                    T_OPEN_SQUARE_BRACKET,
142
-                    T_CLOSE_SQUARE_BRACKET,
143
-                    T_MODULUS,
144
-                    T_NONE,
145
-                   );
146
-
147
-        $allowed += PHP_CodeSniffer_Tokens::$operators;
148
-
149
-        $lastBracket = false;
150
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
151
-            $parenthesis = array_reverse($tokens[$stackPtr]['nested_parenthesis'], true);
152
-            foreach ($parenthesis as $bracket => $endBracket) {
153
-                $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($bracket - 1), null, true);
154
-                $prevCode  = $tokens[$prevToken]['code'];
155
-
156
-                if ($prevCode === T_ISSET) {
157
-                    // This operation is inside an isset() call, but has
158
-                    // no bracket of it's own.
159
-                    break;
160
-                }
161
-
162
-                if ($prevCode === T_STRING || $prevCode === T_SWITCH) {
163
-                    // We allow simple operations to not be bracketed.
164
-                    // For example, ceil($one / $two).
165
-                    for ($prev = ($stackPtr - 1); $prev > $bracket; $prev--) {
166
-                        if (in_array($tokens[$prev]['code'], $allowed) === true) {
167
-                            continue;
168
-                        }
169
-
170
-                        if ($tokens[$prev]['code'] === T_CLOSE_PARENTHESIS) {
171
-                            $prev = $tokens[$prev]['parenthesis_opener'];
172
-                        } else {
173
-                            break;
174
-                        }
175
-                    }
176
-
177
-                    if ($prev !== $bracket) {
178
-                        break;
179
-                    }
180
-
181
-                    for ($next = ($stackPtr + 1); $next < $endBracket; $next++) {
182
-                        if (in_array($tokens[$next]['code'], $allowed) === true) {
183
-                            continue;
184
-                        }
185
-
186
-                        if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
187
-                            $next = $tokens[$next]['parenthesis_closer'];
188
-                        } else {
189
-                            break;
190
-                        }
191
-                    }
192
-
193
-                    if ($next !== $endBracket) {
194
-                        break;
195
-                    }
196
-                }//end if
197
-
198
-                if (in_array($prevCode, PHP_CodeSniffer_Tokens::$scopeOpeners) === true) {
199
-                    // This operation is inside a control structure like FOREACH
200
-                    // or IF, but has no bracket of it's own.
201
-                    // The only control structure allowed to do this is SWITCH.
202
-                    if ($prevCode !== T_SWITCH) {
203
-                        break;
204
-                    }
205
-                }
206
-
207
-                if ($prevCode === T_OPEN_PARENTHESIS) {
208
-                    // These are two open parenthesis in a row. If the current
209
-                    // one doesn't enclose the operator, go to the previous one.
210
-                    if ($endBracket < $stackPtr) {
211
-                        continue;
212
-                    }
213
-                }
214
-
215
-                $lastBracket = $bracket;
216
-                break;
217
-            }//end foreach
218
-        }//end if
219
-
220
-        if ($lastBracket === false) {
221
-            // It is not in a bracketed statement at all.
222
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
223
-            return;
224
-        } else if ($tokens[$lastBracket]['parenthesis_closer'] < $stackPtr) {
225
-            // There are a set of brackets in front of it that don't include it.
226
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
227
-            return;
228
-        } else {
229
-            // We are enclosed in a set of bracket, so the last thing to
230
-            // check is that we are not also enclosed in square brackets
231
-            // like this: ($array[$index + 1]), which is invalid.
232
-            $brackets = array(
233
-                         T_OPEN_SQUARE_BRACKET,
234
-                         T_CLOSE_SQUARE_BRACKET,
235
-                        );
236
-
237
-            $squareBracket = $phpcsFile->findPrevious($brackets, ($stackPtr - 1), $lastBracket);
238
-            if ($squareBracket !== false && $tokens[$squareBracket]['code'] === T_OPEN_SQUARE_BRACKET) {
239
-                $closeSquareBracket = $phpcsFile->findNext($brackets, ($stackPtr + 1));
240
-                if ($closeSquareBracket !== false && $tokens[$closeSquareBracket]['code'] === T_CLOSE_SQUARE_BRACKET) {
241
-                    $this->addMissingBracketsError($phpcsFile, $stackPtr);
242
-                }
243
-            }
244
-
245
-            return;
246
-        }//end if
247
-
248
-        $lastAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $stackPtr, null, false, null, true);
249
-        if ($lastAssignment !== false && $lastAssignment > $lastBracket) {
250
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
251
-        }
252
-
253
-    }//end process()
254
-
255
-
256
-    /**
257
-     * Add and fix the missing brackets error.
258
-     *
259
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
260
-     * @param int                  $stackPtr  The position of the current token in the
261
-     *                                        stack passed in $tokens.
262
-     *
263
-     * @return void
264
-     */
265
-    public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
266
-    {
267
-        $error = 'Arithmetic operation must be bracketed';
268
-        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets');
269
-
270
-        if ($fix === false || $phpcsFile->fixer->enabled === false) {
271
-            return;
272
-        }
273
-
274
-        $tokens = $phpcsFile->getTokens();
275
-
276
-        $allowed = array(
277
-                    T_VARIABLE        => true,
278
-                    T_LNUMBER         => true,
279
-                    T_DNUMBER         => true,
280
-                    T_STRING          => true,
281
-                    T_WHITESPACE      => true,
282
-                    T_THIS            => true,
283
-                    T_SELF            => true,
284
-                    T_OBJECT_OPERATOR => true,
285
-                    T_DOUBLE_COLON    => true,
286
-                    T_MODULUS         => true,
287
-                    T_ISSET           => true,
288
-                    T_ARRAY           => true,
289
-                    T_NONE            => true,
290
-                   );
291
-
292
-        // Find the first token in the expression.
293
-        for ($before = ($stackPtr - 1); $before > 0; $before--) {
294
-            // Special case for plus operators because we can't tell if they are used
295
-            // for addition or string contact. So assume string concat to be safe.
296
-            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$before]['code'] === T_PLUS) {
297
-                break;
298
-            }
299
-
300
-            if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$before]['code']]) === true
301
-                || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$before]['code']]) === true
302
-                || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$before]['code']]) === true
303
-                || isset($allowed[$tokens[$before]['code']]) === true
304
-            ) {
305
-                continue;
306
-            }
307
-
308
-            if ($tokens[$before]['code'] === T_CLOSE_PARENTHESIS) {
309
-                $before = $tokens[$before]['parenthesis_opener'];
310
-                continue;
311
-            }
312
-
313
-            if ($tokens[$before]['code'] === T_CLOSE_SQUARE_BRACKET) {
314
-                $before = $tokens[$before]['bracket_opener'];
315
-                continue;
316
-            }
317
-
318
-            break;
319
-        }//end for
320
-
321
-        $before = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($before + 1), null, true);
322
-
323
-        // Find the last token in the expression.
324
-        for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) {
325
-            // Special case for plus operators because we can't tell if they are used
326
-            // for addition or string contact. So assume string concat to be safe.
327
-            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$after]['code'] === T_PLUS) {
328
-                break;
329
-            }
330
-
331
-            if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$after]['code']]) === true
332
-                || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$after]['code']]) === true
333
-                || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$after]['code']]) === true
334
-                || isset($allowed[$tokens[$after]['code']]) === true
335
-            ) {
336
-                continue;
337
-            }
338
-
339
-            if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS) {
340
-                $after = $tokens[$after]['parenthesis_closer'];
341
-                continue;
342
-            }
343
-
344
-            if ($tokens[$after]['code'] === T_OPEN_SQUARE_BRACKET) {
345
-                $after = $tokens[$after]['bracket_closer'];
346
-                continue;
347
-            }
348
-
349
-            break;
350
-        }//end for
351
-
352
-        $after = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($after - 1), null, true);
353
-
354
-        // Can only fix this error if both tokens are available for fixing.
355
-        // Adding one bracket without the other will create parse errors.
356
-        $phpcsFile->fixer->beginChangeset();
357
-        $phpcsFile->fixer->replaceToken($before, '('.$tokens[$before]['content']);
358
-        $phpcsFile->fixer->replaceToken($after, $tokens[$after]['content'].')');
359
-        $phpcsFile->fixer->endChangeset();
360
-
361
-    }//end addMissingBracketsError()
33
+	 /**
34
+	  * A list of tokenizers this sniff supports.
35
+	  *
36
+	  * @var array
37
+	  */
38
+	 public $supportedTokenizers = array(
39
+											  'PHP',
40
+											  'JS',
41
+											 );
42
+
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 PHP_CodeSniffer_Tokens::$operators;
52
+
53
+	 }//end register()
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 in the
61
+	  *                                        stack passed in $tokens.
62
+	  *
63
+	  * @return void
64
+	  */
65
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
+	 {
67
+		  $tokens = $phpcsFile->getTokens();
68
+
69
+		  if ($phpcsFile->tokenizerType === 'JS' && $tokens[$stackPtr]['code'] === T_PLUS) {
70
+				// JavaScript uses the plus operator for string concatenation as well
71
+				// so we cannot accurately determine if it is a string concat or addition.
72
+				// So just ignore it.
73
+				return;
74
+		  }
75
+
76
+		  // If the & is a reference, then we don't want to check for brackets.
77
+		  if ($tokens[$stackPtr]['code'] === T_BITWISE_AND && $phpcsFile->isReference($stackPtr) === true) {
78
+				return;
79
+		  }
80
+
81
+		  // There is one instance where brackets aren't needed, which involves
82
+		  // the minus sign being used to assign a negative number to a variable.
83
+		  if ($tokens[$stackPtr]['code'] === T_MINUS) {
84
+				// Check to see if we are trying to return -n.
85
+				$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
86
+				if ($tokens[$prev]['code'] === T_RETURN) {
87
+					 return;
88
+				}
89
+
90
+				$number = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
+				if ($tokens[$number]['code'] === T_LNUMBER || $tokens[$number]['code'] === T_DNUMBER) {
92
+					 $previous = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
93
+					 if ($previous !== false) {
94
+						  $isAssignment = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens);
95
+						  $isEquality   = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$equalityTokens);
96
+						  $isComparison = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens);
97
+						  if ($isAssignment === true || $isEquality === true || $isComparison === true) {
98
+								// This is a negative assignment or comparison.
99
+								// We need to check that the minus and the number are
100
+								// adjacent.
101
+								if (($number - $stackPtr) !== 1) {
102
+									 $error = 'No space allowed between minus sign and number';
103
+									 $phpcsFile->addError($error, $stackPtr, 'SpacingAfterMinus');
104
+								}
105
+
106
+								return;
107
+						  }
108
+					 }
109
+				}
110
+		  }//end if
111
+
112
+		  $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true, null, true);
113
+		  if ($previousToken !== false) {
114
+				// A list of tokens that indicate that the token is not
115
+				// part of an arithmetic operation.
116
+				$invalidTokens = array(
117
+										T_COMMA,
118
+										T_COLON,
119
+										T_OPEN_PARENTHESIS,
120
+										T_OPEN_SQUARE_BRACKET,
121
+										T_OPEN_SHORT_ARRAY,
122
+										T_CASE,
123
+									  );
124
+
125
+				if (in_array($tokens[$previousToken]['code'], $invalidTokens) === true) {
126
+					 return;
127
+				}
128
+		  }
129
+
130
+		  // Tokens that are allowed inside a bracketed operation.
131
+		  $allowed = array(
132
+						  T_VARIABLE,
133
+						  T_LNUMBER,
134
+						  T_DNUMBER,
135
+						  T_STRING,
136
+						  T_WHITESPACE,
137
+						  T_THIS,
138
+						  T_SELF,
139
+						  T_OBJECT_OPERATOR,
140
+						  T_DOUBLE_COLON,
141
+						  T_OPEN_SQUARE_BRACKET,
142
+						  T_CLOSE_SQUARE_BRACKET,
143
+						  T_MODULUS,
144
+						  T_NONE,
145
+						 );
146
+
147
+		  $allowed += PHP_CodeSniffer_Tokens::$operators;
148
+
149
+		  $lastBracket = false;
150
+		  if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
151
+				$parenthesis = array_reverse($tokens[$stackPtr]['nested_parenthesis'], true);
152
+				foreach ($parenthesis as $bracket => $endBracket) {
153
+					 $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($bracket - 1), null, true);
154
+					 $prevCode  = $tokens[$prevToken]['code'];
155
+
156
+					 if ($prevCode === T_ISSET) {
157
+						  // This operation is inside an isset() call, but has
158
+						  // no bracket of it's own.
159
+						  break;
160
+					 }
161
+
162
+					 if ($prevCode === T_STRING || $prevCode === T_SWITCH) {
163
+						  // We allow simple operations to not be bracketed.
164
+						  // For example, ceil($one / $two).
165
+						  for ($prev = ($stackPtr - 1); $prev > $bracket; $prev--) {
166
+								if (in_array($tokens[$prev]['code'], $allowed) === true) {
167
+									 continue;
168
+								}
169
+
170
+								if ($tokens[$prev]['code'] === T_CLOSE_PARENTHESIS) {
171
+									 $prev = $tokens[$prev]['parenthesis_opener'];
172
+								} else {
173
+									 break;
174
+								}
175
+						  }
176
+
177
+						  if ($prev !== $bracket) {
178
+								break;
179
+						  }
180
+
181
+						  for ($next = ($stackPtr + 1); $next < $endBracket; $next++) {
182
+								if (in_array($tokens[$next]['code'], $allowed) === true) {
183
+									 continue;
184
+								}
185
+
186
+								if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
187
+									 $next = $tokens[$next]['parenthesis_closer'];
188
+								} else {
189
+									 break;
190
+								}
191
+						  }
192
+
193
+						  if ($next !== $endBracket) {
194
+								break;
195
+						  }
196
+					 }//end if
197
+
198
+					 if (in_array($prevCode, PHP_CodeSniffer_Tokens::$scopeOpeners) === true) {
199
+						  // This operation is inside a control structure like FOREACH
200
+						  // or IF, but has no bracket of it's own.
201
+						  // The only control structure allowed to do this is SWITCH.
202
+						  if ($prevCode !== T_SWITCH) {
203
+								break;
204
+						  }
205
+					 }
206
+
207
+					 if ($prevCode === T_OPEN_PARENTHESIS) {
208
+						  // These are two open parenthesis in a row. If the current
209
+						  // one doesn't enclose the operator, go to the previous one.
210
+						  if ($endBracket < $stackPtr) {
211
+								continue;
212
+						  }
213
+					 }
214
+
215
+					 $lastBracket = $bracket;
216
+					 break;
217
+				}//end foreach
218
+		  }//end if
219
+
220
+		  if ($lastBracket === false) {
221
+				// It is not in a bracketed statement at all.
222
+				$this->addMissingBracketsError($phpcsFile, $stackPtr);
223
+				return;
224
+		  } else if ($tokens[$lastBracket]['parenthesis_closer'] < $stackPtr) {
225
+				// There are a set of brackets in front of it that don't include it.
226
+				$this->addMissingBracketsError($phpcsFile, $stackPtr);
227
+				return;
228
+		  } else {
229
+				// We are enclosed in a set of bracket, so the last thing to
230
+				// check is that we are not also enclosed in square brackets
231
+				// like this: ($array[$index + 1]), which is invalid.
232
+				$brackets = array(
233
+								 T_OPEN_SQUARE_BRACKET,
234
+								 T_CLOSE_SQUARE_BRACKET,
235
+								);
236
+
237
+				$squareBracket = $phpcsFile->findPrevious($brackets, ($stackPtr - 1), $lastBracket);
238
+				if ($squareBracket !== false && $tokens[$squareBracket]['code'] === T_OPEN_SQUARE_BRACKET) {
239
+					 $closeSquareBracket = $phpcsFile->findNext($brackets, ($stackPtr + 1));
240
+					 if ($closeSquareBracket !== false && $tokens[$closeSquareBracket]['code'] === T_CLOSE_SQUARE_BRACKET) {
241
+						  $this->addMissingBracketsError($phpcsFile, $stackPtr);
242
+					 }
243
+				}
244
+
245
+				return;
246
+		  }//end if
247
+
248
+		  $lastAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $stackPtr, null, false, null, true);
249
+		  if ($lastAssignment !== false && $lastAssignment > $lastBracket) {
250
+				$this->addMissingBracketsError($phpcsFile, $stackPtr);
251
+		  }
252
+
253
+	 }//end process()
254
+
255
+
256
+	 /**
257
+	  * Add and fix the missing brackets error.
258
+	  *
259
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
260
+	  * @param int                  $stackPtr  The position of the current token in the
261
+	  *                                        stack passed in $tokens.
262
+	  *
263
+	  * @return void
264
+	  */
265
+	 public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
266
+	 {
267
+		  $error = 'Arithmetic operation must be bracketed';
268
+		  $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets');
269
+
270
+		  if ($fix === false || $phpcsFile->fixer->enabled === false) {
271
+				return;
272
+		  }
273
+
274
+		  $tokens = $phpcsFile->getTokens();
275
+
276
+		  $allowed = array(
277
+						  T_VARIABLE        => true,
278
+						  T_LNUMBER         => true,
279
+						  T_DNUMBER         => true,
280
+						  T_STRING          => true,
281
+						  T_WHITESPACE      => true,
282
+						  T_THIS            => true,
283
+						  T_SELF            => true,
284
+						  T_OBJECT_OPERATOR => true,
285
+						  T_DOUBLE_COLON    => true,
286
+						  T_MODULUS         => true,
287
+						  T_ISSET           => true,
288
+						  T_ARRAY           => true,
289
+						  T_NONE            => true,
290
+						 );
291
+
292
+		  // Find the first token in the expression.
293
+		  for ($before = ($stackPtr - 1); $before > 0; $before--) {
294
+				// Special case for plus operators because we can't tell if they are used
295
+				// for addition or string contact. So assume string concat to be safe.
296
+				if ($phpcsFile->tokenizerType === 'JS' && $tokens[$before]['code'] === T_PLUS) {
297
+					 break;
298
+				}
299
+
300
+				if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$before]['code']]) === true
301
+					 || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$before]['code']]) === true
302
+					 || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$before]['code']]) === true
303
+					 || isset($allowed[$tokens[$before]['code']]) === true
304
+				) {
305
+					 continue;
306
+				}
307
+
308
+				if ($tokens[$before]['code'] === T_CLOSE_PARENTHESIS) {
309
+					 $before = $tokens[$before]['parenthesis_opener'];
310
+					 continue;
311
+				}
312
+
313
+				if ($tokens[$before]['code'] === T_CLOSE_SQUARE_BRACKET) {
314
+					 $before = $tokens[$before]['bracket_opener'];
315
+					 continue;
316
+				}
317
+
318
+				break;
319
+		  }//end for
320
+
321
+		  $before = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($before + 1), null, true);
322
+
323
+		  // Find the last token in the expression.
324
+		  for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) {
325
+				// Special case for plus operators because we can't tell if they are used
326
+				// for addition or string contact. So assume string concat to be safe.
327
+				if ($phpcsFile->tokenizerType === 'JS' && $tokens[$after]['code'] === T_PLUS) {
328
+					 break;
329
+				}
330
+
331
+				if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$after]['code']]) === true
332
+					 || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$after]['code']]) === true
333
+					 || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$after]['code']]) === true
334
+					 || isset($allowed[$tokens[$after]['code']]) === true
335
+				) {
336
+					 continue;
337
+				}
338
+
339
+				if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS) {
340
+					 $after = $tokens[$after]['parenthesis_closer'];
341
+					 continue;
342
+				}
343
+
344
+				if ($tokens[$after]['code'] === T_OPEN_SQUARE_BRACKET) {
345
+					 $after = $tokens[$after]['bracket_closer'];
346
+					 continue;
347
+				}
348
+
349
+				break;
350
+		  }//end for
351
+
352
+		  $after = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($after - 1), null, true);
353
+
354
+		  // Can only fix this error if both tokens are available for fixing.
355
+		  // Adding one bracket without the other will create parse errors.
356
+		  $phpcsFile->fixer->beginChangeset();
357
+		  $phpcsFile->fixer->replaceToken($before, '('.$tokens[$before]['content']);
358
+		  $phpcsFile->fixer->replaceToken($after, $tokens[$after]['content'].')');
359
+		  $phpcsFile->fixer->endChangeset();
360
+
361
+	 }//end addMissingBracketsError()
362 362
 
363 363
 
364 364
 }//end class
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -62,11 +62,11 @@  discard block
 block discarded – undo
62 62
      *
63 63
      * @return void
64 64
      */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
65
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
66 66
     {
67 67
         $tokens = $phpcsFile->getTokens();
68 68
 
69
-        if ($phpcsFile->tokenizerType === 'JS' && $tokens[$stackPtr]['code'] === T_PLUS) {
69
+        if ( $phpcsFile->tokenizerType === 'JS' && $tokens[ $stackPtr ][ 'code' ] === T_PLUS ) {
70 70
             // JavaScript uses the plus operator for string concatenation as well
71 71
             // so we cannot accurately determine if it is a string concat or addition.
72 72
             // So just ignore it.
@@ -74,33 +74,33 @@  discard block
 block discarded – undo
74 74
         }
75 75
 
76 76
         // If the & is a reference, then we don't want to check for brackets.
77
-        if ($tokens[$stackPtr]['code'] === T_BITWISE_AND && $phpcsFile->isReference($stackPtr) === true) {
77
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_BITWISE_AND && $phpcsFile->isReference( $stackPtr ) === true ) {
78 78
             return;
79 79
         }
80 80
 
81 81
         // There is one instance where brackets aren't needed, which involves
82 82
         // the minus sign being used to assign a negative number to a variable.
83
-        if ($tokens[$stackPtr]['code'] === T_MINUS) {
83
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_MINUS ) {
84 84
             // Check to see if we are trying to return -n.
85
-            $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
86
-            if ($tokens[$prev]['code'] === T_RETURN) {
85
+            $prev = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
86
+            if ( $tokens[ $prev ][ 'code' ] === T_RETURN ) {
87 87
                 return;
88 88
             }
89 89
 
90
-            $number = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
-            if ($tokens[$number]['code'] === T_LNUMBER || $tokens[$number]['code'] === T_DNUMBER) {
92
-                $previous = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
93
-                if ($previous !== false) {
94
-                    $isAssignment = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens);
95
-                    $isEquality   = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$equalityTokens);
96
-                    $isComparison = in_array($tokens[$previous]['code'], PHP_CodeSniffer_Tokens::$comparisonTokens);
97
-                    if ($isAssignment === true || $isEquality === true || $isComparison === true) {
90
+            $number = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
91
+            if ( $tokens[ $number ][ 'code' ] === T_LNUMBER || $tokens[ $number ][ 'code' ] === T_DNUMBER ) {
92
+                $previous = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
93
+                if ( $previous !== false ) {
94
+                    $isAssignment = in_array( $tokens[ $previous ][ 'code' ], PHP_CodeSniffer_Tokens::$assignmentTokens );
95
+                    $isEquality   = in_array( $tokens[ $previous ][ 'code' ], PHP_CodeSniffer_Tokens::$equalityTokens );
96
+                    $isComparison = in_array( $tokens[ $previous ][ 'code' ], PHP_CodeSniffer_Tokens::$comparisonTokens );
97
+                    if ( $isAssignment === true || $isEquality === true || $isComparison === true ) {
98 98
                         // This is a negative assignment or comparison.
99 99
                         // We need to check that the minus and the number are
100 100
                         // adjacent.
101
-                        if (($number - $stackPtr) !== 1) {
101
+                        if ( ( $number - $stackPtr ) !== 1 ) {
102 102
                             $error = 'No space allowed between minus sign and number';
103
-                            $phpcsFile->addError($error, $stackPtr, 'SpacingAfterMinus');
103
+                            $phpcsFile->addError( $error, $stackPtr, 'SpacingAfterMinus' );
104 104
                         }
105 105
 
106 106
                         return;
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
             }
110 110
         }//end if
111 111
 
112
-        $previousToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true, null, true);
113
-        if ($previousToken !== false) {
112
+        $previousToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true, null, true );
113
+        if ( $previousToken !== false ) {
114 114
             // A list of tokens that indicate that the token is not
115 115
             // part of an arithmetic operation.
116 116
             $invalidTokens = array(
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
                               T_CASE,
123 123
                              );
124 124
 
125
-            if (in_array($tokens[$previousToken]['code'], $invalidTokens) === true) {
125
+            if ( in_array( $tokens[ $previousToken ][ 'code' ], $invalidTokens ) === true ) {
126 126
                 return;
127 127
             }
128 128
         }
@@ -147,67 +147,67 @@  discard block
 block discarded – undo
147 147
         $allowed += PHP_CodeSniffer_Tokens::$operators;
148 148
 
149 149
         $lastBracket = false;
150
-        if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
151
-            $parenthesis = array_reverse($tokens[$stackPtr]['nested_parenthesis'], true);
152
-            foreach ($parenthesis as $bracket => $endBracket) {
153
-                $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($bracket - 1), null, true);
154
-                $prevCode  = $tokens[$prevToken]['code'];
150
+        if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
151
+            $parenthesis = array_reverse( $tokens[ $stackPtr ][ 'nested_parenthesis' ], true );
152
+            foreach ( $parenthesis as $bracket => $endBracket ) {
153
+                $prevToken = $phpcsFile->findPrevious( T_WHITESPACE, ( $bracket - 1 ), null, true );
154
+                $prevCode  = $tokens[ $prevToken ][ 'code' ];
155 155
 
156
-                if ($prevCode === T_ISSET) {
156
+                if ( $prevCode === T_ISSET ) {
157 157
                     // This operation is inside an isset() call, but has
158 158
                     // no bracket of it's own.
159 159
                     break;
160 160
                 }
161 161
 
162
-                if ($prevCode === T_STRING || $prevCode === T_SWITCH) {
162
+                if ( $prevCode === T_STRING || $prevCode === T_SWITCH ) {
163 163
                     // We allow simple operations to not be bracketed.
164 164
                     // For example, ceil($one / $two).
165
-                    for ($prev = ($stackPtr - 1); $prev > $bracket; $prev--) {
166
-                        if (in_array($tokens[$prev]['code'], $allowed) === true) {
165
+                    for ( $prev = ( $stackPtr - 1 ); $prev > $bracket; $prev-- ) {
166
+                        if ( in_array( $tokens[ $prev ][ 'code' ], $allowed ) === true ) {
167 167
                             continue;
168 168
                         }
169 169
 
170
-                        if ($tokens[$prev]['code'] === T_CLOSE_PARENTHESIS) {
171
-                            $prev = $tokens[$prev]['parenthesis_opener'];
170
+                        if ( $tokens[ $prev ][ 'code' ] === T_CLOSE_PARENTHESIS ) {
171
+                            $prev = $tokens[ $prev ][ 'parenthesis_opener' ];
172 172
                         } else {
173 173
                             break;
174 174
                         }
175 175
                     }
176 176
 
177
-                    if ($prev !== $bracket) {
177
+                    if ( $prev !== $bracket ) {
178 178
                         break;
179 179
                     }
180 180
 
181
-                    for ($next = ($stackPtr + 1); $next < $endBracket; $next++) {
182
-                        if (in_array($tokens[$next]['code'], $allowed) === true) {
181
+                    for ( $next = ( $stackPtr + 1 ); $next < $endBracket; $next++ ) {
182
+                        if ( in_array( $tokens[ $next ][ 'code' ], $allowed ) === true ) {
183 183
                             continue;
184 184
                         }
185 185
 
186
-                        if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
187
-                            $next = $tokens[$next]['parenthesis_closer'];
186
+                        if ( $tokens[ $next ][ 'code' ] === T_OPEN_PARENTHESIS ) {
187
+                            $next = $tokens[ $next ][ 'parenthesis_closer' ];
188 188
                         } else {
189 189
                             break;
190 190
                         }
191 191
                     }
192 192
 
193
-                    if ($next !== $endBracket) {
193
+                    if ( $next !== $endBracket ) {
194 194
                         break;
195 195
                     }
196 196
                 }//end if
197 197
 
198
-                if (in_array($prevCode, PHP_CodeSniffer_Tokens::$scopeOpeners) === true) {
198
+                if ( in_array( $prevCode, PHP_CodeSniffer_Tokens::$scopeOpeners ) === true ) {
199 199
                     // This operation is inside a control structure like FOREACH
200 200
                     // or IF, but has no bracket of it's own.
201 201
                     // The only control structure allowed to do this is SWITCH.
202
-                    if ($prevCode !== T_SWITCH) {
202
+                    if ( $prevCode !== T_SWITCH ) {
203 203
                         break;
204 204
                     }
205 205
                 }
206 206
 
207
-                if ($prevCode === T_OPEN_PARENTHESIS) {
207
+                if ( $prevCode === T_OPEN_PARENTHESIS ) {
208 208
                     // These are two open parenthesis in a row. If the current
209 209
                     // one doesn't enclose the operator, go to the previous one.
210
-                    if ($endBracket < $stackPtr) {
210
+                    if ( $endBracket < $stackPtr ) {
211 211
                         continue;
212 212
                     }
213 213
                 }
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
             }//end foreach
218 218
         }//end if
219 219
 
220
-        if ($lastBracket === false) {
220
+        if ( $lastBracket === false ) {
221 221
             // It is not in a bracketed statement at all.
222
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
222
+            $this->addMissingBracketsError( $phpcsFile, $stackPtr );
223 223
             return;
224
-        } else if ($tokens[$lastBracket]['parenthesis_closer'] < $stackPtr) {
224
+        } else if ( $tokens[ $lastBracket ][ 'parenthesis_closer' ] < $stackPtr ) {
225 225
             // There are a set of brackets in front of it that don't include it.
226
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
226
+            $this->addMissingBracketsError( $phpcsFile, $stackPtr );
227 227
             return;
228 228
         } else {
229 229
             // We are enclosed in a set of bracket, so the last thing to
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
                          T_CLOSE_SQUARE_BRACKET,
235 235
                         );
236 236
 
237
-            $squareBracket = $phpcsFile->findPrevious($brackets, ($stackPtr - 1), $lastBracket);
238
-            if ($squareBracket !== false && $tokens[$squareBracket]['code'] === T_OPEN_SQUARE_BRACKET) {
239
-                $closeSquareBracket = $phpcsFile->findNext($brackets, ($stackPtr + 1));
240
-                if ($closeSquareBracket !== false && $tokens[$closeSquareBracket]['code'] === T_CLOSE_SQUARE_BRACKET) {
241
-                    $this->addMissingBracketsError($phpcsFile, $stackPtr);
237
+            $squareBracket = $phpcsFile->findPrevious( $brackets, ( $stackPtr - 1 ), $lastBracket );
238
+            if ( $squareBracket !== false && $tokens[ $squareBracket ][ 'code' ] === T_OPEN_SQUARE_BRACKET ) {
239
+                $closeSquareBracket = $phpcsFile->findNext( $brackets, ( $stackPtr + 1 ) );
240
+                if ( $closeSquareBracket !== false && $tokens[ $closeSquareBracket ][ 'code' ] === T_CLOSE_SQUARE_BRACKET ) {
241
+                    $this->addMissingBracketsError( $phpcsFile, $stackPtr );
242 242
                 }
243 243
             }
244 244
 
245 245
             return;
246 246
         }//end if
247 247
 
248
-        $lastAssignment = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$assignmentTokens, $stackPtr, null, false, null, true);
249
-        if ($lastAssignment !== false && $lastAssignment > $lastBracket) {
250
-            $this->addMissingBracketsError($phpcsFile, $stackPtr);
248
+        $lastAssignment = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$assignmentTokens, $stackPtr, null, false, null, true );
249
+        if ( $lastAssignment !== false && $lastAssignment > $lastBracket ) {
250
+            $this->addMissingBracketsError( $phpcsFile, $stackPtr );
251 251
         }
252 252
 
253 253
     }//end process()
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return void
264 264
      */
265
-    public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
265
+    public function addMissingBracketsError( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
266 266
     {
267 267
         $error = 'Arithmetic operation must be bracketed';
268
-        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets');
268
+        $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'MissingBrackets' );
269 269
 
270
-        if ($fix === false || $phpcsFile->fixer->enabled === false) {
270
+        if ( $fix === false || $phpcsFile->fixer->enabled === false ) {
271 271
             return;
272 272
         }
273 273
 
@@ -290,72 +290,72 @@  discard block
 block discarded – undo
290 290
                    );
291 291
 
292 292
         // Find the first token in the expression.
293
-        for ($before = ($stackPtr - 1); $before > 0; $before--) {
293
+        for ( $before = ( $stackPtr - 1 ); $before > 0; $before-- ) {
294 294
             // Special case for plus operators because we can't tell if they are used
295 295
             // for addition or string contact. So assume string concat to be safe.
296
-            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$before]['code'] === T_PLUS) {
296
+            if ( $phpcsFile->tokenizerType === 'JS' && $tokens[ $before ][ 'code' ] === T_PLUS ) {
297 297
                 break;
298 298
             }
299 299
 
300
-            if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$before]['code']]) === true
301
-                || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$before]['code']]) === true
302
-                || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$before]['code']]) === true
303
-                || isset($allowed[$tokens[$before]['code']]) === true
300
+            if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $tokens[ $before ][ 'code' ] ] ) === true
301
+                || isset( PHP_CodeSniffer_Tokens::$operators[ $tokens[ $before ][ 'code' ] ] ) === true
302
+                || isset( PHP_CodeSniffer_Tokens::$castTokens[ $tokens[ $before ][ 'code' ] ] ) === true
303
+                || isset( $allowed[ $tokens[ $before ][ 'code' ] ] ) === true
304 304
             ) {
305 305
                 continue;
306 306
             }
307 307
 
308
-            if ($tokens[$before]['code'] === T_CLOSE_PARENTHESIS) {
309
-                $before = $tokens[$before]['parenthesis_opener'];
308
+            if ( $tokens[ $before ][ 'code' ] === T_CLOSE_PARENTHESIS ) {
309
+                $before = $tokens[ $before ][ 'parenthesis_opener' ];
310 310
                 continue;
311 311
             }
312 312
 
313
-            if ($tokens[$before]['code'] === T_CLOSE_SQUARE_BRACKET) {
314
-                $before = $tokens[$before]['bracket_opener'];
313
+            if ( $tokens[ $before ][ 'code' ] === T_CLOSE_SQUARE_BRACKET ) {
314
+                $before = $tokens[ $before ][ 'bracket_opener' ];
315 315
                 continue;
316 316
             }
317 317
 
318 318
             break;
319 319
         }//end for
320 320
 
321
-        $before = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($before + 1), null, true);
321
+        $before = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $before + 1 ), null, true );
322 322
 
323 323
         // Find the last token in the expression.
324
-        for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) {
324
+        for ( $after = ( $stackPtr + 1 ); $after < $phpcsFile->numTokens; $after++ ) {
325 325
             // Special case for plus operators because we can't tell if they are used
326 326
             // for addition or string contact. So assume string concat to be safe.
327
-            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$after]['code'] === T_PLUS) {
327
+            if ( $phpcsFile->tokenizerType === 'JS' && $tokens[ $after ][ 'code' ] === T_PLUS ) {
328 328
                 break;
329 329
             }
330 330
 
331
-            if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$tokens[$after]['code']]) === true
332
-                || isset(PHP_CodeSniffer_Tokens::$operators[$tokens[$after]['code']]) === true
333
-                || isset(PHP_CodeSniffer_Tokens::$castTokens[$tokens[$after]['code']]) === true
334
-                || isset($allowed[$tokens[$after]['code']]) === true
331
+            if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $tokens[ $after ][ 'code' ] ] ) === true
332
+                || isset( PHP_CodeSniffer_Tokens::$operators[ $tokens[ $after ][ 'code' ] ] ) === true
333
+                || isset( PHP_CodeSniffer_Tokens::$castTokens[ $tokens[ $after ][ 'code' ] ] ) === true
334
+                || isset( $allowed[ $tokens[ $after ][ 'code' ] ] ) === true
335 335
             ) {
336 336
                 continue;
337 337
             }
338 338
 
339
-            if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS) {
340
-                $after = $tokens[$after]['parenthesis_closer'];
339
+            if ( $tokens[ $after ][ 'code' ] === T_OPEN_PARENTHESIS ) {
340
+                $after = $tokens[ $after ][ 'parenthesis_closer' ];
341 341
                 continue;
342 342
             }
343 343
 
344
-            if ($tokens[$after]['code'] === T_OPEN_SQUARE_BRACKET) {
345
-                $after = $tokens[$after]['bracket_closer'];
344
+            if ( $tokens[ $after ][ 'code' ] === T_OPEN_SQUARE_BRACKET ) {
345
+                $after = $tokens[ $after ][ 'bracket_closer' ];
346 346
                 continue;
347 347
             }
348 348
 
349 349
             break;
350 350
         }//end for
351 351
 
352
-        $after = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($after - 1), null, true);
352
+        $after = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $after - 1 ), null, true );
353 353
 
354 354
         // Can only fix this error if both tokens are available for fixing.
355 355
         // Adding one bracket without the other will create parse errors.
356 356
         $phpcsFile->fixer->beginChangeset();
357
-        $phpcsFile->fixer->replaceToken($before, '('.$tokens[$before]['content']);
358
-        $phpcsFile->fixer->replaceToken($after, $tokens[$after]['content'].')');
357
+        $phpcsFile->fixer->replaceToken( $before, '(' . $tokens[ $before ][ 'content' ] );
358
+        $phpcsFile->fixer->replaceToken( $after, $tokens[ $after ][ 'content' ] . ')' );
359 359
         $phpcsFile->fixer->endChangeset();
360 360
 
361 361
     }//end addMissingBracketsError()
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_Formatting_OperatorBracketSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_Formatting_OperatorBracketSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
     /**
34 33
      * A list of tokenizers this sniff supports.
@@ -46,8 +45,7 @@  discard block
 block discarded – undo
46 45
      *
47 46
      * @return array
48 47
      */
49
-    public function register()
50
-    {
48
+    public function register() {
51 49
         return PHP_CodeSniffer_Tokens::$operators;
52 50
 
53 51
     }//end register()
@@ -62,8 +60,7 @@  discard block
 block discarded – undo
62 60
      *
63 61
      * @return void
64 62
      */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
-    {
63
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
67 64
         $tokens = $phpcsFile->getTokens();
68 65
 
69 66
         if ($phpcsFile->tokenizerType === 'JS' && $tokens[$stackPtr]['code'] === T_PLUS) {
@@ -262,8 +259,7 @@  discard block
 block discarded – undo
262 259
      *
263 260
      * @return void
264 261
      */
265
-    public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
266
-    {
262
+    public function addMissingBracketsError(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
267 263
         $error = 'Arithmetic operation must be bracketed';
268 264
         $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets');
269 265
 
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectInstantiationSniff.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -31,51 +31,51 @@
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * Registers the token types that this sniff wishes to listen to.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(T_NEW);
34
+	 /**
35
+	  * Registers the token types that this sniff wishes to listen to.
36
+	  *
37
+	  * @return array
38
+	  */
39
+	 public function register()
40
+	 {
41
+		  return array(T_NEW);
42 42
 
43
-    }//end register()
43
+	 }//end register()
44 44
 
45 45
 
46
-    /**
47
-     * Process the tokens that this sniff is listening for.
48
-     *
49
-     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
50
-     * @param int                  $stackPtr  The position in the stack where
51
-     *                                        the token was found.
52
-     *
53
-     * @return void
54
-     */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
57
-        $tokens = $phpcsFile->getTokens();
46
+	 /**
47
+	  * Process the tokens that this sniff is listening for.
48
+	  *
49
+	  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
50
+	  * @param int                  $stackPtr  The position in the stack where
51
+	  *                                        the token was found.
52
+	  *
53
+	  * @return void
54
+	  */
55
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
+	 {
57
+		  $tokens = $phpcsFile->getTokens();
58 58
 
59
-        $allowedTokens   = PHP_CodeSniffer_Tokens::$emptyTokens;
60
-        $allowedTokens[] = T_BITWISE_AND;
59
+		  $allowedTokens   = PHP_CodeSniffer_Tokens::$emptyTokens;
60
+		  $allowedTokens[] = T_BITWISE_AND;
61 61
 
62
-        $prev = $phpcsFile->findPrevious($allowedTokens, ($stackPtr - 1), null, true);
62
+		  $prev = $phpcsFile->findPrevious($allowedTokens, ($stackPtr - 1), null, true);
63 63
 
64
-        $allowedTokens = array(
65
-                          T_EQUAL        => true,
66
-                          T_DOUBLE_ARROW => true,
67
-                          T_THROW        => true,
68
-                          T_RETURN       => true,
69
-                          T_INLINE_THEN  => true,
70
-                          T_INLINE_ELSE  => true,
71
-                         );
64
+		  $allowedTokens = array(
65
+								  T_EQUAL        => true,
66
+								  T_DOUBLE_ARROW => true,
67
+								  T_THROW        => true,
68
+								  T_RETURN       => true,
69
+								  T_INLINE_THEN  => true,
70
+								  T_INLINE_ELSE  => true,
71
+								 );
72 72
 
73
-        if (isset($allowedTokens[$tokens[$prev]['code']]) === false) {
74
-            $error = 'New objects must be assigned to a variable';
75
-            $phpcsFile->addError($error, $stackPtr, 'NotAssigned');
76
-        }
73
+		  if (isset($allowedTokens[$tokens[$prev]['code']]) === false) {
74
+				$error = 'New objects must be assigned to a variable';
75
+				$phpcsFile->addError($error, $stackPtr, 'NotAssigned');
76
+		  }
77 77
 
78
-    }//end process()
78
+	 }//end process()
79 79
 
80 80
 
81 81
 }//end class
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(T_NEW);
41
+        return array( T_NEW );
42 42
 
43 43
     }//end register()
44 44
 
@@ -52,14 +52,14 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
56 56
     {
57 57
         $tokens = $phpcsFile->getTokens();
58 58
 
59 59
         $allowedTokens   = PHP_CodeSniffer_Tokens::$emptyTokens;
60
-        $allowedTokens[] = T_BITWISE_AND;
60
+        $allowedTokens[ ] = T_BITWISE_AND;
61 61
 
62
-        $prev = $phpcsFile->findPrevious($allowedTokens, ($stackPtr - 1), null, true);
62
+        $prev = $phpcsFile->findPrevious( $allowedTokens, ( $stackPtr - 1 ), null, true );
63 63
 
64 64
         $allowedTokens = array(
65 65
                           T_EQUAL        => true,
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
                           T_INLINE_ELSE  => true,
71 71
                          );
72 72
 
73
-        if (isset($allowedTokens[$tokens[$prev]['code']]) === false) {
73
+        if ( isset( $allowedTokens[ $tokens[ $prev ][ 'code' ] ] ) === false ) {
74 74
             $error = 'New objects must be assigned to a variable';
75
-            $phpcsFile->addError($error, $stackPtr, 'NotAssigned');
75
+            $phpcsFile->addError( $error, $stackPtr, 'NotAssigned' );
76 76
         }
77 77
 
78 78
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_Objects_ObjectInstantiationSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_Objects_ObjectInstantiationSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
 
34 33
     /**
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(T_NEW);
42 40
 
43 41
     }//end register()
@@ -52,8 +50,7 @@  discard block
 block discarded – undo
52 50
      *
53 51
      * @return void
54 52
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
53
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
57 54
         $tokens = $phpcsFile->getTokens();
58 55
 
59 56
         $allowedTokens   = PHP_CodeSniffer_Tokens::$emptyTokens;
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/PHP/InnerFunctionsSniff.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -31,53 +31,53 @@
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(T_FUNCTION);
34
+	 /**
35
+	  * Returns an array of tokens this test wants to listen for.
36
+	  *
37
+	  * @return array
38
+	  */
39
+	 public function register()
40
+	 {
41
+		  return array(T_FUNCTION);
42 42
 
43
-    }//end register()
43
+	 }//end register()
44 44
 
45 45
 
46
-    /**
47
-     * Processes this test, when one of its tokens is encountered.
48
-     *
49
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
-     * @param int                  $stackPtr  The position of the current token in the
51
-     *                                        stack passed in $tokens.
52
-     *
53
-     * @return void
54
-     */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
57
-        $tokens = $phpcsFile->getTokens();
46
+	 /**
47
+	  * Processes this test, when one of its tokens is encountered.
48
+	  *
49
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
+	  * @param int                  $stackPtr  The position of the current token in the
51
+	  *                                        stack passed in $tokens.
52
+	  *
53
+	  * @return void
54
+	  */
55
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
+	 {
57
+		  $tokens = $phpcsFile->getTokens();
58 58
 
59
-        $function = $phpcsFile->getCondition($stackPtr, T_FUNCTION);
60
-        if ($function === false) {
61
-            // Not a nested function.
62
-            return;
63
-        }
59
+		  $function = $phpcsFile->getCondition($stackPtr, T_FUNCTION);
60
+		  if ($function === false) {
61
+				// Not a nested function.
62
+				return;
63
+		  }
64 64
 
65
-        $class = $phpcsFile->getCondition($stackPtr, T_ANON_CLASS);
66
-        if ($class !== false && $class > $function) {
67
-            // Ignore methods in anon classes.
68
-            return;
69
-        }
65
+		  $class = $phpcsFile->getCondition($stackPtr, T_ANON_CLASS);
66
+		  if ($class !== false && $class > $function) {
67
+				// Ignore methods in anon classes.
68
+				return;
69
+		  }
70 70
 
71
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
72
-        if ($tokens[$prev]['code'] === T_EQUAL) {
73
-            // Ignore closures.
74
-            return;
75
-        }
71
+		  $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
72
+		  if ($tokens[$prev]['code'] === T_EQUAL) {
73
+				// Ignore closures.
74
+				return;
75
+		  }
76 76
 
77
-        $error = 'The use of inner functions is forbidden';
78
-        $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
77
+		  $error = 'The use of inner functions is forbidden';
78
+		  $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
79 79
 
80
-    }//end process()
80
+	 }//end process()
81 81
 
82 82
 
83 83
 }//end class
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(T_FUNCTION);
41
+        return array( T_FUNCTION );
42 42
 
43 43
     }//end register()
44 44
 
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
56 56
     {
57 57
         $tokens = $phpcsFile->getTokens();
58 58
 
59
-        $function = $phpcsFile->getCondition($stackPtr, T_FUNCTION);
60
-        if ($function === false) {
59
+        $function = $phpcsFile->getCondition( $stackPtr, T_FUNCTION );
60
+        if ( $function === false ) {
61 61
             // Not a nested function.
62 62
             return;
63 63
         }
64 64
 
65
-        $class = $phpcsFile->getCondition($stackPtr, T_ANON_CLASS);
66
-        if ($class !== false && $class > $function) {
65
+        $class = $phpcsFile->getCondition( $stackPtr, T_ANON_CLASS );
66
+        if ( $class !== false && $class > $function ) {
67 67
             // Ignore methods in anon classes.
68 68
             return;
69 69
         }
70 70
 
71
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
72
-        if ($tokens[$prev]['code'] === T_EQUAL) {
71
+        $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
72
+        if ( $tokens[ $prev ][ 'code' ] === T_EQUAL ) {
73 73
             // Ignore closures.
74 74
             return;
75 75
         }
76 76
 
77 77
         $error = 'The use of inner functions is forbidden';
78
-        $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
78
+        $phpcsFile->addError( $error, $stackPtr, 'NotAllowed' );
79 79
 
80 80
     }//end process()
81 81
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_PHP_InnerFunctionsSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_PHP_InnerFunctionsSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
 
34 33
     /**
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(T_FUNCTION);
42 40
 
43 41
     }//end register()
@@ -52,8 +50,7 @@  discard block
 block discarded – undo
52 50
      *
53 51
      * @return void
54 52
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
53
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
57 54
         $tokens = $phpcsFile->getTokens();
58 55
 
59 56
         $function = $phpcsFile->getCondition($stackPtr, T_FUNCTION);
Please login to merge, or discard this patch.
php_codesniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/HeredocSniff.php 3 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(
42
-                T_START_HEREDOC,
43
-                T_START_NOWDOC,
44
-               );
34
+	 /**
35
+	  * Returns an array of tokens this test wants to listen for.
36
+	  *
37
+	  * @return array
38
+	  */
39
+	 public function register()
40
+	 {
41
+		  return array(
42
+					 T_START_HEREDOC,
43
+					 T_START_NOWDOC,
44
+					);
45 45
 
46
-    }//end register()
46
+	 }//end register()
47 47
 
48 48
 
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
-     * @param int                  $stackPtr  The position of the current token in the
54
-     *                                        stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
60
-        $error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead';
61
-        $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
49
+	 /**
50
+	  * Processes this test, when one of its tokens is encountered.
51
+	  *
52
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
+	  * @param int                  $stackPtr  The position of the current token in the
54
+	  *                                        stack passed in $tokens.
55
+	  *
56
+	  * @return void
57
+	  */
58
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
+	 {
60
+		  $error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead';
61
+		  $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
62 62
 
63
-    }//end process()
63
+	 }//end process()
64 64
 
65 65
 
66 66
 }//end class
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -55,10 +55,10 @@
 block discarded – undo
55 55
      *
56 56
      * @return void
57 57
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
59 59
     {
60 60
         $error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead';
61
-        $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
61
+        $phpcsFile->addError( $error, $stackPtr, 'NotAllowed' );
62 62
 
63 63
     }//end process()
64 64
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_PHP_HeredocSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_PHP_HeredocSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
 
34 33
     /**
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(
42 40
                 T_START_HEREDOC,
43 41
                 T_START_NOWDOC,
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
      *
56 54
      * @return void
57 55
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
56
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
60 57
         $error = 'Use of heredoc and nowdoc syntax ("<<<") is not allowed; use standard strings or inline HTML instead';
61 58
         $phpcsFile->addError($error, $stackPtr, 'NotAllowed');
62 59
 
Please login to merge, or discard this patch.