Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
[Compiler] Operators\NewOp - compile all parts + new will always retu…
Browse files Browse the repository at this point in the history
…rn Object, refs #298
  • Loading branch information
ovr committed Jan 15, 2017
1 parent 298ca45 commit 8bad524
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/Compiler/Expression/Operators/NewOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@ class NewOp extends AbstractExpressionCompiler
*/
protected function compile($expr, Context $context)
{
if ($expr->class instanceof Node\Name) {
$arguments = [];
$expressionCompile = $context->getExpressionCompiler();
$expressionCompile->compile($expr->class);

if (count($expr->args) > 0) {
foreach ($expr->args as $argument) {
$arguments[] = $context->getExpressionCompiler()->compile($argument->value);
}
} else {
$name = (string)$expr->class;
if (class_exists($name, true)) {
return new CompiledExpression(CompiledExpression::OBJECT, new $name());
}
if (count($expr->args) > 0) {
foreach ($expr->args as $argument) {
$expressionCompile->compile($argument->value);
}

return new CompiledExpression(CompiledExpression::OBJECT);
}

$context->debug('Unknown how to pass new', $expr);
return new CompiledExpression();
$context->debug(
'@todo We should support UnionTypes with FCQN assert...',
$expr
);

return new CompiledExpression(
CompiledExpression::OBJECT
);
}
}

0 comments on commit 8bad524

Please sign in to comment.