Completed
Pull Request — master (#196)
by Enrico
05:34 queued 41s
created

ConstFetch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 31
ccs 4
cts 9
cp 0.4444
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 19 4
1
<?php
2
3
namespace PHPSA\Compiler\Expression;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
use PHPSA\Compiler\Expression;
8
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
9
10
class ConstFetch extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\ConstFetch';
13
14
    /**
15
     * true, CONSTANTNAME, ...
16
     *
17
     * @param \PhpParser\Node\Expr\ConstFetch $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21 7
    protected function compile($expr, Context $context)
22
    {
23 7
        $compiler = $context->getExpressionCompiler();
24
25 7
        if ($expr->name instanceof Node\Name) {
0 ignored issues
show
Bug introduced by
The class PHPSA\Compiler\Expression\Node\Name does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
26
            if ($expr->name->parts[0] === 'true') {
27
                return new CompiledExpression(CompiledExpression::BOOLEAN, true);
28
            }
29
30
            if ($expr->name->parts[0] === 'false') {
31
                return new CompiledExpression(CompiledExpression::BOOLEAN, false);
32
            }
33
        }
34
35
        /**
36
         * @todo Implement check
37
         */
38 7
        return $compiler->compile($expr->name);
39
    }
40
}
41