Skip to content

Commit

Permalink
Use toArray instead of json_decode/json_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnetau committed Jun 28, 2023
1 parent f6aa1b5 commit ac01dee
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace EdgeTelemetrics\EventCorrelation;

use RuntimeException;
use JsonSerializable;

/**
Expand All @@ -35,15 +34,13 @@ class Action implements JsonSerializable {
* @param string $cmd
* @param array|Event $vars
*/
public function __construct(string $cmd, $vars)
public function __construct(string $cmd, Event|array $vars)
{
$this->cmd = $cmd;
if ($vars instanceof Event) {
$this->vars = json_decode(json_encode($vars),true);
} elseif (is_array($vars)) {
$this->vars = $vars;
$this->vars = $vars->toArray();
} else {
throw new RuntimeException("Invalid variables passed to Action constructor");
$this->vars = $vars;
}
}

Expand Down

0 comments on commit ac01dee

Please sign in to comment.