@param string     $class
@param int        $callIndex
@param Call       $call
@param MockObject $mock

@return \Closure
494181
private function getMockCallback(
        string $class,
        int $callIndex,
        Call $call,
        MockObject $mock
    ): \Closure {
        return function () use ($class, $callIndex, $call, $mock) {
            if ($call->hasWith()) {
                $this->compareArguments($class, $call->getMethod(), $callIndex, $call->getWith(), func_get_args());
            }

            if (null !== $exception = $call->getException()) {
                throw $exception;
            }

            if ($call->hasReturnSelf()) {
                return $mock;
            }

            if ($call->hasReturn()) {
                return $call->getReturn();
            }

            if ($call->hasReturnCallback()) {
                $callback = $call->getReturnCallback();

                return $callback(...func_get_args());
            }
        };
    }
1068371
protected function callHandler(
        callable $callable,
        ServerRequestInterface $request,
        ResponseInterface $response,
        array $routeArguments
    ) {
        # Action is a closure
        if ($callable instanceof Closure) {
            array_unshift($routeArguments, $request, $response);
            $result = call_user_func_array($callable, $routeArguments);
        } else {
            # Action is a method of an Action class
            if (is_array($callable) && $callable[0] instanceof Action\ActionInterface) {
                $callable[0]->setResponse($response);
                $callable[0]->setRequest($request);
            }

            # Call Action method
            $result   = $this->callAction($callable, $request, $response, $routeArguments);
            /** @var Action\ActionInterface $action */
            $action   = $callable[0];
            $response = $action->getResponse();
        }

        if (($result instanceof ResponseInterface)) {
            $response = $result;
        } else {
            $response = $this->buildResponse($result, $response, $request);
        }

        return $response;
    }
179602
public function deleteCall($index = null)
	{
		$calls = $this->listCalls();

		if ($index === null)
		{
			$index = \count($calls) - 1;
		}

		$call = $calls[$index];
		unset($calls[$index]);
		$calls = array_values($calls);
		$this->setOption('calls', $calls);

		return $call;
	}
80480
private function executeCall()
    {
        $call = $this->call;
        list($results, $shouldContinue) = $this->mapResults(
            $call($this->callOptions)
        );

        $this->set(
            $this->resultTokenPath,
            $this->callOptions,
            $this->determineNextResultToken($results, $shouldContinue)
        );

        return $results;
    }
287220
protected function createQueuedHandlerCallable($class, $method)
    {
        return function () use ($class, $method) {
            $arguments = array_map(function ($a) {
                return is_object($a) ? clone $a : $a;
            }, func_get_args());

            if ($this->handlerWantsToBeQueued($class, $arguments)) {
                $this->queueHandler($class, $method, $arguments);
            }
        };
    }
435734
public function model($key, $class, Closure $callback = null)
    {
        $this->bind($key, RouteBinding::forModel($this->container, $class, $callback));
    }
660228
private function callableForNextMiddleware($index)
    {
        $middlewares = $this->getMiddlewares();

        if (!isset($middlewares[$index])) {
            return function () { return; };
        }

        $middleware = $middlewares[$index];
        $returningMiddleware = $this->decorateMiddlewareIfNeeded($middleware);

        return function ($message, &$return = null) use ($returningMiddleware, $index) {
            $returningMiddleware->handle($message, $this->callableForNextMiddleware($index + 1), $return);

            return $return;
        };
    }
248693
public function call(Closure $callback = null, $caller = null)
    {
        if ($callback instanceof Closure) {
            // Make dependency injection possible
            $parameters = $this->resolveMethodDependencies(
                [$caller], new ReflectionFunction($callback)
            );
            call_user_func_array($callback, $parameters);
        }

        return $caller;
    }
1108425
public static function dispatch(
        $options = [],
        $closure = null,
        $class = null
    ) {
        if (is_callable($options)) {
            $_closure = $options;
            $_options = $closure;
        } else {
            $_closure = $closure;
            $_options = $options;
        }

        is_array($_options) || $_options = [];

        /** @var Implementation $app */
        self::getInstance($class, $_options);

        is_null($_closure) || $_closure();

        self::getInstance()->dispatch();
    }
1162870
public static function assertNotCalled(
      FBMock_Mock $mock,
      $method_name,
      $msg='') {
    FBMock_Utils::assertString($method_name);
    self::assertNumCalls($mock, $method_name, 0, $msg);
  }
