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

nepada / message-bus / 11624443481

01 Nov 2024 04:43AM UTC coverage: 96.657%. Remained the same
11624443481

push

github

web-flow
Bump the phpstan group with 3 updates (#117)

318 of 329 relevant lines covered (96.66%)

0.97 hits per line

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

95.0
/src/MessageBus/StaticAnalysis/MessageType.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\MessageBus\StaticAnalysis;
5

6
use Nepada\MessageBus\Commands\Command;
7
use Nepada\MessageBus\Events\Event;
8
use Nepada\MessageBus\StaticAnalysis\Rules\ClassNameHasSuffixRule;
9

10
final readonly class MessageType
11
{
12

13
    /**
14
     * @var class-string
15
     */
16
    private string $type;
17

18
    /**
19
     * @param class-string $type
20
     */
21
    private function __construct(string $type)
1✔
22
    {
23
        $this->type = $type;
1✔
24
    }
1✔
25

26
    public static function fromMessage(object $message): self
1✔
27
    {
28
        return new self($message::class);
1✔
29
    }
30

31
    /**
32
     * @param class-string $type
33
     * @return MessageType
34
     */
35
    public static function fromString(string $type): self
1✔
36
    {
37
        return new self($type);
1✔
38
    }
39

40
    /**
41
     * @return class-string
42
     */
43
    public function toString(): string
44
    {
45
        return $this->type;
1✔
46
    }
47

48
    public function getGeneralType(): string
49
    {
50
        if (is_subclass_of($this->type, Command::class)) {
1✔
51
            return 'Command';
1✔
52

53
        } elseif (is_subclass_of($this->type, Event::class)) {
1✔
54
            return 'Event';
1✔
55

56
        } else {
57
            return 'Message';
1✔
58
        }
59
    }
60

61
    public function isHandlerRequired(): bool
62
    {
63
        return ! is_subclass_of($this->type, Event::class);
×
64
    }
65

66
    /**
67
     * @return string message name without namespace and suffix
68
     * @throws StaticAnalysisFailedException
69
     */
70
    public function shortName(string $suffix): string
1✔
71
    {
72
        $messageTypeReflection = ReflectionHelper::requireClassReflection($this->toString());
1✔
73

74
        $rule = new ClassNameHasSuffixRule($suffix);
1✔
75
        $rule->validate($this->toString());
1✔
76

77
        preg_match($rule->getRegexPattern(), $messageTypeReflection->getShortName(), $matches);
1✔
78

79
        return (string) $matches[1];
1✔
80
    }
81

82
}
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