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 (#35)
by Cristian
04:55 queued 22s
created

ArticleCrudController::setup()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 103

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 103
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 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\NewsCRUD\app\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Backpack\NewsCRUD\app\Http\Requests\ArticleRequest;
7
8
class ArticleCrudController extends CrudController
9
{
10
    use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
11
    use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
12
    use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
13
    use \Backpack\CRUD\app\Http\Controllers\Operations\CloneOperation;
14
    use \Backpack\CRUD\app\Http\Controllers\Operations\BulkCloneOperation;
15
    use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
16
    use \Backpack\CRUD\app\Http\Controllers\Operations\BulkDeleteOperation;
17
18
    public function setup()
19
    {
20
        /*
21
        |--------------------------------------------------------------------------
22
        | BASIC CRUD INFORMATION
23
        |--------------------------------------------------------------------------
24
        */
25
        $this->crud->setModel("Backpack\NewsCRUD\app\Models\Article");
26
        $this->crud->setRoute(config('backpack.base.route_prefix', 'admin').'/article');
27
        $this->crud->setEntityNameStrings('article', 'articles');
28
29
        /*
30
        |--------------------------------------------------------------------------
31
        | LIST OPERATION
32
        |--------------------------------------------------------------------------
33
        */
34
        $this->crud->operation('list', function () {
0 ignored issues
show
Bug introduced by
The method operation() does not exist on Backpack\CRUD\CrudPanel. Did you maybe mean doingListOperation()?

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...
35
            $this->crud->addColumn('title');
36
            $this->crud->addColumn([
37
                'name' => 'date',
38
                'label' => 'Date',
39
                'type' => 'date',
40
            ]);
41
            $this->crud->addColumn('status');
42
            $this->crud->addColumn([
43
                'name' => 'featured',
44
                'label' => 'Featured',
45
                'type' => 'check',
46
            ]);
47
            $this->crud->addColumn([
48
                'label' => 'Category',
49
                'type' => 'select',
50
                'name' => 'category_id',
51
                'entity' => 'category',
52
                'attribute' => 'name',
53
            ]);
54
        });
55
56
        /*
57
        |--------------------------------------------------------------------------
58
        | CREATE & UPDATE OPERATIONS
59
        |--------------------------------------------------------------------------
60
        */
61
        $this->crud->operation(['create', 'update'], function () {
0 ignored issues
show
Bug introduced by
The method operation() does not exist on Backpack\CRUD\CrudPanel. Did you maybe mean doingListOperation()?

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...
62
            $this->crud->setValidation(ArticleRequest::class);
63
64
            $this->crud->addField([
65
                'name' => 'title',
66
                'label' => 'Title',
67
                'type' => 'text',
68
                'placeholder' => 'Your title here',
69
            ]);
70
            $this->crud->addField([
71
                'name' => 'slug',
72
                'label' => 'Slug (URL)',
73
                'type' => 'text',
74
                'hint' => 'Will be automatically generated from your title, if left empty.',
75
                // 'disabled' => 'disabled'
76
            ]);
77
            $this->crud->addField([
78
                'name' => 'date',
79
                'label' => 'Date',
80
                'type' => 'date',
81
                'default' => date('Y-m-d'),
82
            ]);
83
            $this->crud->addField([
84
                'name' => 'content',
85
                'label' => 'Content',
86
                'type' => 'ckeditor',
87
                'placeholder' => 'Your textarea text here',
88
            ]);
89
            $this->crud->addField([
90
                'name' => 'image',
91
                'label' => 'Image',
92
                'type' => 'browse',
93
            ]);
94
            $this->crud->addField([
95
                'label' => 'Category',
96
                'type' => 'select2',
97
                'name' => 'category_id',
98
                'entity' => 'category',
99
                'attribute' => 'name',
100
            ]);
101
            $this->crud->addField([
102
                'label' => 'Tags',
103
                'type' => 'select2_multiple',
104
                'name' => 'tags', // the method that defines the relationship in your Model
105
                'entity' => 'tags', // the method that defines the relationship in your Model
106
                'attribute' => 'name', // foreign key attribute that is shown to user
107
                'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
108
            ]);
109
            $this->crud->addField([
110
                'name' => 'status',
111
                'label' => 'Status',
112
                'type' => 'enum',
113
            ]);
114
            $this->crud->addField([
115
                'name' => 'featured',
116
                'label' => 'Featured item',
117
                'type' => 'checkbox',
118
            ]);
119
        });
120
    }
121
}
122