Skip to content

Commit 8030138

Browse files
committed
CS: Fix violations in VIPCS code
Mostly `PSR2.Classes.PropertyDeclaration.Underscore` issues.
1 parent 0349261 commit 8030138

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff {
2222
*
2323
* @var string
2424
*/
25-
private $_currentClass = '';
25+
private $currentClass = '';
2626

2727
/**
2828
* A list of functions in the current class.
2929
*
3030
* @var string[]
3131
*/
32-
private $_functionList = [];
32+
private $functionList = [];
3333

3434
/**
3535
* A list of classes and methods to check.
@@ -204,9 +204,9 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco
204204

205205
$className = $phpcsFile->getDeclarationName( $currScope );
206206

207-
if ( $className !== $this->_currentClass ) {
207+
if ( $className !== $this->currentClass ) {
208208
$this->loadFunctionNamesInScope( $phpcsFile, $currScope );
209-
$this->_currentClass = $className;
209+
$this->currentClass = $className;
210210
}
211211

212212
$methodName = $phpcsFile->getDeclarationName( $stackPtr );
@@ -300,7 +300,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco
300300
*/
301301
private function addError( $parentClassName, $methodName, $currentMethodSignature, $parentMethodSignature, $phpcsFile, $stackPtr ) {
302302

303-
$currentSignature = sprintf( '%s::%s(%s)', $this->_currentClass, $methodName, implode( ', ', $this->generateParamList( $currentMethodSignature ) ) );
303+
$currentSignature = sprintf( '%s::%s(%s)', $this->currentClass, $methodName, implode( ', ', $this->generateParamList( $currentMethodSignature ) ) );
304304

305305
$parentSignature = sprintf( '%s::%s(%s)', $parentClassName, $methodName, implode( ', ', $this->generateParamList( $parentMethodSignature ) ) );
306306

@@ -354,16 +354,16 @@ private function generateParamList( $methodSignature ) {
354354
* @return void
355355
*/
356356
protected function loadFunctionNamesInScope( File $phpcsFile, $currScope ) {
357-
$this->_functionList = [];
358-
$tokens = $phpcsFile->getTokens();
357+
$this->functionList = [];
358+
$tokens = $phpcsFile->getTokens();
359359

360360
for ( $i = ( $tokens[ $currScope ]['scope_opener'] + 1 ); $i < $tokens[ $currScope ]['scope_closer']; $i++ ) {
361361
if ( T_FUNCTION !== $tokens[ $i ]['code'] ) {
362362
continue;
363363
}
364364

365-
$next = $phpcsFile->findNext( T_STRING, $i );
366-
$this->_functionList[] = trim( $tokens[ $next ]['content'] );
365+
$next = $phpcsFile->findNext( T_STRING, $i );
366+
$this->functionList[] = trim( $tokens[ $next ]['content'] );
367367
}
368368
}
369369

WordPressVIPMinimum/Sniffs/Functions/CheckReturnValueSniff.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace WordPressVIPMinimum\Sniffs\Functions;
99

10-
use PHP_CodeSniffer\Files\File;
1110
use WordPressVIPMinimum\Sniffs\Sniff;
1211
use PHP_CodeSniffer\Util\Tokens;
1312

@@ -22,13 +21,6 @@
2221
*/
2322
class CheckReturnValueSniff extends Sniff {
2423

25-
/**
26-
* Tokens of the whole file.
27-
*
28-
* @var array
29-
*/
30-
private $_tokens = [];
31-
3224
/**
3325
* Pairs we are about to check.
3426
*

WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DynamicCallsSniff extends Sniff {
3131
*
3232
* @var array
3333
*/
34-
private $_blacklisted_functions = [
34+
private $blacklisted_functions = [
3535
'assert',
3636
'compact',
3737
'extract',
@@ -49,14 +49,14 @@ class DynamicCallsSniff extends Sniff {
4949
*
5050
* @var array
5151
*/
52-
private $_variables_arr = [];
52+
private $variables_arr = [];
5353

5454
/**
5555
* The position in the stack where the token was found.
5656
*
5757
* @var int
5858
*/
59-
private $_stackPtr;
59+
private $stackPtr;
6060

6161
/**
6262
* Returns the token types that this sniff is interested in.
@@ -77,7 +77,7 @@ public function register() {
7777
* @return void
7878
*/
7979
public function process_token( $stackPtr ) {
80-
$this->_stackPtr = $stackPtr;
80+
$this->stackPtr = $stackPtr;
8181

8282
// First collect all variables encountered and their values.
8383
$this->collect_variables();
@@ -101,13 +101,13 @@ private function collect_variables() {
101101

102102
if (
103103
'T_VARIABLE' !==
104-
$this->tokens[ $this->_stackPtr ]['type']
104+
$this->tokens[ $this->stackPtr ]['type']
105105
) {
106106
return;
107107
}
108108

109109
$current_var_name = $this->tokens[
110-
$this->_stackPtr
110+
$this->stackPtr
111111
]['content'];
112112

113113
/*
@@ -118,7 +118,7 @@ private function collect_variables() {
118118

119119
$t_item_key = $this->phpcsFile->findNext(
120120
[ T_WHITESPACE ],
121-
$this->_stackPtr + 1,
121+
$this->stackPtr + 1,
122122
null,
123123
true,
124124
null,
@@ -162,7 +162,7 @@ private function collect_variables() {
162162
$current_var_value =
163163
$this->tokens[ $t_item_key ]['content'];
164164

165-
$this->_variables_arr[ $current_var_name ] =
165+
$this->variables_arr[ $current_var_name ] =
166166
str_replace( "'", '', $current_var_value );
167167
}
168168

@@ -179,7 +179,7 @@ private function find_dynamic_calls() {
179179
* anything
180180
*/
181181

182-
if ( empty( $this->_variables_arr ) ) {
182+
if ( empty( $this->variables_arr ) ) {
183183
return;
184184
}
185185

@@ -189,7 +189,7 @@ private function find_dynamic_calls() {
189189

190190
if (
191191
'T_VARIABLE' !==
192-
$this->tokens[ $this->_stackPtr ]['type']
192+
$this->tokens[ $this->stackPtr ]['type']
193193
) {
194194
return;
195195
}
@@ -202,8 +202,8 @@ private function find_dynamic_calls() {
202202
*/
203203

204204
if ( ! isset(
205-
$this->_variables_arr[
206-
$this->tokens[ $this->_stackPtr ]['content']
205+
$this->variables_arr[
206+
$this->tokens[ $this->stackPtr ]['content']
207207
]
208208
) ) {
209209
return;
@@ -221,39 +221,39 @@ private function find_dynamic_calls() {
221221
} while (
222222
'T_WHITESPACE' ===
223223
$this->tokens[
224-
$this->_stackPtr + $i
224+
$this->stackPtr + $i
225225
]['type']
226226
);
227227

228228
if (
229229
'T_OPEN_PARENTHESIS' !==
230230
$this->tokens[
231-
$this->_stackPtr + $i
231+
$this->stackPtr + $i
232232
]['type']
233233
) {
234234
return;
235235
}
236236

237-
$t_item_key = $this->_stackPtr + $i;
237+
$t_item_key = $this->stackPtr + $i;
238238

239239
/*
240240
* We have a variable match, but make sure it contains name
241241
* of a function which is on our blacklist.
242242
*/
243243

244244
if ( ! in_array(
245-
$this->_variables_arr[
246-
$this->tokens[ $this->_stackPtr ]['content']
245+
$this->variables_arr[
246+
$this->tokens[ $this->stackPtr ]['content']
247247
],
248-
$this->_blacklisted_functions,
248+
$this->blacklisted_functions,
249249
true
250250
) ) {
251251
return;
252252
}
253253

254254
// We do, so report.
255255
$message = 'Dynamic calling is not recommended in the case of %s.';
256-
$data = [ $this->_variables_arr[ $this->tokens[ $this->_stackPtr ]['content'] ] ];
256+
$data = [ $this->variables_arr[ $this->tokens[ $this->stackPtr ]['content'] ] ];
257257
$this->phpcsFile->addError( $message, $t_item_key, 'DynamicCalls', $data );
258258
}
259259
}

0 commit comments

Comments
 (0)