Skip to content

Commit

Permalink
Loop over PDOStatement::fetch() arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
cgocast committed Sep 28, 2023
1 parent 83485f3 commit 2217f5e
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ private static function handleFetch(MethodReturnTypeProviderEvent $event): ?Unio
$source = $event->getSource();
$call_args = $event->getCallArgs();
$fetch_mode = 0;

if (isset($call_args[0])
&& ($first_arg_type = $source->getNodeTypeProvider()->getType($call_args[0]->value))
&& $first_arg_type->isSingleIntLiteral()
) {
$fetch_mode = $first_arg_type->getSingleIntLiteral()->value;

foreach($call_args as $call_arg) {
$arg_name = $call_arg->name->name;

Check failure on line 54 in src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullPropertyFetch

src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php:54:25: PossiblyNullPropertyFetch: Cannot get property on possibly null variable $call_arg->name of type PhpParser\Node\Identifier|null (see https://psalm.dev/082)
if (!isset($arg_name) || $arg_name === "mode") {
$first_arg_type = $source->getNodeTypeProvider()->getType($call_arg->value);
if ($first_arg_type->isSingleIntLiteral()) {

Check failure on line 57 in src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullReference

src/Psalm/Internal/Provider/ReturnTypeProvider/PdoStatementReturnTypeProvider.php:57:38: PossiblyNullReference: Cannot call method isSingleIntLiteral on possibly null value (see https://psalm.dev/083)
$fetch_mode = $first_arg_type->getSingleIntLiteral()->value;
}
break;
}
}

switch ($fetch_mode) {
Expand Down

0 comments on commit 2217f5e

Please sign in to comment.