Skip to content

Commit

Permalink
Merge branch 'hotfix/20'
Browse files Browse the repository at this point in the history
Close #20
  • Loading branch information
michalbundyra committed May 15, 2019
2 parents 11435cb + 79bd180 commit 75affdf
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 48 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ All notable changes to this project will be documented in this file, in reverse

- [#19](https://github.com/webimpress/coding-standard/pull/19) `Commenting\DocComment` - fixes issue with doc-block after colon (for example in switch statement) - empty line is no longer required before doc-block in that case

- [#20](https://github.com/webimpress/coding-standard/pull/20) `Functions\ReturnType` - fixes false-positive error when function may return `$this`

## 1.0.2 - 2019-05-12

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
use const T_OPEN_PARENTHESIS;
use const T_OPEN_SHORT_ARRAY;
use const T_OPEN_SQUARE_BRACKET;
use const T_PARENT;
use const T_RETURN;
use const T_SELF;
use const T_SEMICOLON;
Expand Down Expand Up @@ -547,14 +546,11 @@ private function processReturnStatements(File $phpcsFile, int $stackPtr) : void
T_SELF,
T_STATIC,
T_STRING_CAST,
T_PARENT,
], true);

if ($isThis
&& $tokens[$next]['code'] === T_VARIABLE
&& (strtolower($tokens[$next]['content']) !== '$this'
|| (($next = $phpcsFile->findNext(Tokens::$emptyTokens, $next + 1, null, true))
&& $tokens[$next]['code'] !== T_SEMICOLON))
&& strtolower($tokens[$next]['content']) !== '$this'
) {
$isThis = false;
}
Expand Down Expand Up @@ -595,7 +591,7 @@ private function processReturnStatements(File $phpcsFile, int $stackPtr) : void
if ($matches = array_udiff(
preg_grep('/[^\]]$/', $this->returnDocTypes),
['null', 'array', 'iterable'],
function ($a, $b) {
static function (string $a, string $b) {
return strcasecmp($a, $b);
}
)) {
Expand Down
3 changes: 2 additions & 1 deletion test/Sniffs/Functions/ReturnTypeUnitTest.2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ abstract class FunctionCommentReturn
return self::CONST;
return static::method();
return (string) $a;
return parent::method();
return true;
return $a;
return parent::method();
return $this->method();
return $this;
}

Expand Down
3 changes: 2 additions & 1 deletion test/Sniffs/Functions/ReturnTypeUnitTest.2.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ abstract class FunctionCommentReturn
return self::CONST;
return static::method();
return (string) $a;
return parent::method();
return true;
return $a;
return parent::method();
return $this->method();
return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions test/Sniffs/Functions/ReturnTypeUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,20 @@ abstract class FunctionCommentReturn
* @return null[]
*/
abstract public function returnNullArray();

/**
* @return $this
*/
public function thisParent() : self
{
return parent::thisParent();
}

/**
* @return $this
*/
public function thisOther() : self
{
return $this->thisParent();
}
}
79 changes: 39 additions & 40 deletions test/Sniffs/Functions/ReturnTypeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,45 @@ protected function getErrorList(string $testFile = '') : array
63 => 1,
64 => 1,
65 => 1,
66 => 1,
70 => 1,
77 => 1,
84 => 1,
96 => 1,
104 => 1,
112 => 1,
116 => 1,
124 => 1,
132 => 1,
176 => 1,
184 => 1,
188 => 1,
192 => 1,
196 => 1,
200 => 1,
204 => 1,
213 => 1,
216 => 1,
265 => 1,
272 => 1,
276 => 1,
280 => 1,
284 => 1,
296 => 1,
305 => 1,
313 => 1,
318 => 1,
353 => 1,
362 => 1,
374 => 1,
383 => 1,
391 => 1,
396 => 1,
411 => 1,
419 => 1,
431 => 1,
451 => 1,
459 => 1,
467 => 1,
71 => 1,
78 => 1,
85 => 1,
97 => 1,
105 => 1,
113 => 1,
117 => 1,
125 => 1,
133 => 1,
177 => 1,
185 => 1,
189 => 1,
193 => 1,
197 => 1,
201 => 1,
205 => 1,
214 => 1,
217 => 1,
266 => 1,
273 => 1,
277 => 1,
281 => 1,
285 => 1,
297 => 1,
306 => 1,
314 => 1,
319 => 1,
354 => 1,
363 => 1,
375 => 1,
384 => 1,
392 => 1,
397 => 1,
412 => 1,
420 => 1,
432 => 1,
452 => 1,
460 => 1,
468 => 1,
];
case 'ReturnTypeUnitTest.3.inc':
return [
Expand Down

0 comments on commit 75affdf

Please sign in to comment.