Skip to content

Commit c87db5f

Browse files
💄 Clean
1 parent 47e36ce commit c87db5f

24 files changed

+389
-351
lines changed

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 154 additions & 85 deletions
Large diffs are not rendered by default.

SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
{
@@ -31,31 +31,15 @@ public function process(File $phpcsFile, $stackPtr): void
3131
$end = $tokens[$stackPtr]['scope_closer'];
3232
}
3333

34-
$scope = $phpcsFile->findNext(
35-
T_FUNCTION,
36-
$stackPtr,
37-
$end
38-
);
34+
$scope = $phpcsFile->findNext(T_FUNCTION, $stackPtr, $end);
3935

40-
$wantedTokens = [
41-
T_PUBLIC,
42-
T_PROTECTED,
43-
T_PRIVATE,
44-
];
36+
$wantedTokens = [T_PUBLIC, T_PROTECTED, T_PRIVATE];
4537

4638
while ($scope) {
47-
$scope = $phpcsFile->findNext(
48-
$wantedTokens,
49-
$scope + 1,
50-
$end
51-
);
39+
$scope = $phpcsFile->findNext($wantedTokens, $scope + 1, $end);
5240

5341
if ($scope && T_VARIABLE === $tokens[$scope + 2]['code']) {
54-
$phpcsFile->addError(
55-
'Declare class properties before methods',
56-
$scope,
57-
'Invalid'
58-
);
42+
$phpcsFile->addError('Declare class properties before methods', $scope, 'Invalid');
5943
}
6044
}
6145
}

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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
class DocCommentForbiddenTagsSniff implements Sniff
1212
{
1313
/**
14-
* A list of PHPDoc tags that are forbidden.
15-
*
1614
* @var array
1715
*/
1816
public $forbiddenTags = ['@package', '@subpackage'];
1917

2018
/**
21-
* A list of tokenizers this sniff supports.
22-
*
2319
* @return array
2420
*/
2521
public function register(): array

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,6 @@
1212
class DocCommentGroupSameTypeSniff implements Sniff
1313
{
1414
/**
15-
* A list of PHPDoc tags that are checked.
16-
*
17-
* @var array
18-
*/
19-
public $tags = [
20-
'@api',
21-
'@author',
22-
'@category',
23-
'@copyright',
24-
'@covers',
25-
'@dataProvider',
26-
'@deprecated',
27-
'@example',
28-
'@filesource',
29-
'@global',
30-
'@ignore',
31-
'@internal',
32-
'@license',
33-
'@link',
34-
'@method',
35-
'@package',
36-
'@param',
37-
'@property',
38-
'@property-read',
39-
'@property-write',
40-
'@required',
41-
'@return',
42-
'@see',
43-
'@since',
44-
'@source',
45-
'@subpackage',
46-
'@throws',
47-
'@todo',
48-
'@uses',
49-
'@var',
50-
'@version',
51-
];
52-
53-
/**
54-
* A list of tokenizers this sniff supports.
55-
*
5615
* @return array
5716
*/
5817
public function register(): array
@@ -101,8 +60,9 @@ public function process(File $phpcsFile, $stackPtr): void
10160
}
10261

10362
if (isset($previousElement) && $previousLine >= 0) {
104-
$currentIsCustom = !in_array($currentType, $this->tags);
105-
$previousIsCustom = ('' !== $previousType) && !in_array($previousType, $this->tags);
63+
$currentIsCustom = !in_array($currentType, SniffHelper::TAGS);
64+
$previousIsCustom = '' !== $previousType
65+
&& !in_array($previousType, SniffHelper::TAGS);
10666

10767
if (($previousType === $currentType) || ($currentIsCustom && $previousIsCustom)) {
10868
if ($previousLine !== $commentTagLine - 1) {
@@ -179,9 +139,6 @@ public function process(File $phpcsFile, $stackPtr): void
179139
}
180140

181141
/**
182-
* Remove all tokens on lines (inclusively).
183-
* This method does not start or end changeset.
184-
*
185142
* @param File $phpcsFile
186143
* @param int $fromPtr
187144
* @param int $fromLine

SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,10 @@ public function process(File $phpcsFile, $stackPtr): void
4444
$short = $phpcsFile->findNext($empty, ($stackPtr + 1), $commentEnd, true);
4545
if (false === $short) {
4646
// No content at all.
47-
$error = 'Doc comment is empty';
48-
4947
$next = $phpcsFile->findNext(T_WHITESPACE, $commentEnd + 1, null, true);
5048
$hasSameLineNext = $next && $tokens[$next]['line'] === $tokens[$commentEnd]['line'];
51-
$previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
52-
$hasSameLinePrevious = $tokens[$previous]['line'] === $tokens[$stackPtr]['line'];
5349

54-
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
50+
$fix = $phpcsFile->addFixableError('Doc comment is empty', $stackPtr, 'Empty');
5551

5652
if ($fix) {
5753
$phpcsFile->fixer->beginChangeset();
@@ -83,8 +79,12 @@ public function process(File $phpcsFile, $stackPtr): void
8379

8480
// The first line of the comment should just be the /** code.
8581
if (!$isSingleLine && $tokens[$short]['line'] === $tokens[$stackPtr]['line']) {
86-
$error = 'The open comment tag must be the only content on the line';
87-
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
82+
$fix = $phpcsFile->addFixableError(
83+
'The open comment tag must be the only content on the line',
84+
$stackPtr,
85+
'ContentAfterOpen'
86+
);
87+
8888
if ($fix) {
8989
$phpcsFile->fixer->beginChangeset();
9090
for ($i = ($stackPtr + 1); $i < $short; $i++) {
@@ -105,8 +105,12 @@ public function process(File $phpcsFile, $stackPtr): void
105105

106106
// Check for additional blank lines at the beginning of the comment.
107107
if ($tokens[$stackPtr]['line'] < ($tokens[$short]['line'] - 1)) {
108-
$error = 'Additional blank lines found at beginning of doc comment';
109-
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBefore');
108+
$fix = $phpcsFile->addFixableError(
109+
'Additional blank lines found at beginning of doc comment',
110+
$stackPtr,
111+
'SpacingBefore'
112+
);
113+
110114
if ($fix) {
111115
$phpcsFile->fixer->beginChangeset();
112116
for ($i = ($stackPtr + 1); $i < $short; $i++) {
@@ -124,8 +128,12 @@ public function process(File $phpcsFile, $stackPtr): void
124128
// The last line of the comment should just be the */ code.
125129
$prev = $phpcsFile->findPrevious($empty, ($commentEnd - 1), $stackPtr, true);
126130
if (!$isSingleLine && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
127-
$error = 'The close comment tag must be the only content on the line';
128-
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'ContentBeforeClose');
131+
$fix = $phpcsFile->addFixableError(
132+
'The close comment tag must be the only content on the line',
133+
$commentEnd,
134+
'ContentBeforeClose'
135+
);
136+
129137
if ($fix) {
130138
$phpcsFile->fixer->beginChangeset();
131139
for ($i = ($prev + 1); $i < $commentEnd; $i++) {
@@ -146,8 +154,12 @@ public function process(File $phpcsFile, $stackPtr): void
146154

147155
// Check for additional blank lines at the end of the comment.
148156
if ($tokens[$prev]['line'] < ($tokens[$commentEnd]['line'] - 1)) {
149-
$error = 'Additional blank lines found at end of doc comment';
150-
$fix = $phpcsFile->addFixableError($error, $commentEnd, 'SpacingAfter');
157+
$fix = $phpcsFile->addFixableError(
158+
'Additional blank lines found at end of doc comment',
159+
$commentEnd,
160+
'SpacingAfter'
161+
);
162+
151163
if ($fix) {
152164
$phpcsFile->fixer->beginChangeset();
153165
for ($i = ($prev + 1); $i < $commentEnd; $i++) {

SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ public function process(File $phpcsFile, $stackPtr): void
4747
}
4848

4949
if (($tokens[$stackPtr]['line'] - 1) !== $tokens[$commentEnd]['line']) {
50-
$error = 'There must be no blank lines after the function comment';
51-
$phpcsFile->addError($error, $commentEnd, 'SpacingAfter');
50+
$phpcsFile->addError(
51+
'There must be no blank lines after the function comment',
52+
$commentEnd,
53+
'SpacingAfter'
54+
);
5255
}
5356

5457
$commentStart = $tokens[$commentEnd]['comment_opener'];
@@ -57,8 +60,7 @@ public function process(File $phpcsFile, $stackPtr): void
5760
// Make sure the tag isn't empty.
5861
$string = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $tag, $commentEnd);
5962
if (false === $string || $tokens[$string]['line'] !== $tokens[$tag]['line']) {
60-
$error = 'Content missing for @see tag in function comment';
61-
$phpcsFile->addError($error, $tag, 'EmptySees');
63+
$phpcsFile->addError('Content missing for @see tag in function comment', $tag, 'EmptySees');
6264
}
6365
}
6466
}
@@ -87,9 +89,12 @@ public function process(File $phpcsFile, $stackPtr): void
8789
} else {
8890
if (count($realParams) > 0) {
8991
foreach ($realParams as $neededParam) {
90-
$error = 'Doc comment for parameter "%s" missing';
91-
$data = [$neededParam['name']];
92-
$phpcsFile->addError($error, $stackPtr, 'MissingParamTag', $data);
92+
$phpcsFile->addError(
93+
'Doc comment for parameter "%s" missing',
94+
$stackPtr,
95+
'MissingParamTag',
96+
[$neededParam['name']]
97+
);
9398
}
9499
}
95100
}
@@ -137,8 +142,11 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart, $has
137142
parent::processReturn($phpcsFile, $stackPtr, $commentStart);
138143
} else {
139144
// There is no doc and we need one with @return
140-
$error = 'Missing @return tag in function comment';
141-
$phpcsFile->addError($error, $stackPtr, 'MissingReturn');
145+
$phpcsFile->addError(
146+
'Missing @return tag in function comment',
147+
$stackPtr,
148+
'MissingReturn'
149+
);
142150
}
143151

144152
break;
@@ -160,8 +168,11 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi
160168
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
161169
if ('@throws' === $tokens[$tag]['content']) {
162170
if (null !== $throw) {
163-
$error = 'Only 1 @throws tag is allowed in a function comment';
164-
$phpcsFile->addError($error, $tag, 'DuplicateThrow');
171+
$phpcsFile->addError(
172+
'Only 1 @throws tag is allowed in a function comment',
173+
$tag,
174+
'DuplicateThrow'
175+
);
165176

166177
return;
167178
}
@@ -179,8 +190,11 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi
179190
}
180191

181192
if (null === $exception) {
182-
$error = 'Exception type missing for @throws tag in function comment';
183-
$phpcsFile->addError($error, $throw, 'InvalidThrows');
193+
$phpcsFile->addError(
194+
'Exception type missing for @throws tag in function comment',
195+
$throw,
196+
'InvalidThrows'
197+
);
184198
}
185199
}
186200
}
@@ -215,7 +229,7 @@ private function processWhitespace(File $phpcsFile, int $commentStart, bool $has
215229
$found = $startLine - $prevLine - 1;
216230

217231
// Skip for class opening
218-
if ($found < 1 && 'T_OPEN_CURLY_BRACKET' !== $tokens[$before]['type']) {
232+
if ($found < 1 && T_OPEN_CURLY_BRACKET !== $tokens[$before]['code']) {
219233
if ($found < 0) {
220234
$found = 0;
221235
}
@@ -228,8 +242,7 @@ private function processWhitespace(File $phpcsFile, int $commentStart, bool $has
228242
$rule = 'SpacingBeforeFunction';
229243
}
230244

231-
$data = [$found];
232-
$fix = $phpcsFile->addFixableError($error, $commentStart, $rule, $data);
245+
$fix = $phpcsFile->addFixableError($error, $commentStart, $rule, [$found]);
233246

234247
if ($fix) {
235248
if ($found > 1) {

0 commit comments

Comments
 (0)