Skip to content

Commit

Permalink
improve ternary to pass both true/null as true
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 9, 2022
1 parent f660cb8 commit 6999ac5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ArrayAssoc
{
public function run($data, array $items)
{
$data = \json_decode($data, $items[0] === null);
$data = \json_decode($data, $items[0] === null ?: $items[0]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final class ClueJsonDecode
public function run($data)
{
if ($this->options === 0) {
$data = \json_decode($data, $this->assoc === null, $this->depth);
$data = \json_decode($data, $this->assoc === null ?: $this->assoc, $this->depth);
} else {
$data = \json_decode($data, $this->assoc === null, $this->depth, $this->options);
$data = \json_decode($data, $this->assoc === null ?: $this->assoc, $this->depth, $this->options);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PossiblyNull
{
function run(string $json, ?bool $associative)
{
$value = json_decode($json, $associative === null);
$value = json_decode($json, $associative === null ?: $associative);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function refactor(Node $node): ?Node

// add conditional ternary
$nullIdentical = new Identical($associativeValue, $this->nodeFactory->createNull());
$args[1]->value = $nullIdentical;
$ternary = new Ternary($nullIdentical, null, $associativeValue);
$args[1]->value = $ternary;

return $node;
}
Expand Down

0 comments on commit 6999ac5

Please sign in to comment.