for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PHPSA\Compiler;
use PHPSA\Context;
use PhpParser\Node;
use PHPSA\Compiler;
use PHPSA\Compiler\Scalar\AbstractScalarCompiler;
use RuntimeException;
class Scalar
{
/**
* @param Node\Scalar $scalar
* @throws RuntimeException
* @return AbstractScalarCompiler
*/
protected function factory(Node\Scalar $scalar)
switch (get_class($scalar)) {
case Node\Scalar\LNumber::class:
return new Compiler\Scalar\LNum();
}
throw new RuntimeException('Unknown scalar: ' . get_class($scalar));
* @param Context $context
public function __construct(Node\Scalar $scalar, Context $context)
try {
$context->getEventManager()->fire(
Event\ScalarBeforeCompile::EVENT_NAME,
new Event\ScalarBeforeCompile(
$scalar,
$context
)
);
$compiler = $this->factory($scalar);
} catch (\Exception $e) {
$context->debug('ScalarCompiler is not implemented for ' . get_class($scalar));
return;
$compiler->pass($scalar, $context);