598998
protected function parseCall()
    {

        if ($this->call instanceof Closure) {
            $this->callClass = Closure::class;
            $this->callMethod = '';
            $this->isStaticMethod = false;
            $this->isFunction = false;
            $this->isClosure = true;
            return;
        }

        list($class, $method) = $this->toClassAndMethod($this->call);

        if ($class === '') {
            $this->callClass = '';
            $this->callMethod = $method;
            $this->isStaticMethod = false;
            $this->isFunction = true;
            $this->isClosure = false;
            return;
        }

        $this->callClass = $class;
        $this->callMethod = $method;
        $this->isFunction = false;
        $this->isClosure = false;

        $reflection = new ReflectionMethod($class, $method);
        $this->isStaticMethod = $reflection->isStatic();

        if (!$reflection->isPublic()) {
            throw new LogicException("Method '$method' of $class is not public and therefore not callable.");
        }

        return;

    }
423001
protected function getFixtureCaller($traceIndex = 6)
    {
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $traceIndex + 1);
        $caller = $trace[$traceIndex];

        if (isset($caller['class'])) {
            $result = @$caller['class'] . '->' . @$caller['function'] . '()';
        } else {
            $result = @$caller['function'] . '()';
        }

        return $result;
    }
1064863
private function processCall(\stdClass $call)
    {
        $id = property_exists($call, 'id') ? $call->id : null;
        $params = property_exists($call, 'params') ? $call->params : [];
        $result = null;
        $namespace = substr($call->method, 0, strpos($call->method, '.'));

        try {
            // set named parameters
            if (is_object($params)) {
                $newParams = [];
                foreach ($this->reflectionMethods[$call->method]->getParameters() as $param) {
                    $paramName = $param->getName();
                    $defaultValue = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
                    $newParams[] = property_exists($params, $paramName) ? $params->$paramName : $defaultValue;
                }

                $params = $newParams;
            }

            // invoke
            $result = $this->reflectionMethods[$call->method]->invokeArgs($this->instances[$namespace], $params);
        } catch (\Exception $e) {
            return $this->getError($e->getCode(), $id, $e->getMessage());
        }

        if (!$id && $id !== 0) {
            return null;
        }

        return [
            'jsonrpc' => '2.0',
            'result' => $result,
            'id' => $id,
        ];
    }
1286540
private static function _callDispatcher($dispatcherCallback) {
        $dispatcherCallback = $dispatcherCallback[0] !== '\\' ? __NAMESPACE__ . '\\' . $dispatcherCallback : $dispatcherCallback;

        if (!is_callable($dispatcherCallback)) {
            throw new \Exception('Routing dispacher [' . $dispatcherCallback . '] cannot be called.', 500);
        }

        return call_user_func_array($dispatcherCallback, [
            self::$_uri, self::$_config
        ]);
    }
1200242
public static function callMethod($objectOrClass, string $methodName, ...$args)
    {
        $objectOrClass = self::getObject($objectOrClass);
        $closure =
            /**
             * @param string $methodName
             * @param array $args
             * @return mixed
             */
            function (string $methodName, ...$args) {
                if (\method_exists($this, $methodName)) {
                    return $this->$methodName(...$args);
                }
                throw new \RuntimeException(
                    Picklock::errorMessage($this, $methodName, true)
                );
            };
        return
            $closure->call($objectOrClass, $methodName, ...$args);
    }
190273
public function buildExecutable($callableOrMethodStr)
    {
        try {
            list($reflFunc, $invocationObj) = $this->buildExecutableStruct($callableOrMethodStr);
        } catch (\ReflectionException $e) {
            throw InjectionException::fromInvalidCallable(
                $this->inProgressMakes,
                $callableOrMethodStr,
                $e
            );
        }

        return new Executable($reflFunc, $invocationObj);
    }
1098881
private function resolve(int $index): RequestHandlerInterface
    {
        return new RequestHandler(function (ServerRequestInterface $request) use ($index) {
            $middleware = isset($this->stack[$index]) ? $this->stack[$index] : new CallableHandler(function () {
            });

            if ($middleware instanceof Closure) {
                $middleware = new CallableHandler($middleware);
            }

            if (!($middleware instanceof MiddlewareInterface)) {
                throw new UnexpectedValueException(
                    sprintf('The middleware must be an instance of %s', MiddlewareInterface::class)
                );
            }

            return $middleware->process($request, $this->resolve($index + 1));
        });
    }