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
Expand Up @@ -12,6 +12,6 @@ namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if ($flag) {
echo "skip";
} elseif (json_validate($config, true)) {
} elseif (json_validate($config)) {
echo "valid config";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ if (json_decode('{"a":1}', true) !== null && json_last_error() === JSON_ERROR_NO
<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate('{"a":1}', true)) {
if (json_validate('{"a":1}')) {
echo "inline";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (json_decode($json, true, 3) !== null && json_last_error() === JSON_ERROR_NON

namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate($json, true, 3)){
if (json_validate($json, 3)){
echo 1;
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (json_decode($json, true) !== null && json_last_error() === JSON_ERROR_NONE){

namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate($json, true)){
if (json_validate($json)){
echo 1;
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (json_decode($json, true, 512) !== null && json_last_error() === JSON_ERROR_N

namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate($json, true, 512)){
if (json_validate($json, 512)){
echo 1;
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (json_decode(associative: true, json: $json) !== null && json_last_error() ==
<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate(associative: true, json: $json)){
if (json_validate(json: $json)){
echo 1;
}
?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (json_decode(json: $json, associative: true) !== null && json_last_error() ==
<?php
namespace Rector\Tests\Php83\Rector\BooleanAnd\JsonValidateRector\Fixture;

if (json_validate(json: $json, associative: true)){
if (json_validate(json: $json)){
echo 1;
}
?>
?>
12 changes: 11 additions & 1 deletion rules/Php83/Rector/BooleanAnd/JsonValidateRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ public function refactor(Node $node): ?Node
return null;
}

// Remove associative argument (position 1 or named) - json_validate does not have this param
foreach ($args as $index => $arg) {
if ($arg instanceof Arg && (
($arg->name !== null && $arg->name->toString() === 'associative') ||
($arg->name === null && $index === 1)
)) {
unset($funcCall->args[$index]);
break;
}
}

$funcCall->name = new Name('json_validate');
$funcCall->args = $args;

return $funcCall;
}
Expand Down