Skip to content

Commit

Permalink
WB-338: Improve type resolution in InvokableBehavior
Browse files Browse the repository at this point in the history
Updated type matching logic to use is_a and is_subclass_of for more accurate type resolution. This ensures that the correct context is selected based on class and subclass hierarchies, enhancing code reliability and maintainability.
  • Loading branch information
deligoez committed Aug 23, 2024
1 parent 97de3d9 commit d9b36e2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Behavior/InvokableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ public static function injectInvokableBehaviorParameters(
: $parameterType->getName();

$value = match (true) {
is_a($state->context, $typeName) => $state->context, // ContextManager
is_a($eventBehavior, $typeName) => $eventBehavior, // EventBehavior
is_a($state, $typeName) => $state, // State
is_a($state->history, $typeName) => $state->history, // EventCollection
$typeName === 'array' => $actionArguments, // Behavior Arguments
default => null,
is_a($typeName, class: ContextManager::class, allow_string: true) || is_subclass_of($typeName, class: ContextManager::class) => $state->context, // ContextManager
is_a($typeName, class: EventBehavior::class, allow_string: true) || is_subclass_of($typeName, class: EventBehavior::class) => $eventBehavior, // EventBehavior
is_a($state, $typeName) => $state, // State
is_a($state->history, $typeName) => $state->history, // EventCollection
$typeName === 'array' => $actionArguments, // Behavior Arguments
default => null,
};

$invocableBehaviorParameters[] = $value;
Expand Down

0 comments on commit d9b36e2

Please sign in to comment.