Skip to content
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
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForJsonArrayRector\Fixture;

use Nette\Utils\Json;

final class JsonUtilsWithNamedArg
{
public function provide(string $contents): array
{
return Json::decode(forceArrays: true, json: $contents);
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForJsonArrayRector\Fixture;

use Nette\Utils\Json;

final class JsonUtilsWithNamedArg
{
/**
* @return array<string, mixed>
*/
public function provide(string $contents): array
{
return Json::decode(forceArrays: true, json: $contents);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForJsonArrayRector\Fixture;

final class WithNamedArg
{
public function provide(string $contents): array
{
return json_decode(associative: true, json: $contents);
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForJsonArrayRector\Fixture;

final class WithNamedArg
{
/**
* @return array<string, mixed>
*/
public function provide(string $contents): array
{
return json_decode(associative: true, json: $contents);
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\TypeDeclarationDocblocks\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
Expand Down Expand Up @@ -139,12 +140,12 @@ private function isJsonDecodeToArray(Expr $expr): bool
return false;
}

if (count($expr->getArgs()) !== 2) {
$arg = $expr->getArg('associative', 1);
if (! $arg instanceof Arg) {
return false;
}

$secondArg = $expr->getArgs()[1];
return $this->valueResolver->isTrue($secondArg->value);
return $this->valueResolver->isTrue($arg->value);
}

if ($expr instanceof StaticCall) {
Expand All @@ -160,12 +161,12 @@ private function isJsonDecodeToArray(Expr $expr): bool
return false;
}

if (count($expr->getArgs()) !== 2) {
$arg = $expr->getArg('forceArrays', 1);
if (! $arg instanceof Arg) {
return false;
}

$secondArg = $expr->getArgs()[1];
return $this->valueResolver->isTrue($secondArg->value);
return $this->valueResolver->isTrue($arg->value);
}

return false;
Expand Down
Loading