• 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

31.03
/src/Tempest/EventBus/src/EventBusDiscovery.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\EventBus;
6

7
use BackedEnum;
8
use Tempest\Core\Discovery;
9
use Tempest\Core\DiscoveryLocation;
10
use Tempest\Core\IsDiscovery;
11
use Tempest\Reflection\ClassReflector;
12
use Tempest\Reflection\TypeReflector;
13
use UnitEnum;
14

15
final class EventBusDiscovery implements Discovery
16
{
17
    use IsDiscovery;
18

19
    public function __construct(
382✔
20
        private readonly EventBusConfig $eventBusConfig,
21
    ) {
22
    }
382✔
23

24
    public function discover(DiscoveryLocation $location, ClassReflector $class): void
×
25
    {
26
        foreach ($class->getPublicMethods() as $method) {
×
27
            $eventHandler = $method->getAttribute(EventHandler::class);
×
28

29
            if (! $eventHandler) {
×
30
                continue;
×
31
            }
32

33
            $eventName = match (true) {
×
34
                $eventHandler->event instanceof BackedEnum => $eventHandler->event->value,
×
35
                $eventHandler->event instanceof UnitEnum => $eventHandler->event->name,
×
36
                is_string($eventHandler->event) => $eventHandler->event,
×
37
                default => null,
×
38
            };
×
39

40
            if ($eventName === null) {
×
41
                $parameters = iterator_to_array($method->getParameters());
×
42

43
                if ($parameters === []) {
×
44
                    continue;
×
45
                }
46

47
                /** @var TypeReflector $type */
48
                $type = $parameters[0]->getType();
×
49

50
                if (! $type->isClass() && ! $type->isInterface()) {
×
51
                    continue;
×
52
                }
53

54
                $eventName = $type->getName();
×
55
            }
56

57
            $this->discoveryItems->add($location, [$eventName, $eventHandler, $method]);
×
58
        }
59
    }
60

61
    public function apply(): void
382✔
62
    {
63
        foreach ($this->discoveryItems as [$eventName, $eventHandler, $method]) {
382✔
64
            $this->eventBusConfig->addClassMethodHandler(
382✔
65
                event: $eventName,
382✔
66
                handler: $eventHandler,
382✔
67
                reflectionMethod: $method,
382✔
68
            );
382✔
69
        }
70
    }
71
}
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