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

voku / Simple-PHP-Code-Parser / 5709606856

pending completion
5709606856

push

github

voku
[+]: ci: run test with PHP 8.2

1305 of 1592 relevant lines covered (81.97%)

7.61 hits per line

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

71.15
/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);
1✔
34

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

37
        $interfaceExists = false;
1✔
38
        try {
39
            if (\interface_exists($this->name, true)) {
1✔
40
                $interfaceExists = true;
1✔
41
            }
42
        } catch (\Exception $e) {
×
43
            // nothing
44
        }
45
        if ($interfaceExists) {
1✔
46
            $reflectionInterface = Utils::createClassReflectionInstance($this->name);
1✔
47
            $this->readObjectFromReflection($reflectionInterface);
1✔
48
        }
49

50
        $this->collectTags($node);
1✔
51

52
        foreach ($node->getMethods() as $method) {
1✔
53
            $methodNameTmp = $method->name->name;
1✔
54

55
            if (isset($this->methods[$methodNameTmp])) {
1✔
56
                $this->methods[$methodNameTmp] = $this->methods[$methodNameTmp]->readObjectFromPhpNode($method);
1✔
57
            } else {
58
                $this->methods[$methodNameTmp] = (new PHPMethod($this->parserContainer))->readObjectFromPhpNode($method);
×
59
            }
60

61
            if (!$this->methods[$methodNameTmp]->file) {
1✔
62
                $this->methods[$methodNameTmp]->file = $this->file;
×
63
            }
64
        }
65

66
        if (!empty($node->extends)) {
1✔
67
            /** @var class-string $interfaceExtended */
68
            $interfaceExtended = \implode('\\', $node->extends[0]->getParts());
×
69
            $this->parentInterfaces[] = $interfaceExtended;
×
70
        }
71

72
        return $this;
1✔
73
    }
74

75
    /**
76
     * @param ReflectionClass $interface
77
     *
78
     * @return $this
79
     */
80
    public function readObjectFromReflection($interface): self
81
    {
82
        $this->name = $interface->getName();
7✔
83

84
        if (!$this->line) {
7✔
85
            $lineTmp = $interface->getStartLine();
6✔
86
            if ($lineTmp !== false) {
6✔
87
                $this->line = $lineTmp;
6✔
88
            }
89
        }
90

91
        $file = $interface->getFileName();
7✔
92
        if ($file) {
7✔
93
            $this->file = $file;
7✔
94
        }
95

96
        $this->is_final = $interface->isFinal();
7✔
97

98
        $this->is_abstract = $interface->isAbstract();
7✔
99

100
        $this->is_anonymous = $interface->isAnonymous();
7✔
101

102
        $this->is_cloneable = $interface->isCloneable();
7✔
103

104
        $this->is_instantiable = $interface->isInstantiable();
7✔
105

106
        $this->is_iterable = $interface->isIterable();
7✔
107

108
        foreach ($interface->getMethods() as $method) {
7✔
109
            $this->methods[$method->getName()] = (new PHPMethod($this->parserContainer))->readObjectFromReflection($method);
7✔
110
        }
111

112
        /** @var class-string[] $interfaceNames */
113
        $interfaceNames = $interface->getInterfaceNames();
7✔
114
        $this->parentInterfaces = $interfaceNames;
7✔
115

116
        foreach ($this->parentInterfaces as $parentInterface) {
7✔
117
            $interfaceExists = false;
×
118
            try {
119
                if (
120
                    !$this->parserContainer->getInterface($parentInterface)
×
121
                    &&
122
                    \interface_exists($parentInterface, true)
×
123
                ) {
124
                    $interfaceExists = true;
×
125
                }
126
            } catch (\Exception $e) {
×
127
                // nothing
128
            }
129
            if ($interfaceExists) {
×
130
                $reflectionInterface = Utils::createClassReflectionInstance($parentInterface);
×
131
                $parentInterfaceNew = (new self($this->parserContainer))->readObjectFromReflection($reflectionInterface);
×
132
                $this->parserContainer->addInterface($parentInterfaceNew);
×
133
            }
134
        }
135

136
        foreach ($interface->getReflectionConstants() as $constant) {
7✔
137
            $this->constants[$constant->getName()] = (new PHPConst($this->parserContainer))->readObjectFromReflection($constant);
×
138
        }
139

140
        return $this;
7✔
141
    }
142
}
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

© 2025 Coveralls, Inc