Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#230)
by Cristian
05:02 queued 02:27
created

CrudRouter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 36
nc 1
nop 3
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0

How to fix   Long Method   

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 Backpack\CRUD;
4
5
use Route;
6
7
class CrudRouter
8
{
9
    protected $extraRoutes = [];
10
11
    protected $name = null;
12
    protected $options = null;
13
    protected $controller = null;
14
15
    /**
16
     * Some CRUD routes should be registered no matter what.
17
     */
18
    public function __construct($name, $controller, $options)
19
    {
20
        $this->name = $name;
21
        $this->options = $options;
22
        $this->controller = $controller;
23
24
        // CRUD routes for core features
25
        Route::post($this->name.'/search', [
26
            'as' => 'crud.'.$this->name.'.search',
27
            'uses' => $this->controller.'@search',
28
        ]);
29
30
        Route::get($this->name.'/reorder', [
31
            'as' => 'crud.'.$this->name.'.reorder',
32
            'uses' => $this->controller.'@reorder',
33
        ]);
34
35
        Route::post($this->name.'/reorder', [
36
            'as' => 'crud.'.$this->name.'.save.reorder',
37
            'uses' => $this->controller.'@saveReorder',
38
        ]);
39
40
        Route::get($this->name.'/{id}/details', [
41
            'as' => 'crud.'.$this->name.'.showDetailsRow',
42
            'uses' => $this->controller.'@showDetailsRow',
43
        ]);
44
45
        Route::get($this->name.'/{id}/translate/{lang}', [
46
            'as' => 'crud.'.$this->name.'.translateItem',
47
            'uses' => $this->controller.'@translateItem',
48
        ]);
49
50
        Route::get($this->name.'/{id}/revisions', [
51
            'as' => 'crud.'.$this->name.'.listRevisions',
52
            'uses' => $this->controller.'@listRevisions',
53
        ]);
54
55
        Route::post($this->name.'/{id}/revisions/{revisionId}/restore', [
56
            'as' => 'crud.'.$this->name.'.restoreRevision',
57
            'uses' => $this->controller.'@restoreRevision',
58
        ]);
59
60
        $options_with_default_route_names = array_merge([
61
            'names' => [
62
                'index'     => 'crud.'.$this->name.'.index',
63
                'create'    => 'crud.'.$this->name.'.create',
64
                'store'     => 'crud.'.$this->name.'.store',
65
                'edit'      => 'crud.'.$this->name.'.edit',
66
                'update'    => 'crud.'.$this->name.'.update',
67
                'show'      => 'crud.'.$this->name.'.show',
68
                'destroy'   => 'crud.'.$this->name.'.destroy',
69
            ],
70
        ], $this->options);
71
72
        Route::resource($this->name, $this->controller, $options_with_default_route_names);
73
    }
74
75
    /**
76
     * Call other methods in this class, that register extra routes.
77
     *
78
     * @param  [type] $injectables [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
79
     * @return [type]              [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
80
     */
81
    public function with($injectables)
82
    {
83
        if (is_string($injectables)) {
84
            $this->extraRoutes[] = 'with'.ucwords($injectables);
85
        } elseif (is_array($injectables)) {
86
            foreach ($injectables as $injectable) {
87
                $this->extraRoutes[] = 'with'.ucwords($injectable);
88
            }
89
        } else {
90
            $reflection = new \ReflectionFunction($injectables);
91
92
            if ($reflection->isClosure()) {
93
                $this->extraRoutes[] = $injectables;
94
            }
95
        }
96
97
        return $this->registerExtraRoutes();
98
    }
99
100
    /**
101
     * TODO
102
     * Give developers the ability to unregister a route.
103
     */
104
    // public function without($injectables) {}
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
106
    /**
107
     * Register the routes that were passed using the "with" syntax.
108
     */
109
    private function registerExtraRoutes()
110
    {
111
        foreach ($this->extraRoutes as $route) {
112
            if (is_string($route)) {
113
                $this->{$route}();
114
            } else {
115
                $route();
116
            }
117
        }
118
    }
119
120
    public function __call($method, $parameters = null)
121
    {
122
        if (method_exists($this, $method)) {
123
            $this->{$method}($parameters);
124
        }
125
    }
126
}
127