Completed
Pull Request — master (#287)
by algo13
03:16
created

Closure::compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Compiler\Expression;
7
8
use PHPSA\CompiledExpression;
9
use PHPSA\Context;
10
use PHPSA\Definition\ClosureDefinition;
11
12
class Closure extends AbstractExpressionCompiler
13
{
14
    protected $name = \PhpParser\Node\Expr\Closure::class;
15
16
    /**
17
     * @param \PhpParser\Node\Expr\Closure $expr
18
     * @param Context $context
19
     * @return mixed
20
     */
21 1
    protected function compile($expr, Context $context)
22
    {
23 1
        $closure = new ClosureDefinition($expr);
24 1
        $closure->setFilepath($context->getFilepath());
25 1
        $closure->preCompile($context);
26 1
        $closure->compile(clone $context);
27
28 1
        return new CompiledExpression(
29 1
            CompiledExpression::CALLABLE_TYPE,
30
            $closure
31 1
        );
32
    }
33
}
34