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

tempestphp / tempest-framework / 12021710761

25 Nov 2024 06:54PM UTC coverage: 79.441% (-2.6%) from 81.993%
12021710761

push

github

web-flow
ci: close stale issues and pull requests

7879 of 9918 relevant lines covered (79.44%)

61.32 hits per line

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

85.71
/src/Tempest/Reflection/src/ClassReflector.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Reflection;
6

7
use Generator;
8
use ReflectionClass as PHPReflectionClass;
9
use ReflectionMethod as PHPReflectionMethod;
10
use ReflectionProperty as PHPReflectionProperty;
11

12
/**
13
 * @template TClassName
14
 */
15
final readonly class ClassReflector implements Reflector
16
{
17
    use HasAttributes;
18

19
    private PHPReflectionClass $reflectionClass;
20

21
    /**
22
     * @param class-string<TClassName>|object<TClassName>|PHPReflectionClass<TClassName> $reflectionClass
23
     * @phpstan-ignore-next-line
24
     */
25
    public function __construct(string|object $reflectionClass)
442✔
26
    {
27
        if (is_string($reflectionClass)) {
442✔
28
            $reflectionClass = new PHPReflectionClass($reflectionClass);
440✔
29
        } elseif (! $reflectionClass instanceof PHPReflectionClass && is_object($reflectionClass)) {
415✔
30
            $reflectionClass = new PHPReflectionClass($reflectionClass);
395✔
31
        }
32

33
        $this->reflectionClass = $reflectionClass;
442✔
34
    }
35

36
    public function getReflection(): PHPReflectionClass
412✔
37
    {
38
        return $this->reflectionClass;
412✔
39
    }
40

41
    /** @return Generator<PropertyReflector> */
42
    public function getPublicProperties(): Generator
99✔
43
    {
44
        foreach ($this->reflectionClass->getProperties(PHPReflectionProperty::IS_PUBLIC) as $property) {
99✔
45
            yield new PropertyReflector($property);
99✔
46
        }
47
    }
48

49
    /** @return Generator<PropertyReflector> */
50
    public function getProperties(): Generator
411✔
51
    {
52
        foreach ($this->reflectionClass->getProperties() as $property) {
411✔
53
            yield new PropertyReflector($property);
396✔
54
        }
55
    }
56

57
    /** @return Generator<MethodReflector> */
58
    public function getPublicMethods(): Generator
×
59
    {
60
        foreach ($this->reflectionClass->getMethods(PHPReflectionMethod::IS_PUBLIC) as $method) {
×
61
            yield new MethodReflector($method);
×
62
        }
63
    }
64

65
    public function getProperty(string $name): PropertyReflector
45✔
66
    {
67
        return new PropertyReflector(new PHPReflectionProperty($this->reflectionClass->getName(), $name));
45✔
68
    }
69

70
    public function hasProperty(string $name): bool
5✔
71
    {
72
        return $this->reflectionClass->hasProperty($name);
5✔
73
    }
74

75
    /**
76
     * @return class-string<TClassName>
77
     */
78
    public function getName(): string
425✔
79
    {
80
        return $this->reflectionClass->getName();
425✔
81
    }
82

83
    public function getShortName(): string
389✔
84
    {
85
        return $this->reflectionClass->getShortName();
389✔
86
    }
87

88
    public function getFileName(): string
×
89
    {
90
        return $this->reflectionClass->getFileName();
×
91
    }
92

93
    public function getType(): TypeReflector
415✔
94
    {
95
        return new TypeReflector($this->reflectionClass);
415✔
96
    }
97

98
    public function getConstructor(): ?MethodReflector
412✔
99
    {
100
        $constructor = $this->reflectionClass->getConstructor();
412✔
101

102
        if ($constructor === null) {
412✔
103
            return null;
407✔
104
        }
105

106
        return new MethodReflector($constructor);
394✔
107
    }
108

109
    public function getMethod(string $name): ?MethodReflector
408✔
110
    {
111
        return new MethodReflector($this->reflectionClass->getMethod($name));
408✔
112
    }
113

114
    public function isInstantiable(): bool
412✔
115
    {
116
        return $this->reflectionClass->isInstantiable();
412✔
117
    }
118

119
    public function newInstanceWithoutConstructor(): object
407✔
120
    {
121
        return $this->reflectionClass->newInstanceWithoutConstructor();
407✔
122
    }
123

124
    public function newInstanceArgs(array $args = []): object
390✔
125
    {
126
        return $this->reflectionClass->newInstanceArgs($args);
390✔
127
    }
128

129
    public function callStatic(string $method, mixed ...$args): mixed
48✔
130
    {
131
        $className = $this->getName();
48✔
132

133
        return $className::$method(...$args);
48✔
134
    }
135

136
    public function is(string $className): bool
×
137
    {
138
        return $this->getType()->matches($className);
×
139
    }
140

141
    public function implements(string $interface): bool
382✔
142
    {
143
        return $this->isInstantiable() && $this->getType()->matches($interface);
382✔
144
    }
145
}
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