Skip to content

Commit

Permalink
rename method to isCollectingExceptions, add return void to test func…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
prolic committed Oct 23, 2017
1 parent 6b3da95 commit 1ed3321
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/EventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function disableCollectExceptions(): void
$this->collectExceptions = false;
}

public function isCollectingException(): bool
public function isCollectingExceptions(): bool
{
return $this->collectExceptions;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugin/InvokeStrategy/OnEventStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function (ActionEvent $actionEvent): void {
$handlers = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, []);

foreach ($handlers as $handler) {
if (is_callable($handler) || ! is_object($handler) || ! method_exists($handler, 'onEvent')) {
if (is_callable($handler) || ! is_object($handler) || ! is_callable([$handler, 'onEvent'])) {
continue;
}

try {
$handler->onEvent($message);
} catch (\Throwable $e) {
if ($target->isCollectingException()) {
if ($target->isCollectingExceptions()) {
$target->addCollectedException($e);
} else {
throw $e;
Expand Down
4 changes: 2 additions & 2 deletions tests/Mock/CustomOnEventStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function (ActionEvent $actionEvent): void {
$handlers = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS, []);

foreach ($handlers as $handler) {
if (is_callable($handler) || ! is_object($handler) || ! method_exists($handler, 'on')) {
if (is_callable($handler) || ! is_object($handler) || ! is_callable([$handler, 'on'])) {
continue;
}

try {
$handler->on($message);
} catch (\Throwable $e) {
if ($target->isCollectingException()) {
if ($target->isCollectingExceptions()) {
$target->addCollectedException($e);
} else {
throw $e;
Expand Down
10 changes: 5 additions & 5 deletions tests/Plugin/InvokeStrategy/OnEventStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function it_can_be_attached_to_event_bus(): void
->shouldBeCalled()
->willReturn(
new DefaultListenerHandler(
function () {
function (): void {
}
)
);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function it_should_still_work_with_callables(): void

$router = new EventRouter();
$router->route(CustomMessage::class)
->to(function (CustomMessage $message) use (&$result) {
->to(function (CustomMessage $message) use (&$result): void {
$result = true;
})
->andTo($handler);
Expand Down Expand Up @@ -144,7 +144,7 @@ public function it_should_still_work_with_callables_and_collect_all_exceptions()

$router = new EventRouter();
$router->route(CustomMessage::class)
->to(function (CustomMessage $message) {
->to(function (CustomMessage $message): void {
throw new \Exception('foo');
})
->andTo($handler);
Expand Down Expand Up @@ -181,7 +181,7 @@ public function it_should_still_work_with_callables_and_collect_all_exceptions_p

$router = new EventRouter();
$router->route(CustomMessage::class)
->to(function (CustomMessage $message) {
->to(function (CustomMessage $message): void {
throw new \Exception('foo');
})
->andTo($handler)
Expand Down Expand Up @@ -222,7 +222,7 @@ public function it_should_still_work_with_callables_and_other_strategies(): void

$router = new EventRouter();
$router->route(CustomMessage::class)
->to(function (CustomMessage $message) use (&$result) {
->to(function (CustomMessage $message) use (&$result): void {
$result = true;
})
->andTo($handler)
Expand Down

0 comments on commit 1ed3321

Please sign in to comment.