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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Tempest\Reflection;
6

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

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

18
    private PHPReflectionClass $reflectionClass;
19

20
    /**
21
     * @param class-string<TClassName>|TClassName|PHPReflectionClass<TClassName> $reflectionClass
22
     */
23
    public function __construct(string|object $reflectionClass)
739✔
24
    {
25
        if (is_string($reflectionClass)) {
739✔
26
            $reflectionClass = new PHPReflectionClass($reflectionClass);
737✔
27
        } elseif ($reflectionClass instanceof self) {
705✔
UNCOV
28
            $reflectionClass = $reflectionClass->getReflection();
×
29
        } elseif (! ($reflectionClass instanceof PHPReflectionClass)) {
705✔
30
            $reflectionClass = new PHPReflectionClass($reflectionClass);
673✔
31
        }
32

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

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

41
    public function getParent(): ?ClassReflector
32✔
42
    {
43
        if ($parentClass = $this->reflectionClass->getParentClass()) {
32✔
44
            return new ClassReflector($parentClass);
2✔
45
        }
46

47
        return null;
31✔
48
    }
49

50
    /** @return \Tempest\Reflection\TypeReflector[] */
51
    public function getInterfaces(): array
662✔
52
    {
53
        return array_map(
662✔
54
            fn (PHPReflectionClass $interface) => new TypeReflector($interface),
662✔
55
            $this->reflectionClass->getInterfaces(),
662✔
56
        );
662✔
57
    }
58

59
    /** @return PropertyReflector[] */
60
    public function getPublicProperties(): array
145✔
61
    {
62
        return array_map(
145✔
63
            fn (PHPReflectionProperty $property) => new PropertyReflector($property),
145✔
64
            $this->reflectionClass->getProperties(PHPReflectionProperty::IS_PUBLIC),
145✔
65
        );
145✔
66
    }
67

68
    /** @return PropertyReflector[] */
69
    public function getProperties(): array
688✔
70
    {
71
        return array_map(
688✔
72
            fn (PHPReflectionProperty $property) => new PropertyReflector($property),
688✔
73
            $this->reflectionClass->getProperties(),
688✔
74
        );
688✔
75
    }
76

77
    /** @return \Tempest\Reflection\MethodReflector[] */
UNCOV
78
    public function getPublicMethods(): array
×
79
    {
UNCOV
80
        return array_map(
×
UNCOV
81
            fn (PHPReflectionMethod $method) => new MethodReflector($method),
×
UNCOV
82
            $this->reflectionClass->getMethods(PHPReflectionMethod::IS_PUBLIC),
×
UNCOV
83
        );
×
84
    }
85

86
    public function getProperty(string $name): PropertyReflector
59✔
87
    {
88
        return new PropertyReflector(new PHPReflectionProperty($this->reflectionClass->getName(), $name));
59✔
89
    }
90

91
    public function hasProperty(string $name): bool
5✔
92
    {
93
        return $this->reflectionClass->hasProperty($name);
5✔
94
    }
95

96
    /**
97
     * @return class-string<TClassName>
98
     */
99
    public function getName(): string
711✔
100
    {
101
        return $this->reflectionClass->getName();
711✔
102
    }
103

104
    public function getShortName(): string
666✔
105
    {
106
        return $this->reflectionClass->getShortName();
666✔
107
    }
108

UNCOV
109
    public function getFileName(): string
×
110
    {
UNCOV
111
        return $this->reflectionClass->getFileName();
×
112
    }
113

114
    public function getType(): TypeReflector
698✔
115
    {
116
        return new TypeReflector($this->reflectionClass);
698✔
117
    }
118

119
    public function getConstructor(): ?MethodReflector
695✔
120
    {
121
        $constructor = $this->reflectionClass->getConstructor();
695✔
122

123
        if ($constructor === null) {
695✔
124
            return null;
690✔
125
        }
126

127
        return new MethodReflector($constructor);
671✔
128
    }
129

130
    public function getMethod(string $name): MethodReflector
685✔
131
    {
132
        return new MethodReflector($this->reflectionClass->getMethod($name));
685✔
133
    }
134

135
    public function isInstantiable(): bool
691✔
136
    {
137
        return $this->reflectionClass->isInstantiable();
691✔
138
    }
139

140
    public function newInstanceWithoutConstructor(): object
684✔
141
    {
142
        return $this->reflectionClass->newInstanceWithoutConstructor();
684✔
143
    }
144

145
    public function newInstanceArgs(array $args = []): object
667✔
146
    {
147
        return $this->reflectionClass->newInstanceArgs($args);
667✔
148
    }
149

150
    public function callStatic(string $method, mixed ...$args): mixed
61✔
151
    {
152
        $className = $this->getName();
61✔
153

154
        return $className::$method(...$args);
61✔
155
    }
156

UNCOV
157
    public function is(string $className): bool
×
158
    {
UNCOV
159
        return $this->getType()->matches($className);
×
160
    }
161

162
    public function implements(string $interface): bool
659✔
163
    {
164
        return $this->isInstantiable() && $this->getType()->matches($interface);
659✔
165
    }
166
}
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