Skip to content

Commit ea9a896

Browse files
✨ Require @return void
1 parent f03f804 commit ea9a896

Some content is hidden

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

52 files changed

+287
-91
lines changed

SymfonyCustom/Helpers/AbstractHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
*/
1010
abstract class AbstractHelper
1111
{
12+
/**
13+
* @return void
14+
*/
1215
private function __construct()
1316
{
1417
}

SymfonyCustom/Helpers/FixerHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class FixerHelper extends AbstractHelper
1515
* @param File $phpcsFile
1616
* @param int $fromPtr
1717
* @param int $toPtr
18+
*
19+
* @return void
1820
*/
1921
public static function removeAll(File $phpcsFile, int $fromPtr, int $toPtr): void
2022
{
@@ -37,6 +39,8 @@ public static function removeAll(File $phpcsFile, int $fromPtr, int $toPtr): voi
3739
* @param int $fromPtr
3840
* @param int $fromLine
3941
* @param int $toLine
42+
*
43+
* @return void
4044
*/
4145
public static function removeLines(File $phpcsFile, int $fromPtr, int $fromLine, int $toLine): void
4246
{
@@ -61,6 +65,8 @@ public static function removeLines(File $phpcsFile, int $fromPtr, int $fromLine,
6165
* @param int $stackPtr
6266
* @param int $expected
6367
* @param int|string $found
68+
*
69+
* @return void
6470
*/
6571
public static function fixWhitespaceAfter(
6672
File $phpcsFile,
@@ -92,6 +98,8 @@ public static function fixWhitespaceAfter(
9298
* @param int $stackPtr
9399
* @param int $expected
94100
* @param int|string $found
101+
*
102+
* @return void
95103
*/
96104
public static function fixWhitespaceBefore(
97105
File $phpcsFile,

SymfonyCustom/Sniffs/Arrays/ArrayDeclarationSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public function register(): array
2828
}
2929

3030
/**
31-
* @param File $phpcsFile The current file being checked.
31+
* @param File $phpcsFile
3232
* @param int $stackPtr
33+
*
34+
* @return void
3335
*/
3436
public function process(File $phpcsFile, $stackPtr): void
3537
{
@@ -92,6 +94,8 @@ public function process(File $phpcsFile, $stackPtr): void
9294
* @param int $stackPtr
9395
* @param int $start
9496
* @param int $end
97+
*
98+
* @return void
9599
*/
96100
public function processSingleLineArray(File $phpcsFile, int $stackPtr, int $start, int $end): void
97101
{
@@ -216,6 +220,8 @@ public function processSingleLineArray(File $phpcsFile, int $stackPtr, int $star
216220
* @param int $stackPtr
217221
* @param int $start
218222
* @param int $end
223+
*
224+
* @return void
219225
*/
220226
public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $start, int $end): void
221227
{

SymfonyCustom/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function register(): array
2222
/**
2323
* @param File $phpcsFile
2424
* @param int $stackPtr
25+
*
26+
* @return void
2527
*/
2628
public function process(File $phpcsFile, $stackPtr): void
2729
{

SymfonyCustom/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function register(): array
2323
/**
2424
* @param File $phpcsFile
2525
* @param int $stackPtr
26+
*
27+
* @return void
2628
*/
2729
public function process(File $phpcsFile, $stackPtr): void
2830
{

SymfonyCustom/Sniffs/Commenting/DocCommentForbiddenTagsSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function register(): array
2828
/**
2929
* @param File $phpcsFile
3030
* @param int $stackPtr
31+
*
32+
* @return void
3133
*/
3234
public function process(File $phpcsFile, $stackPtr): void
3335
{

SymfonyCustom/Sniffs/Commenting/DocCommentGroupSameTypeSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function register(): array
2525
/**
2626
* @param File $phpcsFile
2727
* @param int $stackPtr
28+
*
29+
* @return void
2830
*/
2931
public function process(File $phpcsFile, $stackPtr): void
3032
{

SymfonyCustom/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function register(): array
2424
/**
2525
* @param File $phpcsFile
2626
* @param int $stackPtr
27+
*
28+
* @return void
2729
*/
2830
public function process(File $phpcsFile, $stackPtr): void
2931
{

SymfonyCustom/Sniffs/Commenting/FunctionCommentSniff.php

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class FunctionCommentSniff extends PEARFunctionCommentSniff
1616
/**
1717
* @param File $phpcsFile
1818
* @param int $stackPtr
19+
*
20+
* @return void
1921
*/
2022
public function process(File $phpcsFile, $stackPtr): void
2123
{
@@ -68,10 +70,7 @@ public function process(File $phpcsFile, $stackPtr): void
6870
}
6971
} else {
7072
// No comment but maybe a method prefix
71-
$methodPrefixes = $phpcsFile->findFirstOnLine(
72-
Tokens::$methodPrefixes,
73-
$stackPtr
74-
);
73+
$methodPrefixes = $phpcsFile->findFirstOnLine(Tokens::$methodPrefixes, $stackPtr);
7574

7675
if (false !== $methodPrefixes) {
7776
$commentStart = $methodPrefixes;
@@ -107,58 +106,56 @@ public function process(File $phpcsFile, $stackPtr): void
107106
* @param int $stackPtr
108107
* @param int|null $commentStart
109108
* @param bool $hasComment
109+
*
110+
* @return void
110111
*/
111112
protected function processReturn(File $phpcsFile, $stackPtr, $commentStart, $hasComment = true): void
112113
{
113-
// Check for inheritDoc if there is comment
114-
if ($hasComment && $this->isInheritDoc($phpcsFile, $stackPtr)) {
114+
if (!$hasComment) {
115+
$phpcsFile->addError('Missing @return tag in function comment', $stackPtr, 'MissingReturn');
116+
117+
return;
118+
}
119+
120+
// Check for inheritDoc
121+
if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
115122
return;
116123
}
117124

118125
$tokens = $phpcsFile->getTokens();
119126

120-
// Only check for a return comment if a non-void return statement exists
121-
if (isset($tokens[$stackPtr]['scope_opener'])) {
122-
// Start inside the function
123-
$start = $phpcsFile->findNext(
124-
T_OPEN_CURLY_BRACKET,
125-
$stackPtr,
126-
$tokens[$stackPtr]['scope_closer']
127-
);
128-
129-
for ($i = $start; $i < $tokens[$stackPtr]['scope_closer']; ++$i) {
130-
// Skip closures
131-
if (T_CLOSURE === $tokens[$i]['code']) {
132-
$i = $tokens[$i]['scope_closer'];
133-
continue;
127+
$return = null;
128+
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
129+
if ('@return' === $tokens[$tag]['content']) {
130+
if (null !== $return) {
131+
$error = 'Only 1 @return tag is allowed in a function comment';
132+
$phpcsFile->addError($error, $tag, 'DuplicateReturn');
133+
134+
return;
134135
}
135136

136-
// Found a return not in a closure statement
137-
// Run the check on the first which is not only 'return;'
138-
if (T_RETURN === $tokens[$i]['code']
139-
&& $this->isMatchingReturn($tokens, $i)
140-
) {
141-
if ($hasComment) {
142-
parent::processReturn($phpcsFile, $stackPtr, $commentStart);
143-
} else {
144-
// There is no doc and we need one with @return
145-
$phpcsFile->addError(
146-
'Missing @return tag in function comment',
147-
$stackPtr,
148-
'MissingReturn'
149-
);
150-
}
137+
$return = $tag;
138+
}
139+
}
151140

152-
break;
153-
}
141+
if (null !== $return) {
142+
$content = $tokens[($return + 2)]['content'];
143+
if (!$content || T_DOC_COMMENT_STRING !== $tokens[($return + 2)]['code']) {
144+
$error = 'Return type missing for @return tag in function comment';
145+
$phpcsFile->addError($error, $return, 'MissingReturnType');
154146
}
147+
} else {
148+
$error = 'Missing @return tag in function comment';
149+
$phpcsFile->addError($error, $tokens[$commentStart]['comment_closer'], 'MissingReturn');
155150
}
156151
}
157152

158153
/**
159154
* @param File $phpcsFile
160155
* @param int $stackPtr
161156
* @param int $commentStart
157+
*
158+
* @return void
162159
*/
163160
protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): void
164161
{
@@ -181,28 +178,15 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi
181178
}
182179
}
183180

184-
if (null !== $throw) {
185-
$exception = null;
186-
if (T_DOC_COMMENT_STRING === $tokens[$throw + 2]['code']) {
187-
$matches = [];
188-
preg_match('/([^\s]+)(?:\s+(.*))?/', $tokens[$throw + 2]['content'], $matches);
189-
$exception = $matches[1];
190-
}
191-
192-
if (null === $exception) {
193-
$phpcsFile->addError(
194-
'Exception type missing for @throws tag in function comment',
195-
$throw,
196-
'InvalidThrows'
197-
);
198-
}
199-
}
181+
parent::processThrows($phpcsFile, $stackPtr, $commentStart);
200182
}
201183

202184
/**
203185
* @param File $phpcsFile
204186
* @param int $stackPtr
205187
* @param int $commentStart
188+
*
189+
* @return void
206190
*/
207191
protected function processParams(File $phpcsFile, $stackPtr, $commentStart): void
208192
{
@@ -226,21 +210,6 @@ private function isInheritDoc(File $phpcsFile, int $stackPtr): bool
226210

227211
$content = $phpcsFile->getTokensAsString($start, ($end - $start));
228212

229-
return preg_match('#{@inheritdoc}#i', $content) === 1;
230-
}
231-
232-
/**
233-
* @param array $tokens
234-
* @param int $returnPos
235-
*
236-
* @return bool
237-
*/
238-
private function isMatchingReturn(array $tokens, int $returnPos): bool
239-
{
240-
do {
241-
$returnPos++;
242-
} while (T_WHITESPACE === $tokens[$returnPos]['code']);
243-
244-
return T_SEMICOLON !== $tokens[$returnPos]['code'];
213+
return preg_match('#@inheritdoc|{@inheritdoc}#i', $content) === 1;
245214
}
246215
}

SymfonyCustom/Sniffs/Commenting/VariableCommentSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class VariableCommentSniff extends AbstractVariableSniff
1515
/**
1616
* @param File $phpcsFile
1717
* @param int $stackPtr
18+
*
19+
* @return void
1820
*/
1921
public function processMemberVar(File $phpcsFile, $stackPtr): void
2022
{
@@ -115,6 +117,8 @@ public function processMemberVar(File $phpcsFile, $stackPtr): void
115117
/**
116118
* @param File $phpcsFile
117119
* @param int $stackPtr
120+
*
121+
* @return void
118122
*/
119123
protected function processVariable(File $phpcsFile, $stackPtr): void
120124
{
@@ -123,6 +127,8 @@ protected function processVariable(File $phpcsFile, $stackPtr): void
123127
/**
124128
* @param File $phpcsFile
125129
* @param int $stackPtr
130+
*
131+
* @return void
126132
*/
127133
protected function processVariableInString(File $phpcsFile, $stackPtr): void
128134
{

SymfonyCustom/Sniffs/Errors/ExceptionMessageSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function register(): array
2323
/**
2424
* @param File $phpcsFile
2525
* @param int $stackPtr
26+
*
27+
* @return void
2628
*/
2729
public function process(File $phpcsFile, $stackPtr): void
2830
{

SymfonyCustom/Sniffs/Errors/UserDeprecatedSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function register(): array
2323
/**
2424
* @param File $phpcsFile
2525
* @param int $stackPtr
26+
*
27+
* @return void
2628
*/
2729
public function process(File $phpcsFile, $stackPtr): void
2830
{

SymfonyCustom/Sniffs/Formatting/BlankLineBeforeReturnSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function register(): array
2424
/**
2525
* @param File $phpcsFile
2626
* @param int $stackPtr
27+
*
28+
* @return void
2729
*/
2830
public function process(File $phpcsFile, $stackPtr): void
2931
{

SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function register(): array
2323
/**
2424
* @param File $phpcsFile
2525
* @param int $stackPtr
26+
*
27+
* @return void
2628
*/
2729
public function process(File $phpcsFile, $stackPtr): void
2830
{

SymfonyCustom/Sniffs/Formatting/StrictComparisonSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public function register(): array
3333
/**
3434
* @param File $phpcsFile
3535
* @param int $stackPtr
36+
*
37+
* @return void
3638
*/
3739
public function process(File $phpcsFile, $stackPtr): void
3840
{

SymfonyCustom/Sniffs/Formatting/YodaConditionSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public function register(): array
2424
/**
2525
* @param File $phpcsFile
2626
* @param int $stackPtr
27+
*
28+
* @return void
2729
*/
2830
public function process(File $phpcsFile, $stackPtr): void
2931
{

SymfonyCustom/Sniffs/Functions/ScopeOrderSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function register(): array
2828
/**
2929
* @param File $phpcsFile
3030
* @param int $stackPtr
31+
*
32+
* @return void
3133
*/
3234
public function process(File $phpcsFile, $stackPtr): void
3335
{

SymfonyCustom/Sniffs/Namespaces/UnusedUseSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function register(): array
2525
/**
2626
* @param File $phpcsFile
2727
* @param int $stackPtr
28+
*
29+
* @return void
2830
*/
2931
public function process(File $phpcsFile, $stackPtr): void
3032
{
@@ -180,6 +182,8 @@ public function process(File $phpcsFile, $stackPtr): void
180182
* @param File $phpcsFile
181183
* @param int $from
182184
* @param int $to
185+
*
186+
* @return void
183187
*/
184188
private function removeUse(File $phpcsFile, int $from, int $to): void
185189
{

0 commit comments

Comments
 (0)