• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

voku / Simple-PHP-Code-Parser / 24276985596

11 Apr 2026 06:47AM UTC coverage: 82.886% (+0.03%) from 82.857%
24276985596

Pull #79

github

web-flow
Merge fd40afd96 into 3fcaa1a81
Pull Request #79: Fix PHP 8 type resolution order and safe autoloading for newer syntax

75 of 128 new or added lines in 11 files covered. (58.59%)

3 existing lines in 1 file now uncovered.

1545 of 1864 relevant lines covered (82.89%)

91.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/src/voku/SimplePhpParser/Model/BasePHPElement.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\SimplePhpParser\Model;
6

7
use PhpParser\Node;
8
use PhpParser\Node\Name;
9
use PhpParser\Node\Stmt\Namespace_;
10
use PhpParser\NodeAbstract;
11
use voku\SimplePhpParser\Parsers\Helper\ParserContainer;
12

13
abstract class BasePHPElement
14
{
15
    public string $name = '';
16

17
    /**
18
     * @var string[]
19
     */
20
    public array $parseError = [];
21

22
    public ?int $line = null;
23

24
    public ?string $file = null;
25

26
    public ?int $pos = null;
27

28
    public ParserContainer $parserContainer;
29

30
    public function __construct(ParserContainer $parserContainer)
31
    {
32
        $this->parserContainer = $parserContainer;
312✔
33
    }
34

35
    /**
36
     * @param \Reflector $object
37
     *
38
     * @return $this
39
     */
40
    abstract public function readObjectFromReflection($object);
41

42
    /**
43
     * @param \PhpParser\NodeAbstract      $mixed_1
44
     * @param \PhpParser\NodeAbstract|null $mixed_2
45
     *
46
     * @return $this
47
     */
48
    abstract public function readObjectFromPhpNode($mixed_1, $mixed_2 = null);
49

50
    protected function getConstantFQN(NodeAbstract $node, string $nodeName): string
51
    {
52
        $parent = $node->getAttribute('parent');
162✔
53
        if (
54
            $parent instanceof Namespace_
162✔
55
            &&
56
            $parent->name instanceof Name
162✔
57
        ) {
58
            $namespace = '\\' . $parent->name->toString() . '\\';
×
59
        } else {
60
            $namespace = '';
162✔
61
        }
62

63
        return $namespace . $nodeName;
162✔
64
    }
65

66
    /**
67
     * @param \PhpParser\Node|string $node
68
     *
69
     * @return string
70
     *
71
     * @psalm-return class-string
72
     */
73
    protected static function getFQN($node): string
74
    {
75
        // init
76
        $fqn = '';
304✔
77

78
        if (
79
            $node instanceof \PhpParser\Node
304✔
80
            &&
81
            \property_exists($node, 'namespacedName')
304✔
82
        ) {
83
            if ($node->namespacedName) {
304✔
84
                $fqn = $node->namespacedName->toString();
304✔
85
            } elseif (\property_exists($node, 'name') && $node->name) {
8✔
86
                $fqn = $node->name instanceof Name ? $node->name->toString() : (string) $node->name;
×
87
            }
88
        }
89

90
        /** @noinspection PhpSillyAssignmentInspection - hack for phpstan */
91
        /** @var class-string $fqn */
92
        $fqn = $fqn;
304✔
93

94
        return $fqn;
304✔
95
    }
96

97
    protected function prepareNode(Node $node): void
98
    {
99
        // Keep the legacy getLine() fallback because we support multiple php-parser
100
        // versions and some restored compatibility code paths still rely on the alias.
101
        // @phpstan-ignore function.alreadyNarrowedType
102
        $this->line = \method_exists($node, 'getStartLine')
312✔
103
            ? $node->getStartLine()
312✔
NEW
104
            : $node->getLine();
×
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc