Completed
Pull Request — master (#323)
by
unknown
01:31
created

LaravelGenerator::getTransformerResponse()   F

Complexity

Conditions 19
Paths 575

Size

Total Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 0.9402
c 0
b 0
f 0
cc 19
nc 575
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 getDomain($route)
17
    {
18
        return $route->domain();
19
    }
20
21
    /**
22
     * @param Route $route
23
     *
24
     * @return mixed
25
     */
26
    public function getUri($route)
27
    {
28
        if (version_compare(app()->version(), '5.4', '<')) {
29
            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...
30
        }
31
32
        return $route->uri();
33
    }
34
35
    /**
36
     * @param Route $route
37
     *
38
     * @return mixed
39
     */
40
    public function getMethods($route)
41
    {
42
        if (version_compare(app()->version(), '5.4', '<')) {
43
            $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...
44
        } else {
45
            $methods = $route->methods();
46
        }
47
48
        return array_diff($methods, ['HEAD']);
49
    }
50
51
    /**
52
     * Prepares / Disables route middlewares.
53
     *
54
     * @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...
55
     *
56
     * @return  void
57
     */
58
    public function prepareMiddleware($enable = true)
59
    {
60
        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...
61
    }
62
63
    /**
64
     * Call the given URI and return the Response.
65
     *
66
     * @param  string  $method
67
     * @param  string  $uri
68
     * @param  array  $parameters
69
     * @param  array  $cookies
70
     * @param  array  $files
71
     * @param  array  $server
72
     * @param  string  $content
73
     *
74
     * @return \Illuminate\Http\Response
75
     */
76
    public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
77
    {
78
        $server = collect([
79
            'CONTENT_TYPE' => 'application/json',
80
            'Accept' => 'application/json',
81
        ])->merge($server)->toArray();
82
83
        $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...
84
            $uri, $method, $parameters,
85
            $cookies, $files, $this->transformHeadersToServerVars($server), $content
86
        );
87
88
        $kernel = App::make('Illuminate\Contracts\Http\Kernel');
89
        $response = $kernel->handle($request);
90
91
        $kernel->terminate($request, $response);
92
93
        return $response;
94
    }
95
}
96