Completed
Push — master ( 12abac...a4ad23 )
by Marcel
05:10
created

DingoGenerator::getMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
nc 1
cc 1
eloc 2
nop 1
1
<?php
2
3
namespace Mpociot\ApiDoc\Generators;
4
5
use Exception;
6
7
class DingoGenerator extends AbstractGenerator
8
{
9
    /**
10
     * @param \Illuminate\Routing\Route $route
11
     * @param array $bindings
12
     * @param array $headers
13
     * @param bool $withResponse
14
     *
15
     * @return array
16
     */
17
    public function processRoute($route, $bindings = [], $headers = [], $withResponse = true)
18
    {
19
        $response = '';
20
21
        if ($withResponse) {
22
            try {
23
                $response = $this->getRouteResponse($route, $bindings, $headers);
24
            } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
25
            }
26
        }
27
28
        $routeAction = $route->getAction();
29
        $routeGroup = $this->getRouteGroup($routeAction['uses']);
30
        $routeDescription = $this->getRouteDescription($routeAction['uses']);
31
32
        return $this->getParameters([
33
            'id' => md5($route->uri().':'.implode($route->getMethods())),
0 ignored issues
show
Bug introduced by
The method getMethods() does not exist on Illuminate\Routing\Route. Did you maybe mean methods()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
            'resource' => $routeGroup,
35
            'title' => $routeDescription['short'],
36
            'description' => $routeDescription['long'],
37
            'methods' => $route->getMethods(),
0 ignored issues
show
Bug introduced by
The method getMethods() does not exist on Illuminate\Routing\Route. Did you maybe mean methods()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38
            'uri' => $route->uri(),
39
            'parameters' => [],
40
            'response' => $response,
41
        ], $routeAction, $bindings);
42
    }
43
44
    /**
45
     * Prepares / Disables route middlewares.
46
     *
47
     * @param  bool $disable
48
     *
49
     * @return  void
50
     */
51
    public function prepareMiddleware($disable = true)
52
    {
53
        // Not needed by Dingo
54
        return false;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
61
    {
62
        $dispatcher = app('Dingo\Api\Dispatcher')->raw();
63
64
        collect($server)->map(function ($key, $value) use ($dispatcher) {
65
            $dispatcher->header($key, $value);
66
        });
67
68
        return call_user_func_array([$dispatcher, strtolower($method)], [$uri]);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getUri($route)
75
    {
76
        return $route->uri();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getMethods($route)
83
    {
84
        return $route->getMethods();
85
    }
86
}
87