Skip to content

Commit 2c6cf3c

Browse files
Merge pull request #83 from VincentLanglet/unused
Lot of refactoring
2 parents 4dcf7f4 + e9e2e0e commit 2c6cf3c

File tree

96 files changed

+2144
-1929
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2144
-1929
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 246 additions & 209 deletions
Large diffs are not rendered by default.

SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,28 @@
1010
class ClassDeclarationSniff
1111
{
1212
/**
13-
* @return array
13+
* @return int[]
1414
*/
15-
public function register()
15+
public function register(): array
1616
{
17-
return [
18-
T_CLASS,
19-
T_INTERFACE,
20-
T_TRAIT,
21-
];
17+
return [T_CLASS, T_INTERFACE, T_TRAIT];
2218
}
2319

2420
/**
25-
* Processes this test, when one of its tokens is encountered.
26-
*
27-
* @param File $phpcsFile The file being scanned.
28-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
29-
*
30-
* @return void
21+
* @param File $phpcsFile
22+
* @param int $stackPtr
3123
*/
32-
public function process(File $phpcsFile, $stackPtr)
24+
public function process(File $phpcsFile, $stackPtr): void
3325
{
3426
// Just in case.
3527
$tokens = $phpcsFile->getTokens();
3628
$openingBrace = $tokens[$stackPtr]['scope_opener'];
3729

38-
if (isset($openingBrace) === false) {
30+
if (!isset($openingBrace)) {
3931
return;
4032
}
4133

42-
$nextElement = $phpcsFile->findNext([T_WHITESPACE], $openingBrace + 1, null, true);
34+
$nextElement = $phpcsFile->findNext(T_WHITESPACE, $openingBrace + 1, null, true);
4335

4436
if ($tokens[$openingBrace]['line'] + 1 < $tokens[$nextElement]['line']) {
4537
$fix = $phpcsFile->addFixableError(
@@ -48,7 +40,7 @@ public function process(File $phpcsFile, $stackPtr)
4840
'Invalid'
4941
);
5042

51-
if (true === $fix) {
43+
if ($fix) {
5244
$phpcsFile->fixer->replaceToken($openingBrace + 1, '');
5345
}
5446
}

SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,23 @@
66
use PHP_CodeSniffer\Sniffs\Sniff;
77

88
/**
9-
* Throws warnings if properties are declared after methods
9+
* Throws error if properties are declared after methods
1010
*/
1111
class PropertyDeclarationSniff implements Sniff
1212
{
1313
/**
14-
* Returns an array of tokens this test wants to listen for.
15-
*
16-
* @return array
14+
* @return int[]
1715
*/
18-
public function register()
16+
public function register(): array
1917
{
20-
return [
21-
T_CLASS,
22-
];
18+
return [T_CLASS];
2319
}
2420

2521
/**
26-
* Processes this test, when one of its tokens is encountered.
27-
*
28-
* @param File $phpcsFile The file being scanned.
29-
* @param int $stackPtr The position of the current token
30-
* in the stack passed in $tokens.
31-
*
32-
* @return void
22+
* @param File $phpcsFile
23+
* @param int $stackPtr
3324
*/
34-
public function process(File $phpcsFile, $stackPtr)
25+
public function process(File $phpcsFile, $stackPtr): void
3526
{
3627
$tokens = $phpcsFile->getTokens();
3728

@@ -40,31 +31,15 @@ public function process(File $phpcsFile, $stackPtr)
4031
$end = $tokens[$stackPtr]['scope_closer'];
4132
}
4233

43-
$scope = $phpcsFile->findNext(
44-
T_FUNCTION,
45-
$stackPtr,
46-
$end
47-
);
34+
$scope = $phpcsFile->findNext(T_FUNCTION, $stackPtr, $end);
4835

49-
$wantedTokens = [
50-
T_PUBLIC,
51-
T_PROTECTED,
52-
T_PRIVATE,
53-
];
36+
$wantedTokens = [T_PUBLIC, T_PROTECTED, T_PRIVATE];
5437

5538
while ($scope) {
56-
$scope = $phpcsFile->findNext(
57-
$wantedTokens,
58-
$scope + 1,
59-
$end
60-
);
39+
$scope = $phpcsFile->findNext($wantedTokens, $scope + 1, $end);
6140

6241
if ($scope && T_VARIABLE === $tokens[$scope + 2]['code']) {
63-
$phpcsFile->addError(
64-
'Declare class properties before methods',
65-
$scope,
66-
'Invalid'
67-
);
42+
$phpcsFile->addError('Declare class properties before methods', $scope, 'Invalid');
6843
}
6944
}
7045
}

SymfonyCustom/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
* Parses and verifies the doc comments for classes.
99
*
1010
* Verifies that :
11-
* <ul>
12-
* <li>A doc comment exists.</li>
13-
* <li>Check the order of the tags.</li>
14-
* <li>Check the indentation of each tag.</li>
15-
* <li>Check required and optional tags and the format of their content.</li>
16-
* </ul>
11+
* - A doc comment exists.
12+
* - Check the order of the tags.
13+
* - Check the indentation of each tag.
14+
* - Check required and optional tags and the format of their content.
1715
*/
1816
class ClassCommentSniff extends PEARClassCommentSniff
1917
{

SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,26 @@
1111
class DocCommentForbiddenTagsSniff implements Sniff
1212
{
1313
/**
14-
* A list of PHPDoc tags that are forbidden.
15-
*
1614
* @var array
1715
*/
18-
public $tags = [
19-
'@package',
20-
'@subpackage',
21-
];
16+
public $forbiddenTags = ['@package', '@subpackage'];
2217

2318
/**
24-
* A list of tokenizers this sniff supports.
25-
*
2619
* @return array
2720
*/
28-
public function register()
21+
public function register(): array
2922
{
30-
return [
31-
T_DOC_COMMENT_TAG,
32-
];
23+
return [T_DOC_COMMENT_TAG];
3324
}
3425

3526
/**
36-
* Processes this test, when one of its tokens is encountered.
37-
*
38-
* @param File $phpcsFile All the tokens found in the document.
39-
* @param int $stackPtr The position of the current token in
40-
* the stack passed in $tokens.
41-
*
42-
* @return void
27+
* @param File $phpcsFile
28+
* @param int $stackPtr
4329
*/
44-
public function process(File $phpcsFile, $stackPtr)
30+
public function process(File $phpcsFile, $stackPtr): void
4531
{
4632
$tokens = $phpcsFile->getTokens();
47-
if (in_array($tokens[$stackPtr]['content'], $this->tags)) {
33+
if (in_array($tokens[$stackPtr]['content'], $this->forbiddenTags)) {
4834
$phpcsFile->addError(
4935
'The %s annotation is forbidden to use',
5036
$stackPtr,

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,26 @@
44

55
use PHP_CodeSniffer\Files\File;
66
use PHP_CodeSniffer\Sniffs\Sniff;
7+
use SymfonyCustom\Sniffs\SniffHelper;
78

89
/**
910
* Throws errors if comments are not grouped by type with one blank line between them.
1011
*/
1112
class DocCommentGroupSameTypeSniff implements Sniff
1213
{
1314
/**
14-
* A list of PHPDoc tags that are checked.
15-
*
16-
* @var array
17-
*/
18-
public $tags = [
19-
'@api',
20-
'@author',
21-
'@category',
22-
'@copyright',
23-
'@covers',
24-
'@dataProvider',
25-
'@deprecated',
26-
'@example',
27-
'@filesource',
28-
'@global',
29-
'@ignore',
30-
'@internal',
31-
'@license',
32-
'@link',
33-
'@method',
34-
'@package',
35-
'@param',
36-
'@property',
37-
'@property-read',
38-
'@property-write',
39-
'@required',
40-
'@return',
41-
'@see',
42-
'@since',
43-
'@source',
44-
'@subpackage',
45-
'@throws',
46-
'@todo',
47-
'@uses',
48-
'@var',
49-
'@version',
50-
];
51-
52-
/**
53-
* A list of tokenizers this sniff supports.
54-
*
5515
* @return array
5616
*/
57-
public function register()
17+
public function register(): array
5818
{
59-
return [
60-
T_DOC_COMMENT_OPEN_TAG,
61-
];
19+
return [T_DOC_COMMENT_OPEN_TAG];
6220
}
6321

6422
/**
65-
* Processes this test, when one of its tokens is encountered.
66-
*
67-
* @param File $phpcsFile All the tokens found in the document.
68-
* @param int $stackPtr The position of the current token in the stack passed in $tokens.
69-
*
70-
* @return void
23+
* @param File $phpcsFile
24+
* @param int $stackPtr
7125
*/
72-
public function process(File $phpcsFile, $stackPtr)
26+
public function process(File $phpcsFile, $stackPtr): void
7327
{
7428
$tokens = $phpcsFile->getTokens();
7529

@@ -106,8 +60,9 @@ public function process(File $phpcsFile, $stackPtr)
10660
}
10761

10862
if (isset($previousElement) && $previousLine >= 0) {
109-
$currentIsCustom = !in_array($currentType, $this->tags);
110-
$previousIsCustom = ('' !== $previousType) && !in_array($previousType, $this->tags);
63+
$currentIsCustom = !in_array($currentType, SniffHelper::TAGS);
64+
$previousIsCustom = '' !== $previousType
65+
&& !in_array($previousType, SniffHelper::TAGS);
11166

11267
if (($previousType === $currentType) || ($currentIsCustom && $previousIsCustom)) {
11368
if ($previousLine !== $commentTagLine - 1) {
@@ -125,7 +80,7 @@ public function process(File $phpcsFile, $stackPtr)
12580
);
12681
}
12782

128-
if (true === $fix) {
83+
if ($fix) {
12984
$phpcsFile->fixer->beginChangeset();
13085
$this->removeLines(
13186
$phpcsFile,
@@ -144,7 +99,7 @@ public function process(File $phpcsFile, $stackPtr)
14499
'DifferentType'
145100
);
146101

147-
if (true === $fix) {
102+
if ($fix) {
148103
$phpcsFile->fixer->beginChangeset();
149104

150105
if ($previousLine === $commentTagLine - 1) {
@@ -184,18 +139,12 @@ public function process(File $phpcsFile, $stackPtr)
184139
}
185140

186141
/**
187-
* Remove all tokens on lines (inclusively).
188-
*
189-
* Note: this method does not start or end changeset.
190-
*
191-
* @param File $phpcsFile File to make changes in
192-
* @param int $fromPtr Start searching tokens from here
193-
* @param int $fromLine First line to delete tokens from
194-
* @param int $toLine Last line to delete tokens from
195-
*
196-
* @return void
142+
* @param File $phpcsFile
143+
* @param int $fromPtr
144+
* @param int $fromLine
145+
* @param int $toLine
197146
*/
198-
protected function removeLines(File $phpcsFile, $fromPtr, $fromLine, $toLine)
147+
private function removeLines(File $phpcsFile, int $fromPtr, int $fromLine, int $toLine): void
199148
{
200149
$tokens = $phpcsFile->getTokens();
201150

0 commit comments

Comments
 (0)