• 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

70.91
/src/voku/SimplePhpParser/Model/PHPInterface.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace voku\SimplePhpParser\Model;
6

7
use PhpParser\Node\Stmt\Interface_;
8
use ReflectionClass;
9
use voku\SimplePhpParser\Parsers\Helper\Utils;
10

11
class PHPInterface extends BasePHPClass
12
{
13
    /**
14
     * @phpstan-var class-string
15
     */
16
    public string $name;
17

18
    /**
19
     * @var string[]
20
     *
21
     * @phpstan-var class-string[]
22
     */
23
    public array $parentInterfaces = [];
24

25
    /**
26
     * @param Interface_ $node
27
     * @param null       $dummy
28
     *
29
     * @return $this
30
     */
31
    public function readObjectFromPhpNode($node, $dummy = null): self
32
    {
33
        $this->prepareNode($node);
8✔
34

35
        $this->name = static::getFQN($node);
8✔
36

37
        // Extract PHP 8.0+ attributes
38
        if (!empty($node->attrGroups)) {
8✔
39
            $this->attributes = Utils::extractAttributesFromAstNode($node->attrGroups);
×
40
        }
41

42
        $interfaceExists = false;
8✔
43
        try {
44
            if (\interface_exists($this->name, true)) {
8✔
45
                $interfaceExists = true;
8✔
46
            }
47
        } catch (\Throwable $e) {
×
48
            // nothing
49
        }
50
        if ($interfaceExists) {
8✔
51
            $reflectionInterface = Utils::createClassReflectionInstance($this->name);
8✔
52
            $this->readObjectFromReflection($reflectionInterface);
8✔
53
        }
54

55
        $this->collectTags($node);
8✔
56

57
        foreach ($node->getMethods() as $method) {
8✔
58
            $methodNameTmp = $method->name->name;
8✔
59

60
            if (isset($this->methods[$methodNameTmp])) {
8✔
61
                $this->methods[$methodNameTmp] = $this->methods[$methodNameTmp]->readObjectFromPhpNode($method);
8✔
62
            } else {
63
                $this->methods[$methodNameTmp] = (new PHPMethod($this->parserContainer))->readObjectFromPhpNode($method);
×
64
            }
65

66
            if (!$this->methods[$methodNameTmp]->file) {
8✔
67
                $this->methods[$methodNameTmp]->file = $this->file;
×
68
            }
69
        }
70

71
        if (!empty($node->extends)) {
8✔
72
            /** @var class-string $interfaceExtended */
NEW
73
            $interfaceExtended = $node->extends[0]->toString();
×
74
            $this->parentInterfaces[] = $interfaceExtended;
×
75
        }
76

77
        return $this;
8✔
78
    }
79

80
    /**
81
     * @param ReflectionClass $interface
82
     *
83
     * @return $this
84
     */
85
    public function readObjectFromReflection($interface): self
86
    {
87
        $this->name = $interface->getName();
31✔
88

89
        if (!$this->line) {
31✔
90
            $lineTmp = $interface->getStartLine();
23✔
91
            if ($lineTmp !== false) {
23✔
92
                $this->line = $lineTmp;
23✔
93
            }
94
        }
95

96
        $file = $interface->getFileName();
31✔
97
        if ($file) {
31✔
98
            $this->file = $file;
31✔
99
        }
100

101
        $this->is_final = $interface->isFinal();
31✔
102

103
        $this->is_abstract = $interface->isAbstract();
31✔
104

105
        $this->is_anonymous = $interface->isAnonymous();
31✔
106

107
        $this->is_cloneable = $interface->isCloneable();
31✔
108

109
        $this->is_instantiable = $interface->isInstantiable();
31✔
110

111
        $this->is_iterable = $interface->isIterable();
31✔
112

113
        // Extract PHP 8.0+ attributes
114
        $this->attributes = Utils::extractAttributesFromReflection($interface);
31✔
115

116
        foreach ($interface->getMethods() as $method) {
31✔
117
            $this->methods[$method->getName()] = (new PHPMethod($this->parserContainer))->readObjectFromReflection($method);
31✔
118
        }
119

120
        /** @var class-string[] $interfaceNames */
121
        $interfaceNames = $interface->getInterfaceNames();
31✔
122
        $this->parentInterfaces = $interfaceNames;
31✔
123

124
        foreach ($this->parentInterfaces as $parentInterface) {
31✔
125
            $interfaceExists = false;
×
126
            try {
127
                if (
128
                    !$this->parserContainer->getInterface($parentInterface)
×
129
                    &&
130
                    \interface_exists($parentInterface, true)
×
131
                ) {
132
                    $interfaceExists = true;
×
133
                }
134
            } catch (\Throwable $e) {
×
135
                // nothing
136
            }
137
            if ($interfaceExists) {
×
138
                $reflectionInterface = Utils::createClassReflectionInstance($parentInterface);
×
139
                $parentInterfaceNew = (new self($this->parserContainer))->readObjectFromReflection($reflectionInterface);
×
140
                $this->parserContainer->addInterface($parentInterfaceNew);
×
141
            }
142
        }
143

144
        foreach ($interface->getReflectionConstants() as $constant) {
31✔
145
            $this->constants[$constant->getName()] = (new PHPConst($this->parserContainer))->readObjectFromReflection($constant);
×
146
        }
147

148
        return $this;
31✔
149
    }
150
}
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