Skip to content

Commit

Permalink
WEB-4344: Refactor ResultBehavior definition to an invokable method
Browse files Browse the repository at this point in the history
The class method definition in ResultBehavior has been refactored to an invokable. A previous anonymous function definition has been replaced with the __invoke magic method, offering a more concise syntax and enhancing the object's versatility by making it directly callable.
  • Loading branch information
deligoez committed Jan 11, 2024
1 parent 4d2a27f commit 039bc55
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions tests/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,15 @@
$value = random_int(10, 20);

$multipleWithItselfAction = new class extends ResultBehavior {
public function definition(): Closure
public function __invoke(EventBehavior $event): int
{
return function (EventBehavior $eventBehavior): int {
return $eventBehavior->payload['value'] * $eventBehavior->payload['value'];
};
return $event->payload['value'] * $event->payload['value'];
}
};

// 2. Act
$result = $multipleWithItselfAction->definition()(
eventBehavior: EventDefinition::from([
$result = $multipleWithItselfAction(
EventDefinition::from([
'type' => 'ADD',
'payload' => [
'value' => $value,
Expand Down

0 comments on commit 039bc55

Please sign in to comment.