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

DingoGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 3 Features 0
Metric Value
wmc 7
c 4
b 3
f 0
lcom 1
cbo 3
dl 0
loc 80
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B processRoute() 0 26 3
A prepareMiddleware() 0 5 1
A callRoute() 0 10 1
A getUri() 0 4 1
A getMethods() 0 4 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