Skip to content

Commit 953cbaa

Browse files
authored
Simplify and improve void or never addition logic (#453)
1 parent 1624bc0 commit 953cbaa

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/Visitor.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,18 @@ public function enterNode(Node $node)
9999
$this->additionalTagStrings[$symbolName] = $additions;
100100
}
101101

102-
if ($voidOrNever instanceof Type) {
103-
$addition = sprintf(
104-
'@phpstan-return %s',
105-
$voidOrNever->__toString()
106-
);
107-
if (
108-
! isset($this->additionalTagStrings[$symbolName])
109-
|| ! in_array($addition, $this->additionalTagStrings[$symbolName], true)
110-
) {
111-
$this->additionalTagStrings[$symbolName][] = $addition;
112-
}
102+
if (! ($voidOrNever instanceof Type)) {
103+
return null;
104+
}
105+
106+
$addition = sprintf('@phpstan-return %s', $voidOrNever->__toString());
107+
108+
if (in_array($addition, $additions, true)) {
109+
return null;
113110
}
114111

112+
$this->additionalTagStrings[$symbolName] = [...$additions, $addition];
113+
115114
return null;
116115
}
117116

@@ -811,6 +810,10 @@ private function voidOrNever(Node $node): ?Type
811810
return null;
812811
}
813812

813+
if ($node->getReturnType() !== null) {
814+
return null;
815+
}
816+
814817
$returnStmts = $this->nodeFinder->findInstanceOf($node, Stmt_Return::class);
815818

816819
// If there is a return statement, it's not return type never.

wordpress-stubs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127890,7 +127890,6 @@ function wp_sizes_attribute_includes_valid_auto(string $sizes_attr): bool
127890127890
* @see https://html.spec.whatwg.org/multipage/rendering.html#img-contain-size
127891127891
* @see https://core.trac.wordpress.org/ticket/62413
127892127892
* @see https://core.trac.wordpress.org/ticket/62731
127893-
* @phpstan-return void
127894127893
*/
127895127894
function wp_enqueue_img_auto_sizes_contain_css_fix(): void
127896127895
{
@@ -143365,7 +143364,6 @@ function wp_get_speculation_rules(): ?\WP_Speculation_Rules
143365143364
*
143366143365
* @since 6.8.0
143367143366
* @access private
143368-
* @phpstan-return void
143369143367
*/
143370143368
function wp_print_speculation_rules(): void
143371143369
{

0 commit comments

Comments
 (0)