Skip to content

Commit

Permalink
fix: Redundant Parentheses - closure with instanceof
Browse files Browse the repository at this point in the history
Closes #199
  • Loading branch information
michalbundyra committed Dec 18, 2023
1 parent b4f23de commit 397f0a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// Skip when open parenthesis after closing parenthesis
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
return;
}

$firstInside = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, $closePtr, true);
$lastInside = $phpcsFile->findPrevious(Tokens::$emptyTokens, $closePtr - 1, $stackPtr + 1, true);

Expand Down Expand Up @@ -176,11 +181,6 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

// Skip when open parenthesis after closing parenthesis
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
return;
}

// Check single expression casting
if (in_array($tokens[$prev]['code'], Tokens::$castTokens, true)) {
$op = $phpcsFile->findNext(
Expand Down
8 changes: 8 additions & 0 deletions test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,12 @@ class RedundantParentheses
default => 0,
};
}

public function closureWithInstanceOf(): void
{
(static function (): void {
$container = require 'config/container.php';
assert($container instanceof ContainerInterface);
})();
}
}
8 changes: 8 additions & 0 deletions test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,12 @@ class RedundantParentheses
default => 0,
};
}

public function closureWithInstanceOf(): void
{
(static function (): void {
$container = require 'config/container.php';
assert($container instanceof ContainerInterface);
})();
}
}

0 comments on commit 397f0a8

Please sign in to comment.