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

voku / Simple-PHP-Code-Parser / 24218032206

09 Apr 2026 11:17PM UTC coverage: 83.27% (+0.009%) from 83.261%
24218032206

push

github

web-flow
Merge pull request #77 from voku/copilot/adapt-php-parser-compatibility

Add php-parser v5 compatibility (^4.18 || ^5)

8 of 13 new or added lines in 7 files covered. (61.54%)

42 existing lines in 4 files now uncovered.

1543 of 1853 relevant lines covered (83.27%)

43.97 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;
146✔
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');
81✔
53
        if (
54
            $parent instanceof Namespace_
81✔
55
            &&
56
            $parent->name instanceof Name
81✔
57
        ) {
NEW
58
            $namespace = '\\' . $parent->name->toString() . '\\';
×
59
        } else {
60
            $namespace = '';
81✔
61
        }
62

63
        return $namespace . $nodeName;
81✔
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 = '';
142✔
77

78
        if (
79
            $node instanceof \PhpParser\Node
142✔
80
            &&
81
            \property_exists($node, 'namespacedName')
142✔
82
        ) {
83
            if ($node->namespacedName) {
142✔
84
                $fqn = $node->namespacedName->toString();
142✔
85
            } elseif (\property_exists($node, 'name') && $node->name) {
4✔
NEW
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;
142✔
93

94
        return $fqn;
142✔
95
    }
96

97
    protected function prepareNode(Node $node): void
98
    {
99
        $this->line = method_exists($node, 'getStartLine')
146✔
100
            ? $node->getStartLine()
146✔
NEW
101
            : $node->getLine(); // @phpstan-ignore-line getLine() was removed in PHP-Parser v5
×
102
    }
103
}
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