Skip to content

Commit

Permalink
use constant & fix variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Jan 12, 2024
1 parent 3dbf3db commit dc02f14
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Attribute/Subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Subscribe
{
public const ALL = '*';

/** @param class-string|'*' $eventClass */
/** @param class-string|self::ALL $eventClass */
public function __construct(
public readonly string $eventClass,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/EventBus/AttributeListenerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function listenersForEvent(object $event): iterable
if ($this->subscribeMethods !== null) {
return array_merge(
$this->subscribeMethods[$event::class] ?? [],
$this->subscribeMethods['*'] ?? [],
$this->subscribeMethods[Subscribe::ALL] ?? [],
);
}

Expand All @@ -52,7 +52,7 @@ public function listenersForEvent(object $event): iterable

return array_merge(
$this->subscribeMethods[$event::class] ?? [],
$this->subscribeMethods['*'] ?? [],
$this->subscribeMethods[Subscribe::ALL] ?? [],
);
}
}
12 changes: 6 additions & 6 deletions src/EventBus/ListenerDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public function __construct(callable $callable)

$this->callable = $callable;

$r = new ReflectionFunction($callable);
$reflectionFunction = new ReflectionFunction($callable);

if (method_exists($r, 'isAnonymous') && $r->isAnonymous()) {
if (method_exists($reflectionFunction, 'isAnonymous') && $reflectionFunction->isAnonymous()) {
$this->name = 'Closure';

return;
}

$callable = $r->getClosureThis();
$callable = $reflectionFunction->getClosureThis();

if (!$callable) {
$class = $r->getClosureCalledClass();
$class = $reflectionFunction->getClosureCalledClass();

$this->name = ($class ? $class->name . '::' : '') . $r->name;
$this->name = ($class ? $class->name . '::' : '') . $reflectionFunction->name;

return;
}

$this->name = $callable::class . '::' . $r->name;
$this->name = $callable::class . '::' . $reflectionFunction->name;
}

public function name(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function metadata(string $projector): ProjectorMetadata
$instance = $attribute->newInstance();
$eventClass = $instance->eventClass;

if ($eventClass === '*') {
if ($eventClass === Subscribe::ALL) {
throw new SubscribeAllNotSupported(
$projector,
$method->getName(),
Expand Down
2 changes: 1 addition & 1 deletion src/WatchServer/WatchListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(
) {
}

#[Subscribe('*')]
#[Subscribe(Subscribe::ALL)]
public function __invoke(Message $message): void
{
try {
Expand Down

0 comments on commit dc02f14

Please sign in to comment.