Skip to content

Commit 1003b66

Browse files
committed
Upgrade PHP_CodeSniffer to support version 3.
1 parent b1e5203 commit 1003b66

36 files changed

+211
-112
lines changed

DWS/Helpers/Array.php renamed to DWS/Helpers/Arrays.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,30 @@
66
* @subpackage Helpers
77
*/
88

9+
namespace DWS\Helpers;
10+
11+
use PHP_CodeSniffer\Files\File;
12+
913
/**
1014
* A collection of helper methods for arrays.
1115
*
1216
* @package DWS
1317
* @subpackage Helpers
1418
*/
15-
final class DWS_Helpers_Array
19+
final class Arrays
1620
{
1721
/**
1822
* Returns the positions of all of the commas that belong to the array beginning at $arrayStart.
1923
*
20-
* @param PHP_CodeSniffer_File $phpcsFile The file where the array is declared.
24+
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the array is declared.
2125
* @param int $arrayStart The position of the opening parenthesis or bracket for the array in the file.
2226
*
2327
* @return array The stack pointers for all of the commas in the array (excluding commas in nested arrays, functions, etc.).
2428
*/
25-
public static function commaPositions(PHP_CodeSniffer_File $phpcsFile, $arrayStart)
29+
public static function commaPositions(File $phpcsFile, $arrayStart)
2630
{
2731
$tokens = $phpcsFile->getTokens();
28-
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $arrayStart);
32+
$arrayEnd = Bracket::bracketEnd($phpcsFile, $arrayStart);
2933

3034
$commas = [];
3135
for ($i = $arrayStart + 1; $i <= $arrayEnd; $i++) {

DWS/Helpers/Bracket.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66
* @subpackage Helpers
77
*/
88

9+
namespace DWS\Helpers;
10+
11+
use PHP_CodeSniffer\Files\File;
12+
913
/**
1014
* A collection of helper methods for bracketed expressions.
1115
*
1216
* @package DWS
1317
* @subpackage Helpers
1418
*/
15-
final class DWS_Helpers_Bracket
19+
final class Bracket
1620
{
1721
/**
1822
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket.
1923
*
20-
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
24+
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
2125
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
2226
*
2327
* @return int The position of the opening bracket, or if not found, the given $stackPtr.
2428
*/
25-
public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
29+
public static function bracketStart(File $phpcsFile, $stackPtr)
2630
{
2731
$tokens = $phpcsFile->getTokens();
2832
if (array_key_exists('parenthesis_opener', $tokens[$stackPtr])) {
@@ -37,12 +41,12 @@ public static function bracketStart(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3741
/**
3842
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the ending bracket.
3943
*
40-
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
44+
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
4145
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
4246
*
4347
* @return int The position of the ending bracket, or if not found, the given $stackPtr.
4448
*/
45-
public static function bracketEnd(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
49+
public static function bracketEnd(File $phpcsFile, $stackPtr)
4650
{
4751
$tokens = $phpcsFile->getTokens();
4852
if (array_key_exists('parenthesis_closer', $tokens[$stackPtr])) {

DWS/Helpers/Operator.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
66
* @subpackage Helpers
77
*/
88

9+
namespace DWS\Helpers;
10+
11+
use PHP_CodeSniffer\Files\File;
12+
use PHP_CodeSniffer\Util\Tokens;
13+
914
/**
1015
* A collection of helper methods for operators.
1116
*
1217
* @package DWS
1318
* @subpackage Helpers
1419
*/
15-
final class DWS_Helpers_Operator
20+
final class Operator
1621
{
1722
/**
1823
* Given a pointer to a bracketed expression (such as T_ARRAY or T_OPEN_SHORT_ARRAY), returns the stack pointer for the opening bracket.
1924
*
20-
* @param PHP_CodeSniffer_File $phpcsFile The file where the bracketed expression is declared.
25+
* @param PHP_CodeSniffer\Files\File $phpcsFile The file where the bracketed expression is declared.
2126
* @param int $stackPtr The position of the expression element in the stack in $phpcsFile.
2227
*
2328
* @return int The position of the opening bracket, or if not found, the given $stackPtr.
2429
*/
25-
public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
30+
public static function isUnary(File $phpcsFile, $stackPtr)
2631
{
2732
$tokens = $phpcsFile->getTokens();
2833

@@ -38,9 +43,9 @@ public static function isUnary(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3843
$prev = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
3944
$unaryHints = array_unique(
4045
array_merge(
41-
PHP_CodeSniffer_Tokens::$comparisonTokens,
42-
PHP_CodeSniffer_Tokens::$operators,
43-
PHP_CodeSniffer_Tokens::$assignmentTokens,
46+
Tokens::$comparisonTokens,
47+
Tokens::$operators,
48+
Tokens::$assignmentTokens,
4449
[
4550
T_RETURN,
4651
T_COMMA,

DWS/Helpers/WhiteSpace.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66
* @subpackage Helpers
77
*/
88

9+
namespace DWS\Helpers;
10+
11+
use PHP_CodeSniffer\Files\File;
12+
913
/**
1014
* A collection of helper methods for whitespace.
1115
*
1216
* @package DWS
1317
* @subpackage Helpers
1418
*/
15-
final class DWS_Helpers_Whitespace
19+
final class Whitespace
1620
{
1721
/**
1822
* Returns the indentation level of the requested line.
1923
*
20-
* @param PHP_CodeSniffer_File $phpcsFile The file in question.
24+
* @param PHP_CodeSniffer\Files\File $phpcsFile The file in question.
2125
* @param int $stackPtr The stack pointer to the element on the line in question.
2226
*
2327
* @return int The normalized column number for the initial non-whitespace token on the line.
2428
*/
25-
public static function indentOfLine(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
29+
public static function indentOfLine(File $phpcsFile, $stackPtr)
2630
{
2731
$tokens = $phpcsFile->getTokens();
2832
$beginningElement = $stackPtr;

DWS/Sniffs/Arrays/ArrayDeclarationSniff.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
* @subpackage Sniffs
77
*/
88

9+
namespace DWS\Sniffs\Arrays;
10+
11+
use DWS\Helpers\Bracket;
12+
use PHP_CodeSniffer\Sniffs\Sniff;
13+
use PHP_CodeSniffer\Files\File;
14+
915
/**
1016
* A test to ensure that arrays conform to the array coding standard.
1117
*
1218
* @package DWS
1319
* @subpackage Sniffs
1420
*/
15-
final class DWS_Sniffs_Arrays_ArrayDeclarationSniff implements PHP_CodeSniffer_Sniff
21+
final class ArrayDeclarationSniff implements Sniff
1622
{
1723
/**
1824
* Returns an array of tokens this test wants to listen for.
@@ -27,16 +33,16 @@ public function register()
2733
/**
2834
* Processes this sniff, when one of its tokens is encountered.
2935
*
30-
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
36+
* @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
3137
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
3238
*
3339
* @return void
3440
*/
35-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
41+
public function process(File $phpcsFile, $stackPtr)
3642
{
3743
$tokens = $phpcsFile->getTokens();
38-
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
39-
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
44+
$arrayStart = Bracket::bracketStart($phpcsFile, $stackPtr);
45+
$arrayEnd = Bracket::bracketEnd($phpcsFile, $stackPtr);
4046

4147
if (!in_array($arrayStart, [$stackPtr, $stackPtr + 1])) {
4248
$phpcsFile->addError('No whitespace allowed between the array keyword and the opening parenthesis', $stackPtr, 'SpaceAfterKeyword');

DWS/Sniffs/Arrays/ArrowSpacingSniff.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
* @subpackage Sniffs
77
*/
88

9+
namespace DWS\Sniffs\Arrays;
10+
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
use PHP_CodeSniffer\Files\File;
13+
914
/**
1015
* A test to ensure that arrows in arrays are set with proper whitespace.
1116
*
1217
* @package DWS
1318
* @subpackage Sniffs
1419
*/
15-
final class DWS_Sniffs_Arrays_ArrowSpacingSniff implements PHP_CodeSniffer_Sniff
20+
final class ArrowSpacingSniff implements Sniff
1621
{
1722
/**
1823
* Returns an array of tokens this test wants to listen for.
@@ -27,12 +32,12 @@ public function register()
2732
/**
2833
* Processes this sniff, when one of its tokens is encountered.
2934
*
30-
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
35+
* @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
3136
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
3237
*
3338
* @return void
3439
*/
35-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
40+
public function process(File $phpcsFile, $stackPtr)
3641
{
3742
$tokens = $phpcsFile->getTokens();
3843

DWS/Sniffs/Arrays/CommaSpacingSniff.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
* @subpackage Sniffs
77
*/
88

9+
namespace DWS\Sniffs\Arrays;
10+
11+
use DWS\Helpers;
12+
use PHP_CodeSniffer\Sniffs\Sniff;
13+
use PHP_CodeSniffer\Files\File;
14+
915
/**
1016
* A test to ensure that commas in arrays are set with proper whitespace.
1117
*
1218
* @package DWS
1319
* @subpackage Sniffs
1420
*/
15-
final class DWS_Sniffs_Arrays_CommaSpacingSniff implements PHP_CodeSniffer_Sniff
21+
final class CommaSpacingSniff implements Sniff
1622
{
1723
/**
1824
* Returns an array of tokens this test wants to listen for.
@@ -27,20 +33,20 @@ public function register()
2733
/**
2834
* Processes this sniff, when one of its tokens is encountered.
2935
*
30-
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
36+
* @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
3137
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
3238
*
3339
* @return void
3440
*/
35-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
41+
public function process(File $phpcsFile, $stackPtr)
3642
{
3743
$tokens = $phpcsFile->getTokens();
38-
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
39-
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
44+
$arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr);
45+
$arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr);
4046

4147
$isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];
4248

43-
foreach (DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart) as $comma) {
49+
foreach (Helpers\Arrays::commaPositions($phpcsFile, $arrayStart) as $comma) {
4450
if ($tokens[$comma - 1]['code'] === T_WHITESPACE) {
4551
$phpcsFile->addError('No whitespace allowed before commas in an array', $comma, 'SpaceBeforeComma');
4652
}

DWS/Sniffs/Arrays/TrailingCommaSniff.php

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
* @subpackage Sniffs
77
*/
88

9+
namespace DWS\Sniffs\Arrays;
10+
11+
use DWS\Helpers;
12+
use PHP_CodeSniffer\Sniffs\Sniff;
13+
use PHP_CodeSniffer\Files\File;
14+
use PHP_CodeSniffer\Util\Tokens;
15+
916
/**
1017
* A test to ensure that trailing commas are included for multi-line arrays only.
1118
*
1219
* @package DWS
1320
* @subpackage Sniffs
1421
*/
15-
final class DWS_Sniffs_Arrays_TrailingCommaSniff implements PHP_CodeSniffer_Sniff
22+
final class TrailingCommaSniff implements Sniff
1623
{
1724
/**
1825
* Returns an array of tokens this test wants to listen for.
@@ -27,30 +34,30 @@ public function register()
2734
/**
2835
* Processes this sniff, when one of its tokens is encountered.
2936
*
30-
* @param PHP_CodeSniffer_File $phpcsFile The current file being checked.
37+
* @param PHP_CodeSniffer\Files\File $phpcsFile The current file being checked.
3138
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
3239
*
3340
* @return void
3441
*/
35-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
42+
public function process(File $phpcsFile, $stackPtr)
3643
{
3744
$tokens = $phpcsFile->getTokens();
38-
$arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
39-
$arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);
45+
$arrayStart = Helpers\Bracket::bracketStart($phpcsFile, $stackPtr);
46+
$arrayEnd = Helpers\Bracket::bracketEnd($phpcsFile, $stackPtr);
4047

4148
$isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];
4249

43-
$commas = DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart);
50+
$commas = Helpers\Arrays::commaPositions($phpcsFile, $arrayStart);
4451

4552
$lastComma = array_pop($commas);
46-
$trailingComma = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false;
53+
$trailingComma = $phpcsFile->findNext(Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false;
4754

4855
if ($isSingleLine) {
4956
if ($trailingComma) {
5057
$phpcsFile->addError('No trailing comma allowed on single-line arrays', $lastComma, 'SingleLineTrailingComma');
5158
}
5259
} elseif (!$trailingComma) {
53-
$previousItem = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true);
60+
$previousItem = $phpcsFile->findPrevious(Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true);
5461
$phpcsFile->addError('Trailing comma required for multi-line arrays', $previousItem, 'MultiLineTrailingComma');
5562
}
5663
}

DWS/Sniffs/ControlStructures/ControlSignatureSniff.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
* @subpackage Sniffs
77
*/
88

9+
namespace DWS\Sniffs\ControlStructures;
10+
11+
use PHP_CodeSniffer\Sniffs\AbstractPatternSniff;
12+
913
/**
1014
* Verifies that control statements conform to their coding standards.
1115
*
1216
* @package DWS
1317
* @subpackage Sniffs
1418
*/
15-
final class DWS_Sniffs_ControlStructures_ControlSignatureSniff extends PHP_CodeSniffer_Standards_AbstractPatternSniff
19+
final class ControlSignatureSniff extends AbstractPatternSniff
1620
{
1721
/**
1822
* Initialze the parent AbstractPatternSniff to ignore comments

0 commit comments

Comments
 (0)