Skip to content

Commit c0d69ba

Browse files
✨ Require @return void
1 parent bd6a6e1 commit c0d69ba

Some content is hidden

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

44 files changed

+243
-99
lines changed

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: 19 additions & 75 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,31 @@ 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+
115117
return;
116118
}
117119

118-
$tokens = $phpcsFile->getTokens();
119-
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;
134-
}
135-
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-
}
151-
152-
break;
153-
}
154-
}
120+
// Check for inheritDoc
121+
if ($this->isInheritDoc($phpcsFile, $stackPtr)) {
122+
return;
155123
}
124+
125+
parent::processReturn($phpcsFile, $stackPtr, $commentStart);
156126
}
157127

158128
/**
159129
* @param File $phpcsFile
160130
* @param int $stackPtr
161131
* @param int $commentStart
132+
*
133+
* @return void
162134
*/
163135
protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): void
164136
{
@@ -181,28 +153,15 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart): voi
181153
}
182154
}
183155

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-
}
156+
parent::processThrows($phpcsFile, $stackPtr, $commentStart);
200157
}
201158

202159
/**
203160
* @param File $phpcsFile
204161
* @param int $stackPtr
205162
* @param int $commentStart
163+
*
164+
* @return void
206165
*/
207166
protected function processParams(File $phpcsFile, $stackPtr, $commentStart): void
208167
{
@@ -226,21 +185,6 @@ private function isInheritDoc(File $phpcsFile, int $stackPtr): bool
226185

227186
$content = $phpcsFile->getTokensAsString($start, ($end - $start));
228187

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'];
188+
return preg_match('#@inheritdoc|{@inheritdoc}#i', $content) === 1;
245189
}
246190
}

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
{

SymfonyCustom/Sniffs/NamingConventions/ValidClassNameSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public function register()
2828
/**
2929
* @param File $phpcsFile
3030
* @param int $stackPtr
31+
*
32+
* @return void
3133
*/
3234
public function process(File $phpcsFile, $stackPtr): void
3335
{
@@ -84,6 +86,8 @@ public function process(File $phpcsFile, $stackPtr): void
8486
* @param int $stackPtr
8587
* @param int|bool $name
8688
* @param string $prefix
89+
*
90+
* @return void
8791
*/
8892
private function checkPrefix(File $phpcsFile, int $stackPtr, $name, string $prefix): void
8993
{
@@ -103,6 +107,8 @@ private function checkPrefix(File $phpcsFile, int $stackPtr, $name, string $pref
103107
* @param int $stackPtr
104108
* @param int|bool $name
105109
* @param string $suffix
110+
*
111+
* @return void
106112
*/
107113
private function checkSuffix(File $phpcsFile, int $stackPtr, $name, string $suffix): void
108114
{

0 commit comments

Comments
 (0)