Skip to content

Commit d4e3826

Browse files
committed
Fix get_posts detection
1 parent b885e4a commit d4e3826

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

phpstan.neon

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,3 @@ parameters:
1212
-
1313
path: %rootDir%/../../../src/GetPostDynamicFunctionReturnTypeExtension.php
1414
message: "#^Strict comparison using !== between PhpParser\\\\Node\\\\Expr and 'OBJECT' will always evaluate to true\\.$#"
15-
# Accessing value of function arguments.
16-
-
17-
message: "#^Cannot access offset 'fields' on PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType\\.$#"
18-
path: src/GetPostsDynamicFunctionReturnTypeExtension.php
19-
-
20-
message: "#^Parameter \\#1 \\$encoded_string of function parse_str expects string, PHPStan\\\\Type\\\\Constant\\\\ConstantStringType given\\.$#"
21-
path: src/GetPostsDynamicFunctionReturnTypeExtension.php

src/GetPostsDynamicFunctionReturnTypeExtension.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,21 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4242

4343
// Called with an array argument
4444
if ($argumentType instanceof ConstantArrayType) {
45-
$fields = $argumentType['fields'] ?? 'all';
45+
foreach($argumentType->getKeyTypes() as $index => $key) {
46+
if (! $key instanceof ConstantStringType || $key->getValue() !== 'fields') {
47+
continue;
48+
}
49+
50+
$fieldsType = $argumentType->getValueTypes()[$index];
51+
if ($fieldsType instanceof ConstantStringType) {
52+
$fields = $fieldsType->getValue();
53+
}
54+
break;
55+
}
4656
}
4757
// Called with a string argument
4858
if ($argumentType instanceof ConstantStringType) {
49-
parse_str($argumentType, $variables);
59+
parse_str($argumentType->getValue(), $variables);
5060
$fields = $variables['fields'] ?? 'all';
5161
}
5262

0 commit comments

Comments
 (0)