StaticSt   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 8 2
1
<?php
2
3
namespace PHPSA\Compiler\Statement;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Context;
7
8
class StaticSt extends AbstractCompiler
9
{
10
    protected $name = '\PhpParser\Node\Stmt\Static_';
11
12
    /**
13
     * @param \PhpParser\Node\Stmt\Static_ $stmt
14
     * @param Context $context
15
     * @return CompiledExpression
16
     */
17
    public function compile($stmt, Context $context)
18
    {
19
        $compiler = $context->getExpressionCompiler();
20
21
        foreach ($stmt->vars as $var) {
22
            $compiler->compile($var->default);
0 ignored issues
show
Bug introduced by
It seems like $var->default can be null; however, compile() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
23
        }
24
    }
25
}
26