Skip to content

Commit

Permalink
Add Args::getFirstCallArg and Args::getFirstCallArgType
Browse files Browse the repository at this point in the history
  • Loading branch information
klimick committed Sep 11, 2022
1 parent f76505b commit 252c2eb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Toolkit/Args.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,28 @@ public function getCallArgs(
fn(Union $type) => new CallArg($arg, new CodeLocation($source, $arg), $type)
));
}

/**
* @return Option<CallArg>
*/
public function getFirstCallArg(
MethodReturnTypeProviderEvent |
FunctionReturnTypeProviderEvent |
AfterFunctionCallAnalysisEvent |
AfterMethodCallAnalysisEvent $from,
): Option {
return $this->getCallArgs($from)->flatMap(fn(ArrayList $args) => $args->head());
}

/**
* @return Option<Union>
*/
public function getFirstCallArgType(
MethodReturnTypeProviderEvent |
FunctionReturnTypeProviderEvent |
AfterFunctionCallAnalysisEvent |
AfterMethodCallAnalysisEvent $from,
): Option {
return $this->getFirstCallArg($from)->map(fn(CallArg $arg) => $arg->type);
}
}

0 comments on commit 252c2eb

Please sign in to comment.