Completed
Push — master ( 6258b7...7a53af )
by
unknown
11s
created

LaravelGenerator::callRoute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 7
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
     * @param Route $route
13
     *
14
     * @return mixed
15
     */
16
    public function getUri(Route $route)
17
    {
18
        if (version_compare(app()->version(), '5.4', '<')) {
19
            return $route->getUri();
0 ignored issues
show
Bug introduced by
The method getUri() does not seem to exist on object<Illuminate\Routing\Route>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
20
        }
21
22
        return $route->uri();
23
    }
24
25
    /**
26
     * @param Route $route
27
     *
28
     * @return mixed
29
     */
30
    public function getMethods(Route $route)
31
    {
32
        if (version_compare(app()->version(), '5.4', '<')) {
33
            $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...
34
        } else {
35
            $methods = $route->methods();
36
        }
37
38
        return array_diff($methods, ['HEAD']);
39
    }
40
41
    /**
42
     * Prepares / Disables route middlewares.
43
     *
44
     * @param  bool $disable
0 ignored issues
show
Bug introduced by
There is no parameter named $disable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     *
46
     * @return  void
47
     */
48
    public function prepareMiddleware($enable = true)
49
    {
50
        App::instance('middleware.disable', ! $enable);
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...
51
    }
52
53
    /**
54
     * Call the given URI and return the Response.
55
     *
56
     * @param  string  $method
57
     * @param  string  $uri
58
     * @param  array  $parameters
59
     * @param  array  $cookies
60
     * @param  array  $files
61
     * @param  array  $server
62
     * @param  string  $content
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
67
    {
68
        $server = collect([
69
            'CONTENT_TYPE' => 'application/json',
70
            'Accept' => 'application/json',
71
        ])->merge($server)->toArray();
72
73
        $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...
74
            $uri, $method, $parameters,
75
            $cookies, $files, $this->transformHeadersToServerVars($server), $content
76
        );
77
78
        $kernel = App::make('Illuminate\Contracts\Http\Kernel');
79
        $response = $kernel->handle($request);
80
81
        $kernel->terminate($request, $response);
82
83
        return $response;
84
    }
85
}
86