Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Formatting\RedundantParentheses - closure with instanceof #200

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
})();
}
}
Loading