Creating a chain array of return values

@param $action
@param $response
964570
private function createChainArrayOfReturnValues($action, $response)
    {
        // Pop first method
        $methods = $this->methods;
        $firstMethod = array_pop($methods);

        $lastValue = $response;

        $mockClassType = get_class($this->mockClass);

        if ( ! $this->mockClass instanceof MockInterface) {
            throw self::generateException('Class is not implementing MockInterface.');
        }

        $mockClassInstanceId = $this->mockClass->getShortifyPunitInstanceId();

        foreach($methods as $currentMethod)
        {
            $fakeClass = new MockClassOnTheFly();

            // extracting methods before the current method into an array
            $chainedMethodsBefore = $this->extractChainedMethodsBefore(
                array_reverse($this->methods),
                $currentMethod
            );

            // adding to the ShortifyPunit chained method response
            $this->addChainedMethodResponse(
                $chainedMethodsBefore,
                $currentMethod,
                $action,
                $lastValue,
                $mockClassInstanceId
            );

            $currentMethodName = key($currentMethod);

            // closure for MockOnTheFly chained methods
            $fakeClass->$currentMethodName = function() use (
                $mockClassInstanceId,
                $mockClassType,
                $chainedMethodsBefore,
                $currentMethod
            ) {
                return ShortifyPunit::createChainResponse(
                    $mockClassInstanceId,
                    $mockClassType,
                    $chainedMethodsBefore,
                    $currentMethod,
                    func_get_args()
                );
            };

            $lastValue = $fakeClass;

            // except from the last method all other chained method `returns` a calls so set the action for the next loop
            $action = MockAction::RETURNS;
        }



        $whenCase = new WhenCase($mockClassType, $this->mockClass->getShortifyPunitInstanceId(), key($firstMethod));
        $whenCase->setMethod(current($firstMethod), $action, $lastValue);
    }
461560
private function formatAction(Action $action)
    {
        $info = [
            'envelope' => 'JSON-RPC-2.0',
            'transport' => 'POST',
            'name' => $action->getName(),
            'description' => $action->getDescription(),
            'parameters' => []
        ];

        foreach ($action->getParameters() as $parameter) {
            $parameterInfo = [
                'name' => $parameter->getName(),
                'type' => $parameter->getType(),
                'description' => $parameter->getDescription(),
                'required' => $parameter->isRequired()
            ];

            if (!$parameter->isRequired()) {
                $parameterInfo['default'] = $parameter->getDefault();
            }

            $info['parameters'][] = $parameterInfo;
        }

        if ($action->getResponse()) {
            $response = $action->getResponse();

            $info['response'] = $response->toArray();
        }

        return $info;
    }
281370
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => true,
            'reference'     => null,
            'message'       => null,
            'test'          => false,
            'authorization' => null,
            'status'        => $response['status'],
            'errorCode'     => false,
            'type'          => $response['type'],
        ]);
    }
87041
protected function handleMultiBulkResponse(string $response): ?array
	{
		if($response === '*-1')
		{
			return null;
		}

		$data = [];

		$count = (int) substr($response, 1);

		for($i = 0; $i < $count; $i++)
		{
			$data[] = $this->getResponse();
		}

		return $data;
	}
575001
public function performAction($controller, $action) {
		// Replace namespace with directory separator
		$controllerFile = str_replace("\\", DIRECTORY_SEPARATOR, $controller);

		// Check if controller exists
		if ( false == is_file( $controllerLocation = APP . 'Controllers/' . $controllerFile . '.php' ) )
			throw new ControllerNotFoundException();

		// Include and init the controller
		$controllerClass = "\\Application\\Controllers\\{$controller}";
		$controllerObj = new $controllerClass($this);

		// Check if the action exists
		if ( 'Errors' != $controller && false == method_exists($controllerObj, $action.= "Action" ) )
			throw new ActionNotFoundException();
		// Check if the error display action exists
		elseif ( $controller == $this->defaultRoute['_controller'] && false == method_exists($controllerObj, $action = "display" . $action ) )
			throw new ErrorActionNotFoundException();

		// Run the action
		$data = $controllerObj->{$action}();

		// Data fetching
		if ( false === $controllerObj->__returnActionPerformed ):
			// Format returned data
			if ( false == is_array( $data ) )
				$data = (array) $data;

			// Start reflection for data loading
			$ref = new \ReflectionObject($controllerObj);
			$properties = $ref->getProperties(\ReflectionProperty::IS_PUBLIC);
			$controllerData = array();

			// Get public data
			foreach ( $properties as $property ):
				// Don't add internal variabels
				if ( '__returnActionPerformed' == $property->getName() )
					continue;

				// Add property to controller data
				$controllerData[$property->getName()] = $property->getValue($controllerObj);
			endforeach;

			// Merge data from controller and action
			$data = array_merge($controllerData, $data);
		endif;

		// Return the object
		return $data;
	}
