Skip to content

Commit 252c2eb

Browse files
committed
Add Args::getFirstCallArg and Args::getFirstCallArgType
1 parent f76505b commit 252c2eb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Toolkit/Args.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,28 @@ public function getCallArgs(
6767
fn(Union $type) => new CallArg($arg, new CodeLocation($source, $arg), $type)
6868
));
6969
}
70+
71+
/**
72+
* @return Option<CallArg>
73+
*/
74+
public function getFirstCallArg(
75+
MethodReturnTypeProviderEvent |
76+
FunctionReturnTypeProviderEvent |
77+
AfterFunctionCallAnalysisEvent |
78+
AfterMethodCallAnalysisEvent $from,
79+
): Option {
80+
return $this->getCallArgs($from)->flatMap(fn(ArrayList $args) => $args->head());
81+
}
82+
83+
/**
84+
* @return Option<Union>
85+
*/
86+
public function getFirstCallArgType(
87+
MethodReturnTypeProviderEvent |
88+
FunctionReturnTypeProviderEvent |
89+
AfterFunctionCallAnalysisEvent |
90+
AfterMethodCallAnalysisEvent $from,
91+
): Option {
92+
return $this->getFirstCallArg($from)->map(fn(CallArg $arg) => $arg->type);
93+
}
7094
}

0 commit comments

Comments
 (0)