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

DingoGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 4
dl 24
loc 52
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B processRoute() 24 24 2
A callRoute() 0 4 1
A getUri() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 DingoGenerator extends AbstractGenerator
10
{
11
12
    /**
13
     * @param  \Illuminate\Routing\Route $route
14
     * @param array $bindings
15
     *
16
     * @return array
17
     */
18 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...
19
    {
20
        $response = $this->getRouteResponse($route, $bindings);
21
22
        $routeAction = $route->getAction();
23
        $routeGroup = $this->getRouteGroup($routeAction['uses']);
24
        $routeDescription = $this->getRouteDescription($routeAction['uses']);
25
        
26
        if ($response->headers->get('Content-Type') === 'application/json') {
27
            $content = json_encode(json_decode($response->getContent()), JSON_PRETTY_PRINT);
28
        } else {
29
            $content = $response->getContent();
30
        }
31
32
        return $this->getParameters([
33
            'resource'    => $routeGroup,
34
            'title' => $routeDescription['short'],
35
            'description' => $routeDescription['long'],
36
            'methods' => $route->getMethods(),
37
            'uri' => $route->getUri(),
38
            'parameters' => [],
39
            'response' => $content,
40
        ], $routeAction);
41
    }
42
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function callRoute($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
48
    {
49
        return call_user_func_array([app('Dingo\Api\Dispatcher'), strtolower($method)], [$uri]);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function getUri(Route $route)
56
    {
57
        return $route->uri();
58
    }
59
    
60
}