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

tempestphp / tempest-framework / 11800557345

12 Nov 2024 03:33PM UTC coverage: 82.436% (-0.02%) from 82.455%
11800557345

Pull #647

github

web-flow
Merge b39c42cf3 into d599d5047
Pull Request #647: feat(console): add `make:controller` and `make:model` commands

175 of 213 new or added lines in 12 files covered. (82.16%)

19 existing lines in 2 files now uncovered.

7425 of 9007 relevant lines covered (82.44%)

51.71 hits per line

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

95.92
/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)
427✔
26
    {
27
        if (is_string($reflectionClass)) {
427✔
28
            $reflectionClass = new PHPReflectionClass($reflectionClass);
425✔
29
        } elseif (! $reflectionClass instanceof PHPReflectionClass && is_object($reflectionClass)) {
400✔
30
            $reflectionClass = new PHPReflectionClass($reflectionClass);
380✔
31
        }
32

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

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

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

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

57
    /** @return Generator<MethodReflector> */
58
    public function getPublicMethods(): Generator
3✔
59
    {
60
        foreach ($this->reflectionClass->getMethods(PHPReflectionMethod::IS_PUBLIC) as $method) {
3✔
61
            yield new MethodReflector($method);
3✔
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
410✔
79
    {
80
        return $this->reflectionClass->getName();
410✔
81
    }
82

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

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

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

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

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

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

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

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

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

124
    public function newInstanceArgs(array $args = []): object
375✔
125
    {
126
        return $this->reflectionClass->newInstanceArgs($args);
375✔
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
3✔
137
    {
138
        return $this->getType()->matches($className);
3✔
139
    }
140

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