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

NewOp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 23 5
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