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

MikeGeorgeff / kernel / 30390209258

28 Jul 2026 07:02PM UTC coverage: 99.66%. First build
30390209258

push

github

web-flow
Merge pull request #7 from MikeGeorgeff/2.x

406 of 408 new or added lines in 24 files covered. (99.51%)

587 of 589 relevant lines covered (99.66%)

35.37 hits per line

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

96.43
/src/Profiler/Profiler.php
1
<?php
2

3
namespace Georgeff\Kernel\Profiler;
4

5
use Georgeff\Kernel\Exception\ProfilerException;
6
use Georgeff\Kernel\Contract\DebuggableInterface;
7

8
/**
9
 * @internal
10
 */
11
final class Profiler implements DebuggableInterface
12
{
13
    /**
14
     * @var array<string, Profile>
15
     */
16
    private array $profiles = [];
17

18
    /**
19
     * @var array<string, DebuggableInterface>
20
     */
21
    private array $registry = [];
22

23
    public function initProfile(string $name): Profile
24
    {
25
        $profile = new Profile($name);
24✔
26

27
        $profile->start();
24✔
28

29
        return $this->profiles[$name] = $profile;
24✔
30
    }
31

32
    public function hasProfile(string $name): bool
33
    {
34
        return isset($this->profiles[$name]);
8✔
35
    }
36

37
    public function getProfile(string $name): Profile
38
    {
39
        ProfilerException::throwIfNot($this->hasProfile($name), "Profile [$name] has not been initialized");
3✔
40

41
        return $this->profiles[$name];
2✔
42
    }
43

44
    public function removeProfile(string $name): void
45
    {
46
        unset($this->profiles[$name]);
2✔
47
    }
48

49
    /**
50
     * Register debuggable services to merge into debug info
51
     */
52
    public function register(DebuggableInterface $service, ?string $name = null): void
53
    {
54
        $name ??= $service::class;
34✔
55

56
        $this->registry[$name] = $service;
34✔
57
    }
58

59
    public function getDebugInfo(): array
60
    {
61
        $output = [];
33✔
62

63
        foreach ($this->profiles as $name => $profile) {
33✔
64
            $output['profiles'][$name] = $profile->getDebugInfo();
18✔
65
        }
66

67
        foreach ($this->registry as $name => $debuggle) {
33✔
68
            $output['components'][$name] = $this->sanitize($debuggle->getDebugInfo());
29✔
69
        }
70

71
        return $output;
33✔
72
    }
73

74
    /**
75
     * @param array<array-key, mixed> $data
76
     *
77
     * @return array<array-key, mixed>
78
     */
79
    private function sanitize(array $data): array
80
    {
81
        $sanitized = [];
29✔
82

83
        foreach ($data as $key => $value) {
29✔
84
            $sanitized[$key] = match (true) {
28✔
85
                is_scalar($value) || null === $value => $value,
28✔
86
                is_array($value)                     => $this->sanitize($value),
22✔
87
                $value instanceof \Closure           => sprintf('Closure#%d', spl_object_id($value)),
6✔
88
                $value instanceof \BackedEnum        => $value->value,
5✔
89
                $value instanceof \UnitEnum          => $value->name,
4✔
90
                is_object($value)                    => $value::class,
3✔
91
                is_resource($value)                  => get_resource_type($value),
1✔
NEW
92
                default                              => $value
×
93
            };
28✔
94
        }
95

96
        return $sanitized;
29✔
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc