diff --git a/app/Engine/Cfnpp.php b/app/Engine/Cfnpp.php index 5979256..88d1fd5 100644 --- a/app/Engine/Cfnpp.php +++ b/app/Engine/Cfnpp.php @@ -46,6 +46,11 @@ class Cfnpp implements ICompile public function __construct(IOptions $options) { + if (!($options instanceof CfnppOptions)) + { + throw new \Exception('Cfnpp compiler requires CfnppOptions'); + } + $this->document = new Document(); $this->functions = []; diff --git a/app/Engine/CfnppFunctions.php b/app/Engine/CfnppFunctions.php index 64cf7ef..f9bb6ec 100644 --- a/app/Engine/CfnppFunctions.php +++ b/app/Engine/CfnppFunctions.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace App\Engine; -use App\Dom\Document; use App\Dom\Node; use App\Dom\NodeValue; use App\Dom\NodeFunction; @@ -105,6 +104,10 @@ class CfnppFunctions */ public function f_var(Node $node, NodeFunction $function): ?Node { + if (!($function instanceof NodeFunctionValue)) + { + throw new \Exception('!var requires scalar argument'); + } $value = $this->options->getVariable($function->getValue()); return new NodeValue(null, $node->hasName() ? $node->getName() : null, $value); } diff --git a/app/Engine/CfnppOptions.php b/app/Engine/CfnppOptions.php index 6abe107..78840ad 100644 --- a/app/Engine/CfnppOptions.php +++ b/app/Engine/CfnppOptions.php @@ -23,6 +23,12 @@ class CfnppOptions implements IOptions $this->variables = []; } + /** + * Set all variables. + * + * @param array $variables + * @return void + */ public function setVariables(array $variables): void { $this->variables = $variables; @@ -41,8 +47,8 @@ class CfnppOptions implements IOptions /** * Retrieve the value of a single variable. * - * @param string $name - * @throws Exception if variable does not exist + * @param string $name + * @throws \Exception if variable does not exist * @return mixed */ public function getVariable(string $name)