Skip to content

Commit

Permalink
Merge branch 'hotfix/90'
Browse files Browse the repository at this point in the history
Close #90
  • Loading branch information
michalbundyra committed Feb 20, 2020
2 parents 9d6a2ba + aca4089 commit 3c44924
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#90](https://github.com/webimpress/coding-standard/pull/90) fixes false-positive in `Formatting\RedundantParentheses` sniff when using nested ternary with `instanceof` condition.

## 1.1.3 - 2020-02-09

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ public function process(File $phpcsFile, $stackPtr)
if (! in_array($tokens[$prev]['code'], Tokens::$castTokens, true)) {
$instanceOf = $phpcsFile->findNext(T_INSTANCEOF, $stackPtr + 1, $closePtr);
if ($instanceOf !== false) {
$op = $phpcsFile->findNext(Tokens::$booleanOperators, $stackPtr + 1, $closePtr);
$op = $phpcsFile->findNext(
Tokens::$booleanOperators + [T_INLINE_ELSE => T_INLINE_ELSE],
$stackPtr + 1,
$closePtr
);
if ($op === false) {
$this->error($phpcsFile, $stackPtr, $closePtr, 'SingleInstanceOf');
return;
Expand Down
7 changes: 7 additions & 0 deletions test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,11 @@ class RedundantParentheses
if (! (new Invoke())()) {}
if (! (new Invoke())->method()) {}
}

public function nestedTernary()
{
return $a->foo()
? $a->bar()
: ($a->baz() instanceof \DateTime ? 1 : 2);
}
}
7 changes: 7 additions & 0 deletions test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,11 @@ class RedundantParentheses
if (! (new Invoke())()) {}
if (! (new Invoke())->method()) {}
}

public function nestedTernary()
{
return $a->foo()
? $a->bar()
: ($a->baz() instanceof \DateTime ? 1 : 2);
}
}

0 comments on commit 3c44924

Please sign in to comment.