Completed
Push — master ( 303c41...204eee )
by Marcel
02:19
created

LaravelGenerator::getUri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Mpociot\ApiDoc\Generators;
4
5
use Illuminate\Routing\Route;
6
use Illuminate\Support\Facades\App;
7
use Illuminate\Support\Facades\Request;
8
9
class LaravelGenerator extends AbstractGenerator
10
{
11
12
    /**
13
     * @param Route $route
14
     * @return mixed
15
     */
16
    protected function getUri(Route $route)
17
    {
18
        return $route->getUri();
19
    }
20
21
    /**
22
     * @param  \Illuminate\Routing\Route $route
23
     * @param array $bindings
24
     *
25
     * @return array
26
     */
27 View Code Duplication
    public function processRoute(Route $route, $bindings = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $response = $this->getRouteResponse($route, $bindings);
30
        
31
        $routeAction = $route->getAction();
32
        $routeGroup = $this->getRouteGroup($routeAction['uses']);
33
        $routeDescription = $this->getRouteDescription($routeAction['uses']);
34
        
35
        if ($response->headers->get('Content-Type') === 'application/json') {
36
            $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
37
        } else {
38
            $content = $response->getContent();
39
        }
40
41
        return $this->getParameters([
42
            'resource'    => $routeGroup,
43
            'title' => $routeDescription['short'],
44
            'description' => $routeDescription['long'],
45
            'methods' => $route->getMethods(),
46
            'uri' => $route->getUri(),
47
            'parameters' => [],
48
            'response' => $content,
49
        ], $routeAction);
50
    }
51
52
    /**
53
     * Call the given URI and return the Response.
54
     *
55
     * @param  string  $method
56
     * @param  string  $uri
57
     * @param  array  $parameters
58
     * @param  array  $cookies
59
     * @param  array  $files
60
     * @param  array  $server
61
     * @param  string  $content
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
66
    {
67
        $kernel = App::make('Illuminate\Contracts\Http\Kernel');
68
        App::instance('middleware.disable', true);
0 ignored issues
show
Bug introduced by
The method instance() does not exist on Illuminate\Support\Facades\App. Did you maybe mean clearResolvedInstance()?

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...
69
70
        $server = [
71
            'CONTENT_TYPE' => 'application/json',
72
            'Accept' => 'application/json',
73
        ];
74
75
        $request = Request::create(
0 ignored issues
show
Bug introduced by
The method create() does not exist on Illuminate\Support\Facades\Request. Did you maybe mean createFreshMockInstance()?

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...
76
            $uri, $method, $parameters,
77
            $cookies, $files, $this->transformHeadersToServerVars($server), $content
78
        );
79
80
        $response = $kernel->handle($request);
81
82
        $kernel->terminate($request, $response);
83
84
        return $response;
85
    }
86
    
87
}