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 ( 2c30fa...9a0b48 )
by Cristian
02:30
created

CrudRouter::with()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 11
nc 4
nop 1
dl 0
loc 18
rs 8.8571
c 1
b 0
f 1
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