Skip to content

Commit 3a91f00

Browse files
authored
Merge pull request #16 from chrisryan/master
Update to support php_codesniffer version 3.
2 parents b0ec63a + def6ca4 commit 3a91f00

10 files changed

+146
-83
lines changed

Chadicus/Sniffs/Classes/UnusedUseStatementSniff.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
class Chadicus_Sniffs_Classes_UnusedUseStatementSniff implements PHP_CodeSniffer_Sniff
3+
namespace Chadicus\Sniffs\Classes;
4+
5+
use PHP_CodeSniffer\Files\File;
6+
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use PHP_CodeSniffer\Util\Tokens;
8+
9+
class UnusedUseStatementSniff implements Sniff
410
{
511

612
/**
@@ -17,13 +23,13 @@ public function register()
1723
/**
1824
* Processes this test, when one of its tokens is encountered.
1925
*
20-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
21-
* @param int $stackPtr The position of the current token in
22-
* the stack passed in $tokens.
26+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
27+
* @param int $stackPtr The position of the current token in
28+
* the stack passed in $tokens.
2329
*
2430
* @return void
2531
*/
26-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
32+
public function process(File $phpcsFile, $stackPtr)
2733
{
2834
$tokens = $phpcsFile->getTokens();
2935

@@ -39,7 +45,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3945
}
4046

4147
$classPtr = $phpcsFile->findPrevious(
42-
PHP_CodeSniffer_Tokens::$emptyTokens,
48+
Tokens::$emptyTokens,
4349
($semiColon - 1),
4450
null,
4551
true
@@ -101,7 +107,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
101107
}
102108

103109
$beforeUsage = $phpcsFile->findPrevious(
104-
PHP_CodeSniffer_Tokens::$emptyTokens,
110+
Tokens::$emptyTokens,
105111
($classUsed - 1),
106112
null,
107113
true

Chadicus/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
3+
namespace Chadicus\Sniffs\Commenting;
4+
5+
use PHP_CodeSniffer\Files\File;
6+
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use PHP_CodeSniffer\Util\Tokens;
8+
29
/**
310
* Parses and verifies the class doc comment.
411
*
@@ -12,7 +19,7 @@
1219
* <li>Disallows throws, return, var and param tags.</li>
1320
* </ul>
1421
*/
15-
final class Chadicus_Sniffs_Commenting_ClassCommentSniff implements PHP_CodeSniffer_Sniff
22+
final class ClassCommentSniff implements Sniff
1623
{
1724
public $disallowedTags = array('@throws', '@return', '@var', '@param');
1825

@@ -29,16 +36,16 @@ public function register()
2936
/**
3037
* Processes this test, when one of its tokens is encountered.
3138
*
32-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
33-
* @param int $stackPtr The position of the current token
34-
* in the stack passed in $tokens.
39+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
40+
* @param int $stackPtr The position of the current token
41+
* in the stack passed in $tokens.
3542
*
3643
* @return void
3744
*/
38-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
45+
public function process(File $phpcsFile, $stackPtr)
3946
{
4047
$tokens = $phpcsFile->getTokens();
41-
$find = PHP_CodeSniffer_Tokens::$methodPrefixes;
48+
$find = Tokens::$methodPrefixes;
4249
$find[] = T_WHITESPACE;
4350

4451
$commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);

Chadicus/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?php
22

3-
class Chadicus_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commenting_FunctionCommentSniff
3+
namespace Chadicus\Sniffs\Commenting;
4+
5+
use PHP_CodeSniffer\Config;
6+
use PHP_CodeSniffer\Files\File;
7+
use PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting\FunctionCommentSniff as PEARFunctionCommentSniff;
8+
use PHP_CodeSniffer\Util\Common;
9+
10+
class FunctionCommentSniff extends PEARFunctionCommentSniff
411
{
512
/**
613
* The current PHP version.
@@ -19,12 +26,12 @@ class Chadicus_Sniffs_Commenting_FunctionCommentSniff extends PEAR_Sniffs_Commen
1926
/**
2027
* Ensures only public methods are processed.
2128
*
22-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
23-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
29+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
30+
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
2431
*
2532
* @return void
2633
*/
27-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
34+
public function process(File $phpcsFile, $stackPtr)
2835
{
2936
$methodProperties = $phpcsFile->getMethodProperties($stackPtr);
3037
if ($methodProperties['scope'] !== 'public') {
@@ -37,14 +44,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
3744
/**
3845
* Process the return comment of this function comment.
3946
*
40-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
41-
* @param int $stackPtr The position of the current token
42-
* in the stack passed in $tokens.
43-
* @param int $commentStart The position in the stack where the comment started.
47+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
48+
* @param int $stackPtr The position of the current token
49+
* in the stack passed in $tokens.
50+
* @param int $commentStart The position in the stack where the comment started.
4451
*
4552
* @return void
4653
*/
47-
protected function processReturn(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
54+
protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
4855
{
4956
$tokens = $phpcsFile->getTokens();
5057

@@ -187,14 +194,14 @@ private function isReturnVoid($phpcsFile, $tokens, $stackPtr) : bool
187194
/**
188195
* Process any throw tags that this function comment has.
189196
*
190-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
191-
* @param int $stackPtr The position of the current token
192-
* in the stack passed in $tokens.
193-
* @param int $commentStart The position in the stack where the comment started.
197+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
198+
* @param int $stackPtr The position of the current token
199+
* in the stack passed in $tokens.
200+
* @param int $commentStart The position in the stack where the comment started.
194201
*
195202
* @return void
196203
*/
197-
protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
204+
protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
198205
{
199206
$tokens = $phpcsFile->getTokens();
200207

@@ -242,17 +249,17 @@ protected function processThrows(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
242249
/**
243250
* Process the function parameter comments.
244251
*
245-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
246-
* @param int $stackPtr The position of the current token
247-
* in the stack passed in $tokens.
248-
* @param int $commentStart The position in the stack where the comment started.
252+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
253+
* @param int $stackPtr The position of the current token
254+
* in the stack passed in $tokens.
255+
* @param int $commentStart The position in the stack where the comment started.
249256
*
250257
* @return void
251258
*/
252-
protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $commentStart)
259+
protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
253260
{
254261
if ($this->_phpVersion === null) {
255-
$this->_phpVersion = PHP_CodeSniffer::getConfigData('php_version');
262+
$this->_phpVersion = Config::getConfigData('php_version');
256263
if ($this->_phpVersion === null) {
257264
$this->_phpVersion = PHP_VERSION_ID;
258265
}
@@ -388,7 +395,7 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
388395
$suggestedTypeHint = 'callable';
389396
} else if (strpos($suggestedName, 'callback') !== false) {
390397
$suggestedTypeHint = 'callable';
391-
} else if (in_array($suggestedName, PHP_CodeSniffer::$allowedTypes) === false) {
398+
} else if (in_array($suggestedName, Common::$allowedTypes) === false) {
392399
$suggestedTypeHint = $suggestedName;
393400
}
394401

@@ -548,14 +555,14 @@ protected function processParams(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $co
548555
/**
549556
* Check the spacing after the type of a parameter.
550557
*
551-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
552-
* @param array $param The parameter to be checked.
553-
* @param int $maxType The maxlength of the longest parameter type.
554-
* @param int $spacing The number of spaces to add after the type.
558+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
559+
* @param array $param The parameter to be checked.
560+
* @param int $maxType The maxlength of the longest parameter type.
561+
* @param int $spacing The number of spaces to add after the type.
555562
*
556563
* @return void
557564
*/
558-
protected function checkSpacingAfterParamType(PHP_CodeSniffer_File $phpcsFile, $param, $maxType, $spacing = 1)
565+
protected function checkSpacingAfterParamType(File $phpcsFile, $param, $maxType, $spacing = 1)
559566
{
560567
// Check number of spaces after the type.
561568
$spaces = ($maxType - strlen($param['type']) + $spacing);
@@ -602,14 +609,14 @@ protected function checkSpacingAfterParamType(PHP_CodeSniffer_File $phpcsFile, $
602609
/**
603610
* Check the spacing after the name of a parameter.
604611
*
605-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
606-
* @param array $param The parameter to be checked.
607-
* @param int $maxVar The maxlength of the longest parameter name.
608-
* @param int $spacing The number of spaces to add after the type.
612+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
613+
* @param array $param The parameter to be checked.
614+
* @param int $maxVar The maxlength of the longest parameter name.
615+
* @param int $spacing The number of spaces to add after the type.
609616
*
610617
* @return void
611618
*/
612-
protected function checkSpacingAfterParamName(PHP_CodeSniffer_File $phpcsFile, $param, $maxVar, $spacing = 1)
619+
protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar, $spacing = 1)
613620
{
614621
// Check number of spaces after the var name.
615622
$spaces = ($maxVar - strlen($param['var']) + $spacing);

Chadicus/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?php
22

3-
final class Chadicus_Sniffs_Commenting_VariableCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff
3+
namespace Chadicus\Sniffs\Commenting;
4+
5+
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
6+
use PHP_CodeSniffer\Files\File;
7+
8+
final class VariableCommentSniff extends AbstractVariableSniff
49
{
510
/**
611
* Called to process class member vars.
712
*
8-
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
9-
* @param int $stackPtr The position of the current token
10-
* in the stack passed in $tokens.
13+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
14+
* @param int $stackPtr The position of the current token
15+
* in the stack passed in $tokens.
1116
*
1217
* @return void
1318
*/
14-
public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
19+
public function processMemberVar(File $phpcsFile, $stackPtr)
1520
{
1621
$tokens = $phpcsFile->getTokens();
1722
$ignore = array(T_PUBLIC, T_PRIVATE, T_PROTECTED, T_VAR, T_STATIC, T_WHITESPACE);
@@ -81,13 +86,13 @@ public function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
8186
*
8287
* Not required for this sniff.
8388
*
84-
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found.
85-
* @param int $stackPtr The position where the double quoted
86-
* string was found.
89+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this token was found.
90+
* @param int $stackPtr The position where the double quoted
91+
* string was found.
8792
*
8893
* @return void
8994
*/
90-
protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
95+
protected function processVariable(File $phpcsFile, $stackPtr)
9196
{
9297

9398
}
@@ -97,13 +102,13 @@ protected function processVariable(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
97102
*
98103
* Not required for this sniff.
99104
*
100-
* @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where this token was found.
101-
* @param int $stackPtr The position where the double quoted
102-
* string was found.
105+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this token was found.
106+
* @param int $stackPtr The position where the double quoted
107+
* string was found.
103108
*
104109
* @return void
105110
*/
106-
protected function processVariableInString(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
111+
protected function processVariableInString(File $phpcsFile, $stackPtr)
107112
{
108113

109114
}
Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
2+
3+
namespace Chadicus\Sniffs\ConstrolStructures;
4+
5+
use PHP_CodeSniffer\Sniffs\AbstractScopeSniff;
6+
use PHP_CodeSniffer\Files\File;
7+
28
/**
39
* Generates a warning if else or elseif control structures are used.
410
*/
5-
final class Chadicus_Sniffs_ControlStructures_ElseIfAndElseDeclarationSniff
6-
extends PHP_CodeSniffer_Standards_AbstractScopeSniff
11+
final class ElseIfAndElseDeclarationSniff extends AbstractScopeSniff
712
{
813
/**
914
* Constructs the test with the tokens it wishes to listen for.
@@ -16,18 +21,30 @@ public function __construct()
1621
/**
1722
* Processes this test, when one of its tokens is encountered.
1823
*
19-
* @param PHP_CodeSniffer_File $phpcsFile The current file being scanned.
20-
* @param int $stackPtr The position of the current token in the
21-
* stack passed in $tokens.
22-
* @param int $currScope A pointer to the start of the scope.
24+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being scanned.
25+
* @param int $stackPtr The position of the current token in the
26+
* stack passed in $tokens.
27+
* @param int $currScope A pointer to the start of the scope.
2328
*
2429
* @return void
2530
*/
26-
public function processTokenWithinScope(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $currScope)
31+
public function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
2732
{
2833
$error = 'Use of ELSE and ELSEIF is discouraged. An if expression with an else branch is never necessary. You '
2934
. 'can rewrite the conditions in a way that the else is not necessary and the code becomes simpler to '
3035
. 'read.';
3136
$phpcsFile->addWarning($error, $stackPtr, 'Discouraged');
3237
}
38+
39+
/**
40+
* Process of tokens outside of scope.
41+
*
42+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being scanned.
43+
* @param int $stackPtr The position of the current token in the
44+
* stack passed in $tokens.
45+
* @return void
46+
*/
47+
protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
48+
{
49+
}
3350
}

Chadicus/Sniffs/Methods/LongMethodSniff.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
22

3+
namespace Chadicus\Sniffs\Methods;
4+
5+
use PHP_CodeSniffer\Files\File;
6+
use PHP_CodeSniffer\Sniffs\Sniff;
7+
38
/**
49
* Issues warning with method length greater than 100 and issues error if length is greater than 200.
510
*/
6-
final class Chadicus_Sniffs_Methods_LongMethodSniff implements PHP_CodeSniffer_Sniff
11+
final class LongMethodSniff implements Sniff
712
{
813
/**
914
* Length at which a warning will be triggered.
@@ -30,12 +35,12 @@ public function register()
3035
}
3136

3237
/**
33-
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
34-
* @param intege $stackPtr The position in the stack where the token was found.
38+
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
39+
* @param intege $stackPtr The position in the stack where the token was found.
3540
*
3641
* @return void
3742
*/
38-
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
43+
public function process(File $phpcsFile, $stackPtr)
3944
{
4045
$tokens = $phpcsFile->getTokens();
4146
$token = $tokens[$stackPtr];

0 commit comments

Comments
 (0)