311507
protected function addRouteMiddlewares(array $action)
    {
        foreach ([static::API_RATE_LIMIT_MIDDLEWARE, static::API_AUTH_MIDDLEWARE] as $middleware) {
            if (($key = array_search($middleware, $action['middleware'])) !== false) {
                unset($action['middleware'][$key]);
            }

            array_unshift($action['middleware'], $middleware);
        }

        return $action;
    }
934624
public function each(callable $action = null)
    {
        if ($action === null) {
            $each = call_user_func($this->each);
            if (!self::isIterable($each)) {
                throw new \RuntimeException("return value is not iterable object");
            }
            return $each;
        } else {
            $this->apply($action);
        }

        return null;
    }
240580
public function load(Action $action)
    {
        if (! is_null($this->argument)) {
            $this->argument->load($action);
        }
    }
59285
protected function convertToControllerAction($action)
    {
        if (is_string($action)) {
            $action = ['uses' => $action];
        }
        
        // Here we'll merge any group "uses" statement if necessary so that the action
        // has the proper clause for this property. Then we can simply set the name
        // of the controller on the action and return the action array for usage.
        if (! empty($this->groupStack)) {
            $action['uses'] = $this->prependGroupUses($action['uses']);
        }
        
        // Here we will set this controller name on the action array just so we always
        // have a copy of it for reference if we need it. This can be used while we
        // search for a controller name or do some other type of fetch operation.
        $action['controller'] = $action['uses'];
        
        return $action;
    }
116187
private function resolveResponseArray(array $response)
    {
        if ($count = count($response)) {
            if ($count === 1) {
                $response = $response[0];
            }
        }
        $this->firing[] = $response;

        return $response;
    }
1242067
public function callAction($action, $defaultAction = 'request') {
		if (method_exists($this, $action)) return $this->{$action}();
		else return $this->{$defaultAction}();
	}
738786
public static function each(array $arr, \Closure $action){
		foreach($arr as $k => $v){
			$action($v, $k);
		}
	}
339712
public function getReturnType($action)
    {
        if(isset($this->returnType[$action])){

            return $this->returnType[$action];
        }

        return false;
    }
655573
private JSONObject createTickerJsonObject(ArrayList<Long> tokens, String action) {
        JSONObject jobj = new JSONObject();
        try {
            JSONArray list = new JSONArray();
            for (int i = 0; i < tokens.size(); i++) {
                list.put(i, tokens.get(i));
            }
            jobj.put("v", list);
            jobj.put("a", action);
        }
        catch (JSONException e){
        }

        return jobj;
    }
634273
protected function _directMapping($action) {
		if (!method_exists($this, $action)) {
			return false;
		}

		$pass = (array)$this->_getRequest()->param('pass');
		$result = call_user_func_array([$this, $action], $pass);

		if ($result instanceof Response) {
			return $result;
		}

		return $this->getController()->render($action);
	}
1316309
function(actions) {
    var actionPromises = [];

    angular.forEach(actions, function(value) {
      var action = angular.isString(value) ? $injector.get(value) : $injector.invoke(value);
      actionPromises.push($q.when(action));
    });

    return $q.all(actionPromises);
  }
922080
protected function convertToControllerAction($action)
    {
        if (is_string($action)) {
            $action = ['uses' => $action];
        }

        // Here we'll merge any group "uses" statement if necessary so that the action
        // has the proper clause for this property. Then we can simply set the name
        // of the controller on the action and return the action array for usage.
        if (! empty($this->groupStack)) {
            $action['uses'] = $this->prependGroupNamespace($action['uses']);
        }

        // Here we will set this controller name on the action array just so we always
        // have a copy of it for reference if we need it. This can be used while we
        // search for a controller name or do some other type of fetch operation.
        $action['controller'] = $action['uses'];

        return $action;
    }