Skip to content

Commit aceb226

Browse files
committed
Enhancement: Extract method which ensures callable
1 parent 6dcd595 commit aceb226

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Client.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,23 @@ public function doSendRequest(RequestInterface $request)
122122
*/
123123
public function on(RequestMatcher $requestMatcher, $result)
124124
{
125-
$callable = null;
125+
$callable = self::ensureCallable($result);
126126

127+
$this->conditionalResults[] = [
128+
'matcher' => $requestMatcher,
129+
'callable' => $callable,
130+
];
131+
}
132+
133+
/**
134+
* @param ResponseInterface|Exception|ClientExceptionInterface|callable $result
135+
*
136+
* @throws \InvalidArgumentException
137+
*
138+
* @return callable
139+
*/
140+
private static function ensureCallable($result)
141+
{
127142
switch (true) {
128143
case is_callable($result):
129144
$callable = $result;
@@ -144,10 +159,8 @@ public function on(RequestMatcher $requestMatcher, $result)
144159
default:
145160
throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable');
146161
}
147-
$this->conditionalResults[] = [
148-
'matcher' => $requestMatcher,
149-
'callable' => $callable,
150-
];
162+
163+
return $callable;
151164
}
152165

153166
/**

0 commit comments

Comments
 (0)