Completed
Pull Request — master (#85)
by Kévin
18:16 queued 14:06
created

NewOp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
ccs 7
cts 14
cp 0.5
rs 10
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 1
    protected function compile($expr, Context $context)
26
    {
27 1
        if ($expr->class instanceof Node\Name) {
28 1
            $name = $expr->class->parts[0];
29
30 1
            $arguments = [];
31
32 1
            if (count($expr->args) > 0) {
33
                foreach ($expr->args as $argument) {
34
                    $arguments[] = $context->getExpressionCompiler()->compile($argument->value);
35
                }
36
            } else {
37 1
                if (class_exists($name, true)) {
38 1
                    return new CompiledExpression(CompiledExpression::OBJECT, new $name());
39
                }
40
            }
41
42
            return new CompiledExpression(CompiledExpression::OBJECT);
43
        }
44
45
        $context->debug('Unknown how to pass new');
46
        return new CompiledExpression();
47
    }
48
}
49