Skip to content

Commit

Permalink
[CodingStyle] Handle null item on ManualJsonStringToJsonEncodeArrayRe…
Browse files Browse the repository at this point in the history
…ctor (#791)

* failing fixture null item on ManualJsonStringToJsonEncodeArrayRector

* fix null item on ManualJsonStringToJsonEncodeArrayRector

* phpstan
  • Loading branch information
samsonasik committed Aug 30, 2021
1 parent 5058437 commit ec7c68f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector\Fixture;

final class NullItem
{
public function run()
{
$json = '{"a":null}';
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\Assign\ManualJsonStringToJsonEncodeArrayRector\Fixture;

final class NullItem
{
public function run()
{
$jsonData = ['a' => null];
$json = \Nette\Utils\Json::encode($jsonData);
}
}

?>
2 changes: 1 addition & 1 deletion src/PhpParser/Node/NodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ private function createArrayItem($item, string | int | null $key = null): ArrayI
$arrayItem = new ArrayItem($this->createArray($item));
}

if ($item instanceof ClassConstFetch) {
if ($item === null || $item instanceof ClassConstFetch) {
$itemValue = BuilderHelpers::normalizeValue($item);
$arrayItem = new ArrayItem($itemValue);
}
Expand Down

0 comments on commit ec7c68f

Please sign in to comment.