for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PHPSA\Compiler\Scalar;
use PHPSA\CompiledExpression;
use PHPSA\Context;
use PHPSA\Compiler\ScalarCompilerInterface;
use RuntimeException;
abstract class AbstractScalarCompiler implements ScalarCompilerInterface
{
/**
* @abstract
* @var string $name
*/
protected $name = 'unknown';
* @param $expression
* @throws RuntimeException when param does not match $this->name
protected function assertExpression($expression)
if (!$expression instanceof $this->name) {
throw new RuntimeException('Passed $expression must be instance of ' . $this->name);
}
* @param $stmt
* @param Context $context
* @return CompiledExpression
public function pass($stmt, Context $context)
$this->assertExpression($stmt);
return $this->compile($stmt, $context);
* @return string
public function getName()
return $this->name;
* @param $expr
* @return mixed
abstract protected function compile($expr, Context $context);