protected function orderParameters($parameters, $template)
    {
        foreach ($parameters as $key => $value) {
            // if a parameter appears to be a nested type
            if (is_array($value) && !empty($value) && !isset($value[0])) {
                $parameters[$key] = $this->orderParameters($parameters[$key], $template[$key]);
            }
        }

        $defaults = array();

        foreach ($template as $key => $type) {
            $defaults[$key] = null;
        }

        $parameters = array_merge(
            $defaults,
            $parameters
        );

        // ensure there are no extra parameters
        $parameters = array_intersect_key($parameters, $template);

        return $parameters;
    }