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
Push — master ( f35a35...781975 )
by Cristian
04:48
created

CrudRouter::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
    public function __construct($name, $controller, $options)
16
    {
17
        $this->name = $name;
18
        $this->controller = $controller;
19
        $this->options = $options;
20
21
        // CRUD routes for core features
22
        Route::post($this->name.'/search', [
23
            'as' => 'crud.'.$this->name.'.search',
24
            'uses' => $this->controller.'@search',
25
        ]);
26
27
        Route::get($this->name.'/reorder', [
28
            'as' => 'crud.'.$this->name.'.reorder',
29
            'uses' => $this->controller.'@reorder',
30
        ]);
31
32
        Route::post($this->name.'/reorder', [
33
            'as' => 'crud.'.$this->name.'.save.reorder',
34
            'uses' => $this->controller.'@saveReorder',
35
        ]);
36
37
        Route::get($this->name.'/{id}/details', [
38
            'as' => 'crud.'.$this->name.'.showDetailsRow',
39
            'uses' => $this->controller.'@showDetailsRow',
40
        ]);
41
42
        Route::get($this->name.'/{id}/translate/{lang}', [
43
            'as' => 'crud.'.$this->name.'.translateItem',
44
            'uses' => $this->controller.'@translateItem',
45
        ]);
46
47
        Route::get($this->name.'/{id}/revisions', [
48
            'as' => 'crud.'.$this->name.'.listRevisions',
49
            'uses' => $this->controller.'@listRevisions',
50
        ]);
51
52
        Route::post($this->name.'/{id}/revisions/{revisionId}/restore', [
53
            'as' => 'crud.'.$this->name.'.restoreRevision',
54
            'uses' => $this->controller.'@restoreRevision',
55
        ]);
56
    }
57
58
    /**
59
     * The CRUD resource needs to be registered after all the other routes.
60
     */
61
    public function __destruct()
62
    {
63
        $options_with_default_route_names = array_merge([
64
            'names' => [
65
                'index'     => 'crud.'.$this->name.'.index',
66
                'create'    => 'crud.'.$this->name.'.create',
67
                'store'     => 'crud.'.$this->name.'.store',
68
                'edit'      => 'crud.'.$this->name.'.edit',
69
                'update'    => 'crud.'.$this->name.'.update',
70
                'show'      => 'crud.'.$this->name.'.show',
71
                'destroy'   => 'crud.'.$this->name.'.destroy',
72
            ],
73
        ], $this->options);
74
75
        Route::resource($this->name, $this->controller, $options_with_default_route_names);
76
    }
77
78
    /**
79
     * Call other methods in this class, that register extra routes.
80
     *
81
     * @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...
82
     * @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...
83
     */
84
    public function with($injectables)
85
    {
86
        if (is_string($injectables)) {
87
            $this->extraRoutes[] = 'with'.ucwords($injectables);
88
        } elseif (is_array($injectables)) {
89
            foreach ($injectables as $injectable) {
90
                $this->extraRoutes[] = 'with'.ucwords($injectable);
91
            }
92
        } else {
93
            $reflection = new \ReflectionFunction($injectables);
94
95
            if ($reflection->isClosure()) {
96
                $this->extraRoutes[] = $injectables;
97
            }
98
        }
99
100
        return $this->registerExtraRoutes();
101
    }
102
103
    /**
104
     * TODO
105
     * Give developers the ability to unregister a route.
106
     */
107
    // 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...
108
109
    /**
110
     * Register the routes that were passed using the "with" syntax.
111
     */
112
    private function registerExtraRoutes()
113
    {
114
        foreach ($this->extraRoutes as $route) {
115
            if (is_string($route)) {
116
                $this->{$route}();
117
            } else {
118
                $route();
119
            }
120
        }
121
    }
122
123
    public function __call($method, $parameters = null)
124
    {
125
        if (method_exists($this, $method)) {
126
            $this->{$method}($parameters);
127
        }
128
    }
129
}
130