Test Failed
Pull Request — master (#37)
by Divine Niiquaye
15:08
created

PhpLiteralVisitor::enterNode()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 13
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\NodeVisitor;
19
20
use PhpParser\BuilderHelpers;
21
use PhpParser\Node\Scalar\String_;
22
23
/**
24
 * PhpLiteral Node Visitor.
25
 *
26
 * @author Divine Niiquaye Ibok <[email protected]>
27
 */
28
final class PhpLiteralVisitor extends \PhpParser\NodeVisitorAbstract
29
{
30
    private int $offset = -1;
31
32
    private array $args;
33
34
    /**
35
     * @param array<int,mixed> $args
36
     */
37
    public function __construct(array $args)
38
    {
39
        $this->args = $args;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function enterNode(\PhpParser\Node $node)
46
    {
47
        if ($node instanceof String_ && '??' === $node->value) {
48
            $value = $this->args[++$this->offset] ?? null;
49
50
            if (null === $value) {
51
                throw new \ParseError('Unable to parse syntax "??" as no value supplied for its string node expression.');
52
            }
53
54
            return BuilderHelpers::normalizeValue($value);
55
        }
56
57
        return parent::enterNode($node);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::enterNode($node) targeting PhpParser\NodeVisitorAbstract::enterNode() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
58
    }
59
}
60