Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
src/Standards/Generic/Sniffs/NamingConventions/ConstructorNameSniff.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      *
32 32
      * @var string[]
33 33
      */
34
-    private $functionList = [];
34
+    private $functionList = [ ];
35 35
 
36 36
 
37 37
     /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function __construct()
41 41
     {
42
-        parent::__construct([T_CLASS, T_ANON_CLASS, T_INTERFACE], [T_FUNCTION], true);
42
+        parent::__construct( [ T_CLASS, T_ANON_CLASS, T_INTERFACE ], [ T_FUNCTION ], true );
43 43
 
44 44
     }//end __construct()
45 45
 
@@ -54,57 +54,57 @@  discard block
 block discarded – undo
54 54
      *
55 55
      * @return void
56 56
      */
57
-    protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
57
+    protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope )
58 58
     {
59 59
         $tokens = $phpcsFile->getTokens();
60 60
 
61 61
         // Determine if this is a function which needs to be examined.
62
-        $conditions = $tokens[$stackPtr]['conditions'];
63
-        end($conditions);
64
-        $deepestScope = key($conditions);
65
-        if ($deepestScope !== $currScope) {
62
+        $conditions = $tokens[ $stackPtr ][ 'conditions' ];
63
+        end( $conditions );
64
+        $deepestScope = key( $conditions );
65
+        if ( $deepestScope !== $currScope ) {
66 66
             return;
67 67
         }
68 68
 
69
-        $className = strtolower($phpcsFile->getDeclarationName($currScope));
70
-        if ($className !== $this->currentClass) {
71
-            $this->loadFunctionNamesInScope($phpcsFile, $currScope);
69
+        $className = strtolower( $phpcsFile->getDeclarationName( $currScope ) );
70
+        if ( $className !== $this->currentClass ) {
71
+            $this->loadFunctionNamesInScope( $phpcsFile, $currScope );
72 72
             $this->currentClass = $className;
73 73
         }
74 74
 
75
-        $methodName = strtolower($phpcsFile->getDeclarationName($stackPtr));
75
+        $methodName = strtolower( $phpcsFile->getDeclarationName( $stackPtr ) );
76 76
 
77
-        if ($methodName === $className) {
78
-            if (in_array('__construct', $this->functionList, true) === false) {
77
+        if ( $methodName === $className ) {
78
+            if ( in_array( '__construct', $this->functionList, true ) === false ) {
79 79
                 $error = 'PHP4 style constructors are not allowed; use "__construct()" instead';
80
-                $phpcsFile->addError($error, $stackPtr, 'OldStyle');
80
+                $phpcsFile->addError( $error, $stackPtr, 'OldStyle' );
81 81
             }
82
-        } else if ($methodName !== '__construct') {
82
+        } else if ( $methodName !== '__construct' ) {
83 83
             // Not a constructor.
84 84
             return;
85 85
         }
86 86
 
87 87
         // Stop if the constructor doesn't have a body, like when it is abstract.
88
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
88
+        if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
89 89
             return;
90 90
         }
91 91
 
92
-        $parentClassName = strtolower($phpcsFile->findExtendedClassName($currScope));
93
-        if ($parentClassName === false) {
92
+        $parentClassName = strtolower( $phpcsFile->findExtendedClassName( $currScope ) );
93
+        if ( $parentClassName === false ) {
94 94
             return;
95 95
         }
96 96
 
97
-        $endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
97
+        $endFunctionIndex = $tokens[ $stackPtr ][ 'scope_closer' ];
98 98
         $startIndex       = $stackPtr;
99
-        while (($doubleColonIndex = $phpcsFile->findNext(T_DOUBLE_COLON, $startIndex, $endFunctionIndex)) !== false) {
100
-            if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
101
-                && strtolower($tokens[($doubleColonIndex + 1)]['content']) === $parentClassName
99
+        while ( ( $doubleColonIndex = $phpcsFile->findNext( T_DOUBLE_COLON, $startIndex, $endFunctionIndex ) ) !== false ) {
100
+            if ( $tokens[ ( $doubleColonIndex + 1 ) ][ 'code' ] === T_STRING
101
+                && strtolower( $tokens[ ( $doubleColonIndex + 1 ) ][ 'content' ] ) === $parentClassName
102 102
             ) {
103 103
                 $error = 'PHP4 style calls to parent constructors are not allowed; use "parent::__construct()" instead';
104
-                $phpcsFile->addError($error, ($doubleColonIndex + 1), 'OldStyleCall');
104
+                $phpcsFile->addError( $error, ( $doubleColonIndex + 1 ), 'OldStyleCall' );
105 105
             }
106 106
 
107
-            $startIndex = ($doubleColonIndex + 1);
107
+            $startIndex = ( $doubleColonIndex + 1 );
108 108
         }
109 109
 
110 110
     }//end processTokenWithinScope()
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      *
121 121
      * @return void
122 122
      */
123
-    protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
123
+    protected function processTokenOutsideScope( File $phpcsFile, $stackPtr )
124 124
     {
125 125
 
126 126
     }//end processTokenOutsideScope()
@@ -134,21 +134,21 @@  discard block
 block discarded – undo
134 134
      *
135 135
      * @return void
136 136
      */
137
-    protected function loadFunctionNamesInScope(File $phpcsFile, $currScope)
137
+    protected function loadFunctionNamesInScope( File $phpcsFile, $currScope )
138 138
     {
139
-        $this->functionList = [];
139
+        $this->functionList = [ ];
140 140
         $tokens = $phpcsFile->getTokens();
141 141
 
142
-        for ($i = ($tokens[$currScope]['scope_opener'] + 1); $i < $tokens[$currScope]['scope_closer']; $i++) {
143
-            if ($tokens[$i]['code'] !== T_FUNCTION) {
142
+        for ( $i = ( $tokens[ $currScope ][ 'scope_opener' ] + 1 ); $i < $tokens[ $currScope ][ 'scope_closer' ]; $i++ ) {
143
+            if ( $tokens[ $i ][ 'code' ] !== T_FUNCTION ) {
144 144
                 continue;
145 145
             }
146 146
 
147
-            $this->functionList[] = trim(strtolower($phpcsFile->getDeclarationName($i)));
147
+            $this->functionList[ ] = trim( strtolower( $phpcsFile->getDeclarationName( $i ) ) );
148 148
 
149
-            if (isset($tokens[$i]['scope_closer']) !== false) {
149
+            if ( isset( $tokens[ $i ][ 'scope_closer' ] ) !== false ) {
150 150
                 // Skip past nested functions and such.
151
-                $i = $tokens[$i]['scope_closer'];
151
+                $i = $tokens[ $i ][ 'scope_closer' ];
152 152
             }
153 153
         }
154 154
 
Please login to merge, or discard this patch.
Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -41,97 +41,97 @@
 block discarded – undo
41 41
      *
42 42
      * @return void
43 43
      */
44
-    public function process(File $phpcsFile, $stackPtr)
44
+    public function process( File $phpcsFile, $stackPtr )
45 45
     {
46 46
         $tokens = $phpcsFile->getTokens();
47 47
 
48
-        if ($tokens[$stackPtr]['code'] === T_CONST) {
48
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_CONST ) {
49 49
             // This is a class constant.
50
-            $constant = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
51
-            if ($constant === false) {
50
+            $constant = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
51
+            if ( $constant === false ) {
52 52
                 return;
53 53
             }
54 54
 
55
-            $constName = $tokens[$constant]['content'];
55
+            $constName = $tokens[ $constant ][ 'content' ];
56 56
 
57
-            if (strtoupper($constName) !== $constName) {
58
-                if (strtolower($constName) === $constName) {
59
-                    $phpcsFile->recordMetric($constant, 'Constant name case', 'lower');
57
+            if ( strtoupper( $constName ) !== $constName ) {
58
+                if ( strtolower( $constName ) === $constName ) {
59
+                    $phpcsFile->recordMetric( $constant, 'Constant name case', 'lower' );
60 60
                 } else {
61
-                    $phpcsFile->recordMetric($constant, 'Constant name case', 'mixed');
61
+                    $phpcsFile->recordMetric( $constant, 'Constant name case', 'mixed' );
62 62
                 }
63 63
 
64 64
                 $error = 'Class constants must be uppercase; expected %s but found %s';
65 65
                 $data  = [
66
-                    strtoupper($constName),
66
+                    strtoupper( $constName ),
67 67
                     $constName,
68 68
                 ];
69
-                $phpcsFile->addError($error, $constant, 'ClassConstantNotUpperCase', $data);
69
+                $phpcsFile->addError( $error, $constant, 'ClassConstantNotUpperCase', $data );
70 70
             } else {
71
-                $phpcsFile->recordMetric($constant, 'Constant name case', 'upper');
71
+                $phpcsFile->recordMetric( $constant, 'Constant name case', 'upper' );
72 72
             }
73 73
 
74 74
             return;
75 75
         }//end if
76 76
 
77 77
         // Only interested in define statements now.
78
-        if (strtolower($tokens[$stackPtr]['content']) !== 'define') {
78
+        if ( strtolower( $tokens[ $stackPtr ][ 'content' ] ) !== 'define' ) {
79 79
             return;
80 80
         }
81 81
 
82 82
         // Make sure this is not a method call.
83
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
84
-        if ($tokens[$prev]['code'] === T_OBJECT_OPERATOR
85
-            || $tokens[$prev]['code'] === T_DOUBLE_COLON
83
+        $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
84
+        if ( $tokens[ $prev ][ 'code' ] === T_OBJECT_OPERATOR
85
+            || $tokens[ $prev ][ 'code' ] === T_DOUBLE_COLON
86 86
         ) {
87 87
             return;
88 88
         }
89 89
 
90 90
         // If the next non-whitespace token after this token
91 91
         // is not an opening parenthesis then it is not a function call.
92
-        $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
93
-        if ($openBracket === false) {
92
+        $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
93
+        if ( $openBracket === false ) {
94 94
             return;
95 95
         }
96 96
 
97 97
         // The next non-whitespace token must be the constant name.
98
-        $constPtr = $phpcsFile->findNext(T_WHITESPACE, ($openBracket + 1), null, true);
99
-        if ($tokens[$constPtr]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
98
+        $constPtr = $phpcsFile->findNext( T_WHITESPACE, ( $openBracket + 1 ), null, true );
99
+        if ( $tokens[ $constPtr ][ 'code' ] !== T_CONSTANT_ENCAPSED_STRING ) {
100 100
             return;
101 101
         }
102 102
 
103
-        $constName = $tokens[$constPtr]['content'];
103
+        $constName = $tokens[ $constPtr ][ 'content' ];
104 104
 
105 105
         // Check for constants like self::CONSTANT.
106 106
         $prefix   = '';
107
-        $splitPos = strpos($constName, '::');
108
-        if ($splitPos !== false) {
109
-            $prefix    = substr($constName, 0, ($splitPos + 2));
110
-            $constName = substr($constName, ($splitPos + 2));
107
+        $splitPos = strpos( $constName, '::' );
108
+        if ( $splitPos !== false ) {
109
+            $prefix    = substr( $constName, 0, ( $splitPos + 2 ) );
110
+            $constName = substr( $constName, ( $splitPos + 2 ) );
111 111
         }
112 112
 
113 113
         // Strip namespace from constant like /foo/bar/CONSTANT.
114
-        $splitPos = strrpos($constName, '\\');
115
-        if ($splitPos !== false) {
116
-            $prefix    = substr($constName, 0, ($splitPos + 1));
117
-            $constName = substr($constName, ($splitPos + 1));
114
+        $splitPos = strrpos( $constName, '\\' );
115
+        if ( $splitPos !== false ) {
116
+            $prefix    = substr( $constName, 0, ( $splitPos + 1 ) );
117
+            $constName = substr( $constName, ( $splitPos + 1 ) );
118 118
         }
119 119
 
120
-        if (strtoupper($constName) !== $constName) {
121
-            if (strtolower($constName) === $constName) {
122
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'lower');
120
+        if ( strtoupper( $constName ) !== $constName ) {
121
+            if ( strtolower( $constName ) === $constName ) {
122
+                $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'lower' );
123 123
             } else {
124
-                $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'mixed');
124
+                $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'mixed' );
125 125
             }
126 126
 
127 127
             $error = 'Constants must be uppercase; expected %s but found %s';
128 128
             $data  = [
129
-                $prefix.strtoupper($constName),
130
-                $prefix.$constName,
129
+                $prefix . strtoupper( $constName ),
130
+                $prefix . $constName,
131 131
             ];
132
-            $phpcsFile->addError($error, $stackPtr, 'ConstantNotUpperCase', $data);
132
+            $phpcsFile->addError( $error, $stackPtr, 'ConstantNotUpperCase', $data );
133 133
         } else {
134
-            $phpcsFile->recordMetric($stackPtr, 'Constant name case', 'upper');
134
+            $phpcsFile->recordMetric( $stackPtr, 'Constant name case', 'upper' );
135 135
         }
136 136
 
137 137
     }//end process()
Please login to merge, or discard this patch.
Standards/Generic/Sniffs/NamingConventions/CamelCapsFunctionNameSniff.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      *
68 68
      * @var array
69 69
      */
70
-    protected $magicFunctions = ['autoload' => true];
70
+    protected $magicFunctions = [ 'autoload' => true ];
71 71
 
72 72
     /**
73 73
      * If TRUE, the string must not have two capital letters next to each other.
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function __construct()
84 84
     {
85
-        parent::__construct(Tokens::$ooScopeTokens, [T_FUNCTION], true);
85
+        parent::__construct( Tokens::$ooScopeTokens, [ T_FUNCTION ], true );
86 86
 
87 87
     }//end __construct()
88 88
 
@@ -97,78 +97,78 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @return void
99 99
      */
100
-    protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
100
+    protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope )
101 101
     {
102 102
         $tokens = $phpcsFile->getTokens();
103 103
 
104 104
         // Determine if this is a function which needs to be examined.
105
-        $conditions = $tokens[$stackPtr]['conditions'];
106
-        end($conditions);
107
-        $deepestScope = key($conditions);
108
-        if ($deepestScope !== $currScope) {
105
+        $conditions = $tokens[ $stackPtr ][ 'conditions' ];
106
+        end( $conditions );
107
+        $deepestScope = key( $conditions );
108
+        if ( $deepestScope !== $currScope ) {
109 109
             return;
110 110
         }
111 111
 
112
-        $methodName = $phpcsFile->getDeclarationName($stackPtr);
113
-        if ($methodName === null) {
112
+        $methodName = $phpcsFile->getDeclarationName( $stackPtr );
113
+        if ( $methodName === null ) {
114 114
             // Ignore closures.
115 115
             return;
116 116
         }
117 117
 
118
-        $className = $phpcsFile->getDeclarationName($currScope);
119
-        if (isset($className) === false) {
118
+        $className = $phpcsFile->getDeclarationName( $currScope );
119
+        if ( isset( $className ) === false ) {
120 120
             $className = '[Anonymous Class]';
121 121
         }
122 122
 
123
-        $errorData = [$className.'::'.$methodName];
123
+        $errorData = [ $className . '::' . $methodName ];
124 124
 
125
-        $methodNameLc = strtolower($methodName);
126
-        $classNameLc  = strtolower($className);
125
+        $methodNameLc = strtolower( $methodName );
126
+        $classNameLc  = strtolower( $className );
127 127
 
128 128
         // Is this a magic method. i.e., is prefixed with "__" ?
129
-        if (preg_match('|^__[^_]|', $methodName) !== 0) {
130
-            $magicPart = substr($methodNameLc, 2);
131
-            if (isset($this->magicMethods[$magicPart]) === true
132
-                || isset($this->methodsDoubleUnderscore[$magicPart]) === true
129
+        if ( preg_match( '|^__[^_]|', $methodName ) !== 0 ) {
130
+            $magicPart = substr( $methodNameLc, 2 );
131
+            if ( isset( $this->magicMethods[ $magicPart ] ) === true
132
+                || isset( $this->methodsDoubleUnderscore[ $magicPart ] ) === true
133 133
             ) {
134 134
                 return;
135 135
             }
136 136
 
137 137
             $error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
138
-            $phpcsFile->addError($error, $stackPtr, 'MethodDoubleUnderscore', $errorData);
138
+            $phpcsFile->addError( $error, $stackPtr, 'MethodDoubleUnderscore', $errorData );
139 139
         }
140 140
 
141 141
         // PHP4 constructors are allowed to break our rules.
142
-        if ($methodNameLc === $classNameLc) {
142
+        if ( $methodNameLc === $classNameLc ) {
143 143
             return;
144 144
         }
145 145
 
146 146
         // PHP4 destructors are allowed to break our rules.
147
-        if ($methodNameLc === '_'.$classNameLc) {
147
+        if ( $methodNameLc === '_' . $classNameLc ) {
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 (Common::isCamelCaps($methodName, false, true, $this->strict) === false) {
156
-            if ($methodProps['scope_specified'] === true) {
154
+        $methodProps = $phpcsFile->getMethodProperties( $stackPtr );
155
+        if ( Common::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  = [
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(File $phpcsFile, $stackPtr)
186
+    protected function processTokenOutsideScope( 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 = [$functionName];
194
+        $errorData = [ $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]) === true) {
197
+        if ( preg_match( '|^__[^_]|', $functionName ) !== 0 ) {
198
+            $magicPart = strtolower( substr( $functionName, 2 ) );
199
+            if ( isset( $this->magicFunctions[ $magicPart ] ) === true ) {
200 200
                 return;
201 201
             }
202 202
 
203 203
             $error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore';
204
-            $phpcsFile->addError($error, $stackPtr, 'FunctionDoubleUnderscore', $errorData);
204
+            $phpcsFile->addError( $error, $stackPtr, 'FunctionDoubleUnderscore', $errorData );
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 (Common::isCamelCaps($functionName, false, true, $this->strict) === false) {
210
+        if ( Common::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.
php_codesniffer/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
      *
24 24
      * @var integer
25 25
      */
26
-    public $errorCodes = [];
26
+    public $errorCodes = [ ];
27 27
 
28 28
     /**
29 29
      * A list of error codes to ignore.
30 30
      *
31 31
      * @var integer
32 32
      */
33
-    public $ignoreCodes = [];
33
+    public $ignoreCodes = [ ];
34 34
 
35 35
     /**
36 36
      * A list of tokenizers this sniff supports.
37 37
      *
38 38
      * @var array
39 39
      */
40
-    public $supportedTokenizers = ['JS'];
40
+    public $supportedTokenizers = [ 'JS' ];
41 41
 
42 42
 
43 43
     /**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     public function register()
49 49
     {
50
-        return [T_OPEN_TAG];
50
+        return [ T_OPEN_TAG ];
51 51
 
52 52
     }//end register()
53 53
 
@@ -62,53 +62,53 @@  discard block
 block discarded – undo
62 62
      * @return void
63 63
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jslint.js could not be run
64 64
      */
65
-    public function process(File $phpcsFile, $stackPtr)
65
+    public function process( File $phpcsFile, $stackPtr )
66 66
     {
67
-        $lintPath = Config::getExecutablePath('gjslint');
68
-        if ($lintPath === null) {
67
+        $lintPath = Config::getExecutablePath( 'gjslint' );
68
+        if ( $lintPath === null ) {
69 69
             return;
70 70
         }
71 71
 
72 72
         $fileName = $phpcsFile->getFilename();
73 73
 
74
-        $lintPath = escapeshellcmd($lintPath);
75
-        $cmd      = $lintPath.' --nosummary --notime --unix_mode '.escapeshellarg($fileName);
76
-        exec($cmd, $output, $retval);
74
+        $lintPath = escapeshellcmd( $lintPath );
75
+        $cmd      = $lintPath . ' --nosummary --notime --unix_mode ' . escapeshellarg( $fileName );
76
+        exec( $cmd, $output, $retval );
77 77
 
78
-        if (is_array($output) === false) {
78
+        if ( is_array( $output ) === false ) {
79 79
             return;
80 80
         }
81 81
 
82
-        foreach ($output as $finding) {
83
-            $matches    = [];
84
-            $numMatches = preg_match('/^(.*):([0-9]+):\(.*?([0-9]+)\)(.*)$/', $finding, $matches);
85
-            if ($numMatches === 0) {
82
+        foreach ( $output as $finding ) {
83
+            $matches    = [ ];
84
+            $numMatches = preg_match( '/^(.*):([0-9]+):\(.*?([0-9]+)\)(.*)$/', $finding, $matches );
85
+            if ( $numMatches === 0 ) {
86 86
                 continue;
87 87
             }
88 88
 
89 89
             // Skip error codes we are ignoring.
90
-            $code = $matches[3];
91
-            if (in_array($code, $this->ignoreCodes) === true) {
90
+            $code = $matches[ 3 ];
91
+            if ( in_array( $code, $this->ignoreCodes ) === true ) {
92 92
                 continue;
93 93
             }
94 94
 
95
-            $line  = (int) $matches[2];
96
-            $error = trim($matches[4]);
95
+            $line  = (int)$matches[ 2 ];
96
+            $error = trim( $matches[ 4 ] );
97 97
 
98 98
             $message = 'gjslint says: (%s) %s';
99 99
             $data    = [
100 100
                 $code,
101 101
                 $error,
102 102
             ];
103
-            if (in_array($code, $this->errorCodes) === true) {
104
-                $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data);
103
+            if ( in_array( $code, $this->errorCodes ) === true ) {
104
+                $phpcsFile->addErrorOnLine( $message, $line, 'ExternalToolError', $data );
105 105
             } else {
106
-                $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data);
106
+                $phpcsFile->addWarningOnLine( $message, $line, 'ExternalTool', $data );
107 107
             }
108 108
         }//end foreach
109 109
 
110 110
         // Ignore the rest of the file.
111
-        return ($phpcsFile->numTokens + 1);
111
+        return ( $phpcsFile->numTokens + 1 );
112 112
 
113 113
     }//end process()
114 114
 
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @var array
24 24
      */
25
-    public $supportedTokenizers = ['JS'];
25
+    public $supportedTokenizers = [ 'JS' ];
26 26
 
27 27
 
28 28
     /**
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function register()
34 34
     {
35
-        return [T_OPEN_TAG];
35
+        return [ T_OPEN_TAG ];
36 36
 
37 37
     }//end register()
38 38
 
@@ -47,46 +47,46 @@  discard block
 block discarded – undo
47 47
      * @return void
48 48
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jshint.js could not be run
49 49
      */
50
-    public function process(File $phpcsFile, $stackPtr)
50
+    public function process( File $phpcsFile, $stackPtr )
51 51
     {
52
-        $rhinoPath  = Config::getExecutablePath('rhino');
53
-        $jshintPath = Config::getExecutablePath('jshint');
54
-        if ($rhinoPath === null && $jshintPath === null) {
52
+        $rhinoPath  = Config::getExecutablePath( 'rhino' );
53
+        $jshintPath = Config::getExecutablePath( 'jshint' );
54
+        if ( $rhinoPath === null && $jshintPath === null ) {
55 55
             return;
56 56
         }
57 57
 
58 58
         $fileName   = $phpcsFile->getFilename();
59
-        $jshintPath = escapeshellcmd($jshintPath);
59
+        $jshintPath = escapeshellcmd( $jshintPath );
60 60
 
61
-        if ($rhinoPath !== null) {
62
-            $rhinoPath = escapeshellcmd($rhinoPath);
63
-            $cmd       = "$rhinoPath \"$jshintPath\" ".escapeshellarg($fileName);
64
-            exec($cmd, $output, $retval);
61
+        if ( $rhinoPath !== null ) {
62
+            $rhinoPath = escapeshellcmd( $rhinoPath );
63
+            $cmd       = "$rhinoPath \"$jshintPath\" " . escapeshellarg( $fileName );
64
+            exec( $cmd, $output, $retval );
65 65
 
66 66
             $regex = '`^(?P<error>.+)\(.+:(?P<line>[0-9]+).*:[0-9]+\)$`';
67 67
         } else {
68
-            $cmd = "$jshintPath ".escapeshellarg($fileName);
69
-            exec($cmd, $output, $retval);
68
+            $cmd = "$jshintPath " . escapeshellarg( $fileName );
69
+            exec( $cmd, $output, $retval );
70 70
 
71 71
             $regex = '`^(.+?): line (?P<line>[0-9]+), col [0-9]+, (?P<error>.+)$`';
72 72
         }
73 73
 
74
-        if (is_array($output) === true) {
75
-            foreach ($output as $finding) {
76
-                $matches    = [];
77
-                $numMatches = preg_match($regex, $finding, $matches);
78
-                if ($numMatches === 0) {
74
+        if ( is_array( $output ) === true ) {
75
+            foreach ( $output as $finding ) {
76
+                $matches    = [ ];
77
+                $numMatches = preg_match( $regex, $finding, $matches );
78
+                if ( $numMatches === 0 ) {
79 79
                     continue;
80 80
                 }
81 81
 
82
-                $line    = (int) $matches['line'];
83
-                $message = 'jshint says: '.trim($matches['error']);
84
-                $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
82
+                $line    = (int)$matches[ 'line' ];
83
+                $message = 'jshint says: ' . trim( $matches[ 'error' ] );
84
+                $phpcsFile->addWarningOnLine( $message, $line, 'ExternalTool' );
85 85
             }
86 86
         }
87 87
 
88 88
         // Ignore the rest of the file.
89
-        return ($phpcsFile->numTokens + 1);
89
+        return ( $phpcsFile->numTokens + 1 );
90 90
 
91 91
     }//end process()
92 92
 
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Debug/ESLintSniff.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @var array
23 23
      */
24
-    public $supportedTokenizers = ['JS'];
24
+    public $supportedTokenizers = [ 'JS' ];
25 25
 
26 26
 
27 27
     /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function register()
41 41
     {
42
-        return [T_OPEN_TAG];
42
+        return [ T_OPEN_TAG ];
43 43
 
44 44
     }//end register()
45 45
 
@@ -54,58 +54,58 @@  discard block
 block discarded – undo
54 54
      * @return void
55 55
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jshint.js could not be run
56 56
      */
57
-    public function process(File $phpcsFile, $stackPtr)
57
+    public function process( File $phpcsFile, $stackPtr )
58 58
     {
59
-        $eslintPath = Config::getExecutablePath('eslint');
60
-        if ($eslintPath === null) {
59
+        $eslintPath = Config::getExecutablePath( 'eslint' );
60
+        if ( $eslintPath === null ) {
61 61
             return;
62 62
         }
63 63
 
64 64
         $filename = $phpcsFile->getFilename();
65 65
 
66 66
         $configFile = $this->configFile;
67
-        if (empty($configFile) === true) {
67
+        if ( empty( $configFile ) === true ) {
68 68
             // Attempt to autodetect.
69
-            $candidates = glob('.eslintrc{.js,.yaml,.yml,.json}', GLOB_BRACE);
70
-            if (empty($candidates) === false) {
71
-                $configFile = $candidates[0];
69
+            $candidates = glob( '.eslintrc{.js,.yaml,.yml,.json}', GLOB_BRACE );
70
+            if ( empty( $candidates ) === false ) {
71
+                $configFile = $candidates[ 0 ];
72 72
             }
73 73
         }
74 74
 
75
-        $eslintOptions = ['--format json'];
76
-        if (empty($configFile) === false) {
77
-            $eslintOptions[] = '--config '.escapeshellarg($configFile);
75
+        $eslintOptions = [ '--format json' ];
76
+        if ( empty( $configFile ) === false ) {
77
+            $eslintOptions[ ] = '--config ' . escapeshellarg( $configFile );
78 78
         }
79 79
 
80
-        $cmd = escapeshellcmd(escapeshellarg($eslintPath).' '.implode(' ', $eslintOptions).' '.escapeshellarg($filename));
80
+        $cmd = escapeshellcmd( escapeshellarg( $eslintPath ) . ' ' . implode( ' ', $eslintOptions ) . ' ' . escapeshellarg( $filename ) );
81 81
 
82 82
         // Execute!
83
-        exec($cmd, $stdout, $code);
83
+        exec( $cmd, $stdout, $code );
84 84
 
85
-        if ($code <= 0) {
85
+        if ( $code <= 0 ) {
86 86
             // No errors, continue.
87
-            return ($phpcsFile->numTokens + 1);
87
+            return ( $phpcsFile->numTokens + 1 );
88 88
         }
89 89
 
90
-        $data = json_decode(implode("\n", $stdout));
91
-        if (json_last_error() !== JSON_ERROR_NONE) {
90
+        $data = json_decode( implode( "\n", $stdout ) );
91
+        if ( json_last_error() !== JSON_ERROR_NONE ) {
92 92
             // Ignore any errors.
93
-            return ($phpcsFile->numTokens + 1);
93
+            return ( $phpcsFile->numTokens + 1 );
94 94
         }
95 95
 
96 96
         // Data is a list of files, but we only pass a single one.
97
-        $messages = $data[0]->messages;
98
-        foreach ($messages as $error) {
99
-            $message = 'eslint says: '.$error->message;
100
-            if (empty($error->fatal) === false || $error->severity === 2) {
101
-                $phpcsFile->addErrorOnLine($message, $error->line, 'ExternalTool');
97
+        $messages = $data[ 0 ]->messages;
98
+        foreach ( $messages as $error ) {
99
+            $message = 'eslint says: ' . $error->message;
100
+            if ( empty( $error->fatal ) === false || $error->severity === 2 ) {
101
+                $phpcsFile->addErrorOnLine( $message, $error->line, 'ExternalTool' );
102 102
             } else {
103
-                $phpcsFile->addWarningOnLine($message, $error->line, 'ExternalTool');
103
+                $phpcsFile->addWarningOnLine( $message, $error->line, 'ExternalTool' );
104 104
             }
105 105
         }
106 106
 
107 107
         // Ignore the rest of the file.
108
-        return ($phpcsFile->numTokens + 1);
108
+        return ( $phpcsFile->numTokens + 1 );
109 109
 
110 110
     }//end process()
111 111
 
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      *
22 22
      * @var array
23 23
      */
24
-    public $supportedTokenizers = ['CSS'];
24
+    public $supportedTokenizers = [ 'CSS' ];
25 25
 
26 26
 
27 27
     /**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      */
32 32
     public function register()
33 33
     {
34
-        return [T_OPEN_TAG];
34
+        return [ T_OPEN_TAG ];
35 35
 
36 36
     }//end register()
37 37
 
@@ -45,49 +45,49 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return void
47 47
      */
48
-    public function process(File $phpcsFile, $stackPtr)
48
+    public function process( File $phpcsFile, $stackPtr )
49 49
     {
50
-        $csslintPath = Config::getExecutablePath('csslint');
51
-        if ($csslintPath === null) {
50
+        $csslintPath = Config::getExecutablePath( 'csslint' );
51
+        if ( $csslintPath === null ) {
52 52
             return;
53 53
         }
54 54
 
55 55
         $fileName = $phpcsFile->getFilename();
56 56
 
57
-        $cmd = escapeshellcmd($csslintPath).' '.escapeshellarg($fileName).' 2>&1';
58
-        exec($cmd, $output, $retval);
57
+        $cmd = escapeshellcmd( $csslintPath ) . ' ' . escapeshellarg( $fileName ) . ' 2>&1';
58
+        exec( $cmd, $output, $retval );
59 59
 
60
-        if (is_array($output) === false) {
60
+        if ( is_array( $output ) === false ) {
61 61
             return;
62 62
         }
63 63
 
64
-        $count = count($output);
64
+        $count = count( $output );
65 65
 
66
-        for ($i = 0; $i < $count; $i++) {
67
-            $matches    = [];
66
+        for ( $i = 0; $i < $count; $i++ ) {
67
+            $matches    = [ ];
68 68
             $numMatches = preg_match(
69 69
                 '/(error|warning) at line (\d+)/',
70
-                $output[$i],
70
+                $output[ $i ],
71 71
                 $matches
72 72
             );
73 73
 
74
-            if ($numMatches === 0) {
74
+            if ( $numMatches === 0 ) {
75 75
                 continue;
76 76
             }
77 77
 
78
-            $line    = (int) $matches[2];
79
-            $message = 'csslint says: '.$output[($i + 1)];
78
+            $line    = (int)$matches[ 2 ];
79
+            $message = 'csslint says: ' . $output[ ( $i + 1 ) ];
80 80
             // First line is message with error line and error code.
81 81
             // Second is error message.
82 82
             // Third is wrong line in file.
83 83
             // Fourth is empty line.
84 84
             $i += 4;
85 85
 
86
-            $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
86
+            $phpcsFile->addWarningOnLine( $message, $line, 'ExternalTool' );
87 87
         }//end for
88 88
 
89 89
         // Ignore the rest of the file.
90
-        return ($phpcsFile->numTokens + 1);
90
+        return ( $phpcsFile->numTokens + 1 );
91 91
 
92 92
     }//end process()
93 93
 
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/WhiteSpace/IncrementDecrementSpacingSniff.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -52,60 +52,60 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    public function process(File $phpcsFile, $stackPtr)
55
+    public function process( File $phpcsFile, $stackPtr )
56 56
     {
57 57
         $tokens = $phpcsFile->getTokens();
58 58
 
59 59
         $tokenName = 'increment';
60
-        if ($tokens[$stackPtr]['code'] === T_DEC) {
60
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DEC ) {
61 61
             $tokenName = 'decrement';
62 62
         }
63 63
 
64 64
         // Is this a pre-increment/decrement ?
65
-        $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
66
-        if ($nextNonEmpty !== false
67
-            && (($phpcsFile->tokenizerType === 'PHP' && $tokens[$nextNonEmpty]['code'] === T_VARIABLE)
68
-            || ($phpcsFile->tokenizerType === 'JS' && $tokens[$nextNonEmpty]['code'] === T_STRING))
65
+        $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
66
+        if ( $nextNonEmpty !== false
67
+            && ( ( $phpcsFile->tokenizerType === 'PHP' && $tokens[ $nextNonEmpty ][ 'code' ] === T_VARIABLE )
68
+            || ( $phpcsFile->tokenizerType === 'JS' && $tokens[ $nextNonEmpty ][ 'code' ] === T_STRING ) )
69 69
         ) {
70
-            if ($nextNonEmpty === ($stackPtr + 1)) {
71
-                $phpcsFile->recordMetric($stackPtr, 'Spacing between in/decrementor and variable', 0);
70
+            if ( $nextNonEmpty === ( $stackPtr + 1 ) ) {
71
+                $phpcsFile->recordMetric( $stackPtr, 'Spacing between in/decrementor and variable', 0 );
72 72
                 return;
73 73
             }
74 74
 
75 75
             $spaces            = 0;
76 76
             $fixable           = true;
77
-            $nextNonWhitespace = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
78
-            if ($nextNonWhitespace !== $nextNonEmpty) {
77
+            $nextNonWhitespace = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
78
+            if ( $nextNonWhitespace !== $nextNonEmpty ) {
79 79
                 $fixable = false;
80 80
                 $spaces  = 'comment';
81 81
             } else {
82
-                if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
82
+                if ( $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $nextNonEmpty ][ 'line' ] ) {
83 83
                     $spaces = 'newline';
84 84
                 } else {
85
-                    $spaces = $tokens[($stackPtr + 1)]['length'];
85
+                    $spaces = $tokens[ ( $stackPtr + 1 ) ][ 'length' ];
86 86
                 }
87 87
             }
88 88
 
89
-            $phpcsFile->recordMetric($stackPtr, 'Spacing between in/decrementor and variable', $spaces);
89
+            $phpcsFile->recordMetric( $stackPtr, 'Spacing between in/decrementor and variable', $spaces );
90 90
 
91 91
             $error     = 'Expected no spaces between the %s operator and %s; %s found';
92
-            $errorCode = 'SpaceAfter'.ucfirst($tokenName);
92
+            $errorCode = 'SpaceAfter' . ucfirst( $tokenName );
93 93
             $data      = [
94 94
                 $tokenName,
95
-                $tokens[$nextNonEmpty]['content'],
95
+                $tokens[ $nextNonEmpty ][ 'content' ],
96 96
                 $spaces,
97 97
             ];
98 98
 
99
-            if ($fixable === false) {
100
-                $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
99
+            if ( $fixable === false ) {
100
+                $phpcsFile->addError( $error, $stackPtr, $errorCode, $data );
101 101
                 return;
102 102
             }
103 103
 
104
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data);
105
-            if ($fix === true) {
104
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, $errorCode, $data );
105
+            if ( $fix === true ) {
106 106
                 $phpcsFile->fixer->beginChangeset();
107
-                for ($i = ($stackPtr + 1); $i < $nextNonEmpty; $i++) {
108
-                    $phpcsFile->fixer->replaceToken($i, '');
107
+                for ( $i = ( $stackPtr + 1 ); $i < $nextNonEmpty; $i++ ) {
108
+                    $phpcsFile->fixer->replaceToken( $i, '' );
109 109
                 }
110 110
 
111 111
                 $phpcsFile->fixer->endChangeset();
@@ -115,50 +115,50 @@  discard block
 block discarded – undo
115 115
         }//end if
116 116
 
117 117
         // Is this a post-increment/decrement ?
118
-        $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
119
-        if ($prevNonEmpty !== false
120
-            && (($phpcsFile->tokenizerType === 'PHP' && $tokens[$prevNonEmpty]['code'] === T_VARIABLE)
121
-            || ($phpcsFile->tokenizerType === 'JS' && $tokens[$prevNonEmpty]['code'] === T_STRING))
118
+        $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
119
+        if ( $prevNonEmpty !== false
120
+            && ( ( $phpcsFile->tokenizerType === 'PHP' && $tokens[ $prevNonEmpty ][ 'code' ] === T_VARIABLE )
121
+            || ( $phpcsFile->tokenizerType === 'JS' && $tokens[ $prevNonEmpty ][ 'code' ] === T_STRING ) )
122 122
         ) {
123
-            if ($prevNonEmpty === ($stackPtr - 1)) {
124
-                $phpcsFile->recordMetric($stackPtr, 'Spacing between in/decrementor and variable', 0);
123
+            if ( $prevNonEmpty === ( $stackPtr - 1 ) ) {
124
+                $phpcsFile->recordMetric( $stackPtr, 'Spacing between in/decrementor and variable', 0 );
125 125
                 return;
126 126
             }
127 127
 
128 128
             $spaces            = 0;
129 129
             $fixable           = true;
130
-            $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
131
-            if ($prevNonWhitespace !== $prevNonEmpty) {
130
+            $prevNonWhitespace = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
131
+            if ( $prevNonWhitespace !== $prevNonEmpty ) {
132 132
                 $fixable = false;
133 133
                 $spaces  = 'comment';
134 134
             } else {
135
-                if ($tokens[$stackPtr]['line'] !== $tokens[$nextNonEmpty]['line']) {
135
+                if ( $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $nextNonEmpty ][ 'line' ] ) {
136 136
                     $spaces = 'newline';
137 137
                 } else {
138
-                    $spaces = $tokens[($stackPtr - 1)]['length'];
138
+                    $spaces = $tokens[ ( $stackPtr - 1 ) ][ 'length' ];
139 139
                 }
140 140
             }
141 141
 
142
-            $phpcsFile->recordMetric($stackPtr, 'Spacing between in/decrementor and variable', $spaces);
142
+            $phpcsFile->recordMetric( $stackPtr, 'Spacing between in/decrementor and variable', $spaces );
143 143
 
144 144
             $error     = 'Expected no spaces between %s and the %s operator; %s found';
145
-            $errorCode = 'SpaceAfter'.ucfirst($tokenName);
145
+            $errorCode = 'SpaceAfter' . ucfirst( $tokenName );
146 146
             $data      = [
147
-                $tokens[$prevNonEmpty]['content'],
147
+                $tokens[ $prevNonEmpty ][ 'content' ],
148 148
                 $tokenName,
149 149
                 $spaces,
150 150
             ];
151 151
 
152
-            if ($fixable === false) {
153
-                $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
152
+            if ( $fixable === false ) {
153
+                $phpcsFile->addError( $error, $stackPtr, $errorCode, $data );
154 154
                 return;
155 155
             }
156 156
 
157
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, $errorCode, $data);
158
-            if ($fix === true) {
157
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, $errorCode, $data );
158
+            if ( $fix === true ) {
159 159
                 $phpcsFile->fixer->beginChangeset();
160
-                for ($i = ($stackPtr - 1); $prevNonEmpty < $i; $i--) {
161
-                    $phpcsFile->fixer->replaceToken($i, '');
160
+                for ( $i = ( $stackPtr - 1 ); $prevNonEmpty < $i; $i-- ) {
161
+                    $phpcsFile->fixer->replaceToken( $i, '' );
162 162
                 }
163 163
 
164 164
                 $phpcsFile->fixer->endChangeset();
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php 1 patch
Spacing   +48 added lines, -48 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 [T_OPEN_TAG];
44
+        return [ T_OPEN_TAG ];
45 45
 
46 46
     }//end register()
47 47
 
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return void
57 57
      */
58
-    public function process(File $phpcsFile, $stackPtr)
58
+    public function process( File $phpcsFile, $stackPtr )
59 59
     {
60
-        if ($this->tabWidth === null) {
61
-            if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
60
+        if ( $this->tabWidth === null ) {
61
+            if ( isset( $phpcsFile->config->tabWidth ) === false || $phpcsFile->config->tabWidth === 0 ) {
62 62
                 // We have no idea how wide tabs are, so assume 4 spaces for metrics.
63 63
                 $this->tabWidth = 4;
64 64
             } else {
@@ -75,37 +75,37 @@  discard block
 block discarded – undo
75 75
             T_COMMENT                => true,
76 76
         ];
77 77
 
78
-        for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
79
-            if (isset($checkTokens[$tokens[$i]['code']]) === false) {
78
+        for ( $i = 0; $i < $phpcsFile->numTokens; $i++ ) {
79
+            if ( isset( $checkTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) {
80 80
                 continue;
81 81
             }
82 82
 
83 83
             // If tabs are being converted to spaces by the tokeniser, the
84 84
             // original content should be checked instead of the converted content.
85
-            if (isset($tokens[$i]['orig_content']) === true) {
86
-                $content = $tokens[$i]['orig_content'];
85
+            if ( isset( $tokens[ $i ][ 'orig_content' ] ) === true ) {
86
+                $content = $tokens[ $i ][ 'orig_content' ];
87 87
             } else {
88
-                $content = $tokens[$i]['content'];
88
+                $content = $tokens[ $i ][ 'content' ];
89 89
             }
90 90
 
91
-            if ($content === '') {
91
+            if ( $content === '' ) {
92 92
                 continue;
93 93
             }
94 94
 
95 95
             // If this is an inline HTML token or a subsequent line of a multi-line comment,
96 96
             // split off the indentation as that is the only part to take into account for the metrics.
97 97
             $indentation = $content;
98
-            if (($tokens[$i]['code'] === T_INLINE_HTML
99
-                || $tokens[$i]['code'] === T_COMMENT)
100
-                && preg_match('`^(\s*)\S.*`s', $content, $matches) > 0
98
+            if ( ( $tokens[ $i ][ 'code' ] === T_INLINE_HTML
99
+                || $tokens[ $i ][ 'code' ] === T_COMMENT )
100
+                && preg_match( '`^(\s*)\S.*`s', $content, $matches ) > 0
101 101
             ) {
102
-                if (isset($matches[1]) === true) {
103
-                    $indentation = $matches[1];
102
+                if ( isset( $matches[ 1 ] ) === true ) {
103
+                    $indentation = $matches[ 1 ];
104 104
                 }
105 105
             }
106 106
 
107
-            if (($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE
108
-                || $tokens[$i]['code'] === T_COMMENT)
107
+            if ( ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_WHITESPACE
108
+                || $tokens[ $i ][ 'code' ] === T_COMMENT )
109 109
                 && $indentation === ' '
110 110
             ) {
111 111
                 // Ignore all non-indented comments, especially for recording metrics.
@@ -113,39 +113,39 @@  discard block
 block discarded – undo
113 113
             }
114 114
 
115 115
             $recordMetrics = true;
116
-            if ($content === $indentation
117
-                && isset($tokens[($i + 1)]) === true
118
-                && $tokens[$i]['line'] < $tokens[($i + 1)]['line']
116
+            if ( $content === $indentation
117
+                && isset( $tokens[ ( $i + 1 ) ] ) === true
118
+                && $tokens[ $i ][ 'line' ] < $tokens[ ( $i + 1 ) ][ 'line' ]
119 119
             ) {
120 120
                 // Don't record metrics for empty lines.
121 121
                 $recordMetrics = false;
122 122
             }
123 123
 
124
-            $foundTabs = substr_count($content, "\t");
124
+            $foundTabs = substr_count( $content, "\t" );
125 125
 
126 126
             $error     = 'Spaces must be used to indent lines; tabs are not allowed';
127 127
             $errorCode = 'TabsUsed';
128
-            if ($tokens[$i]['column'] === 1) {
129
-                if ($recordMetrics === true) {
130
-                    $foundIndentSpaces = substr_count($indentation, ' ');
131
-                    $foundIndentTabs   = substr_count($indentation, "\t");
132
-
133
-                    if ($foundIndentTabs > 0 && $foundIndentSpaces === 0) {
134
-                        $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
135
-                    } else if ($foundIndentTabs === 0 && $foundIndentSpaces > 0) {
136
-                        $phpcsFile->recordMetric($i, 'Line indent', 'spaces');
137
-                    } else if ($foundIndentTabs > 0 && $foundIndentSpaces > 0) {
138
-                        $spacePosition  = strpos($indentation, ' ');
139
-                        $tabAfterSpaces = strpos($indentation, "\t", $spacePosition);
140
-                        if ($tabAfterSpaces !== false) {
141
-                            $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
128
+            if ( $tokens[ $i ][ 'column' ] === 1 ) {
129
+                if ( $recordMetrics === true ) {
130
+                    $foundIndentSpaces = substr_count( $indentation, ' ' );
131
+                    $foundIndentTabs   = substr_count( $indentation, "\t" );
132
+
133
+                    if ( $foundIndentTabs > 0 && $foundIndentSpaces === 0 ) {
134
+                        $phpcsFile->recordMetric( $i, 'Line indent', 'tabs' );
135
+                    } else if ( $foundIndentTabs === 0 && $foundIndentSpaces > 0 ) {
136
+                        $phpcsFile->recordMetric( $i, 'Line indent', 'spaces' );
137
+                    } else if ( $foundIndentTabs > 0 && $foundIndentSpaces > 0 ) {
138
+                        $spacePosition  = strpos( $indentation, ' ' );
139
+                        $tabAfterSpaces = strpos( $indentation, "\t", $spacePosition );
140
+                        if ( $tabAfterSpaces !== false ) {
141
+                            $phpcsFile->recordMetric( $i, 'Line indent', 'mixed' );
142 142
                         } else {
143 143
                             // Check for use of precision spaces.
144
-                            $numTabs = (int) floor($foundIndentSpaces / $this->tabWidth);
145
-                            if ($numTabs === 0) {
146
-                                $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
144
+                            $numTabs = (int)floor( $foundIndentSpaces / $this->tabWidth );
145
+                            if ( $numTabs === 0 ) {
146
+                                $phpcsFile->recordMetric( $i, 'Line indent', 'tabs' );
147 147
                             } else {
148
-                                $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
148
+                                $phpcsFile->recordMetric( $i, 'Line indent', 'mixed' );
149 149
                             }
150 150
                         }
151 151
                     }
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 // Look for tabs so we can report and replace, but don't
155 155
                 // record any metrics about them because they aren't
156 156
                 // line indent tokens.
157
-                if ($foundTabs > 0) {
157
+                if ( $foundTabs > 0 ) {
158 158
                     $error     = 'Spaces must be used for alignment; tabs are not allowed';
159 159
                     $errorCode = 'NonIndentTabsUsed';
160 160
                 }
161 161
             }//end if
162 162
 
163
-            if ($foundTabs === 0) {
163
+            if ( $foundTabs === 0 ) {
164 164
                 continue;
165 165
             }
166 166
 
167
-            $fix = $phpcsFile->addFixableError($error, $i, $errorCode);
168
-            if ($fix === true) {
169
-                if (isset($tokens[$i]['orig_content']) === true) {
167
+            $fix = $phpcsFile->addFixableError( $error, $i, $errorCode );
168
+            if ( $fix === true ) {
169
+                if ( isset( $tokens[ $i ][ 'orig_content' ] ) === true ) {
170 170
                     // Use the replacement that PHPCS has already done.
171
-                    $phpcsFile->fixer->replaceToken($i, $tokens[$i]['content']);
171
+                    $phpcsFile->fixer->replaceToken( $i, $tokens[ $i ][ 'content' ] );
172 172
                 } else {
173 173
                     // Replace tabs with spaces, using an indent of tabWidth spaces.
174 174
                     // Other sniffs can then correct the indent if they need to.
175
-                    $newContent = str_replace("\t", str_repeat(' ', $this->tabWidth), $tokens[$i]['content']);
176
-                    $phpcsFile->fixer->replaceToken($i, $newContent);
175
+                    $newContent = str_replace( "\t", str_repeat( ' ', $this->tabWidth ), $tokens[ $i ][ 'content' ] );
176
+                    $phpcsFile->fixer->replaceToken( $i, $newContent );
177 177
                 }
178 178
             }
179 179
         }//end for
180 180
 
181 181
         // Ignore the rest of the file.
182
-        return ($phpcsFile->numTokens + 1);
182
+        return ( $phpcsFile->numTokens + 1 );
183 183
 
184 184
     }//end process()
185 185
 
Please login to merge, or discard this patch.