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

nepada / message-bus / 4581487412

pending completion
4581487412

push

github

GitHub
Update spaze/phpstan-disallowed-calls requirement from 2.11.6 to 2.12.1 (#75)

303 of 315 relevant lines covered (96.19%)

0.96 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 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(get_class($message));
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
     * @param string $suffix
68
     * @return string message name without namespace and suffix
69
     * @throws StaticAnalysisFailedException
70
     */
71
    public function shortName(string $suffix): string
1✔
72
    {
73
        $messageTypeReflection = ReflectionHelper::requireClassReflection($this->toString());
1✔
74

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

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

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

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

© 2025 Coveralls, Inc