storage = $storage; $this->automationValidator = $automationValidator; } /** * @param array{steps: array>, name: string} $data * * @return Automation */ public function createAutomation(array $data): Automation { $steps = []; foreach ($data['steps'] as $index => $step) { $steps[(string)$index] = Step::fromArray($step); } $automation = new Automation($data['name'], $steps, wp_get_current_user()); $this->automationValidator->validate($automation); $automationId = $this->storage->createAutomation($automation); $automation = $this->storage->getAutomation($automationId); if (!$automation) { throw new InvalidStateException("Could not find automation $automationId"); } return $automation; } }