ClassNameReplacement::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\PhpGenerics\Generator\Visitor;
4
5
use PhpParser\Node;
6
use PhpParser\Node\Name;
7
use PhpParser\Node\Stmt\Class_;
8
use PhpParser\NodeVisitorAbstract;
9
10
final class ClassNameReplacement extends NodeVisitorAbstract
11
{
12
    /** @var string */
13
    private $newName;
14
15
    public function __construct(string $newName)
16
    {
17
        $this->newName = $newName;
18
    }
19
20
    public function enterNode(Node $node)
21
    {
22
        if (!$node instanceof Class_) {
23
            return null;
24
        }
25
        return new Class_(
26
            $this->newName,
27
            [
28
                'flags' => Class_::MODIFIER_FINAL,
29
                'extends' => new Name($node->name->toString()),
0 ignored issues
show
Bug introduced by
The method toString() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
                'extends' => new Name($node->name->/** @scrutinizer ignore-call */ toString()),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
                'implements' => $node->implements,
31
                'stmts' => $node->stmts,
32
            ],
33
            ['comments' => []] + $node->getAttributes()
34
        );
35
    }
36
}
37