Skip to content

Commit 710f71a

Browse files
fix: Redundant Parentheses - closure with instanceof (#200)
Closes #199
1 parent b4f23de commit 710f71a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/WebimpressCodingStandard/Sniffs/Formatting/RedundantParenthesesSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ public function process(File $phpcsFile, $stackPtr)
143143
return;
144144
}
145145

146+
// Skip when open parenthesis after closing parenthesis
147+
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
148+
return;
149+
}
150+
146151
$firstInside = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, $closePtr, true);
147152
$lastInside = $phpcsFile->findPrevious(Tokens::$emptyTokens, $closePtr - 1, $stackPtr + 1, true);
148153

@@ -176,11 +181,6 @@ public function process(File $phpcsFile, $stackPtr)
176181
return;
177182
}
178183

179-
// Skip when open parenthesis after closing parenthesis
180-
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
181-
return;
182-
}
183-
184184
// Check single expression casting
185185
if (in_array($tokens[$prev]['code'], Tokens::$castTokens, true)) {
186186
$op = $phpcsFile->findNext(

test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc

+8
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,12 @@ class RedundantParentheses
207207
default => 0,
208208
};
209209
}
210+
211+
public function closureWithInstanceOf(): void
212+
{
213+
(static function (): void {
214+
$container = require 'config/container.php';
215+
assert($container instanceof ContainerInterface);
216+
})();
217+
}
210218
}

test/Sniffs/Formatting/RedundantParenthesesUnitTest.inc.fixed

+8
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,12 @@ class RedundantParentheses
207207
default => 0,
208208
};
209209
}
210+
211+
public function closureWithInstanceOf(): void
212+
{
213+
(static function (): void {
214+
$container = require 'config/container.php';
215+
assert($container instanceof ContainerInterface);
216+
})();
217+
}
210218
}

0 commit comments

Comments
 (0)