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

voku / Simple-PHP-Code-Parser / 24698292519

21 Apr 2026 12:55AM UTC coverage: 84.815%. Remained the same
24698292519

push

github

web-flow
Merge pull request #87 from voku/renovate/actions-cache-5.x

Update actions/cache action to v5.0.5

1765 of 2081 relevant lines covered (84.81%)

165.91 hits per line

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

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

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

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

94
        return $fqn;
639✔
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')
649✔
103
            ? $node->getStartLine()
649✔
104
            : $node->getLine();
×
105
    }
106

107
    /**
108
     * @phpstan-return ''|'private'|'protected'|'public'
109
     */
110
    protected static function getAsymmetricSetVisibility(object $node): string
111
    {
112
        if (\method_exists($node, 'isPublicSet') && $node->isPublicSet()) {
439✔
113
            return 'public';
×
114
        }
115

116
        if (\method_exists($node, 'isProtectedSet') && $node->isProtectedSet()) {
439✔
117
            return 'protected';
48✔
118
        }
119

120
        if (\method_exists($node, 'isPrivateSet') && $node->isPrivateSet()) {
439✔
121
            return 'private';
30✔
122
        }
123

124
        return '';
439✔
125
    }
126

127
    protected static function isPromotedParameter(\PhpParser\Node\Param $parameter): bool
128
    {
129
        return ($parameter->flags & \PhpParser\Node\Stmt\Class_::VISIBILITY_MODIFIER_MASK) !== 0;
153✔
130
    }
131

132
    /**
133
     * @phpstan-return ''|'private'|'protected'|'public'
134
     */
135
    protected static function getVisibilityFromModifierFlags(int $flags): string
136
    {
137
        if (($flags & \PhpParser\Node\Stmt\Class_::MODIFIER_PRIVATE) !== 0) {
135✔
138
            return 'private';
10✔
139
        }
140

141
        if (($flags & \PhpParser\Node\Stmt\Class_::MODIFIER_PROTECTED) !== 0) {
125✔
142
            return 'protected';
×
143
        }
144

145
        if (($flags & \PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC) !== 0) {
125✔
146
            return 'public';
125✔
147
        }
148

149
        return '';
×
150
    }
151

152
    protected static function hasReadonlyModifier(int $flags): bool
153
    {
154
        return ($flags & \PhpParser\Node\Stmt\Class_::MODIFIER_READONLY) !== 0;
135✔
155
    }
156

157
    protected static function hasFinalModifier(int $flags): bool
158
    {
159
        return ($flags & \PhpParser\Node\Stmt\Class_::MODIFIER_FINAL) !== 0;
135✔
160
    }
161
}
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