Completed
Pull Request — master (#283)
by Enrico
04:27
created

NewOp::compile()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0729

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 4
nop 2
dl 0
loc 23
ccs 12
cts 14
cp 0.8571
crap 5.0729
rs 8.5906
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP Smart Analysis project 2015-2016
4
 *
5
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
6
 */
7
8
namespace PHPSA\Compiler\Expression\Operators;
9
10
use PhpParser\Node;
11
use PHPSA\CompiledExpression;
12
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
13
use PHPSA\Context;
14
use PHPSA\Compiler\Expression;
15
16
class NewOp extends AbstractExpressionCompiler
17
{
18
    protected $name = 'PhpParser\Node\Expr\New_';
19
20
    /**
21
     * @param \PhpParser\Node\Expr\New_ $expr
22
     * @param Context $context
23
     * @return CompiledExpression
24
     */
25 4
    protected function compile($expr, Context $context)
26
    {
27 4
        if ($expr->class instanceof Node\Name) {
28 4
            $name = $expr->class->parts[0];
0 ignored issues
show
Deprecated Code introduced by
The property PhpParser\Node\Name::$parts has been deprecated with message: Avoid directly accessing $parts, use methods instead.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
29
30 4
            $arguments = [];
31
32 4
            if (count($expr->args) > 0) {
33 2
                foreach ($expr->args as $argument) {
34 2
                    $arguments[] = $context->getExpressionCompiler()->compile($argument->value);
35 2
                }
36 2
            } else {
37 4
                if (class_exists($name, true)) {
38 2
                    return new CompiledExpression(CompiledExpression::OBJECT, new $name());
39
                }
40
            }
41
42 2
            return new CompiledExpression(CompiledExpression::OBJECT);
43
        }
44
45
        $context->debug('Unknown how to pass new', $expr);
46
        return new CompiledExpression();
47
    }
48
}
49