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 ( 0b178a...48f066 )
by Cristian
10:06 queued 08:57
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
    use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
18
19
    public function setup()
20
    {
21
        /*
22
        |--------------------------------------------------------------------------
23
        | BASIC CRUD INFORMATION
24
        |--------------------------------------------------------------------------
25
        */
26
        $this->crud->setModel("Backpack\NewsCRUD\app\Models\Article");
27
        $this->crud->setRoute(config('backpack.base.route_prefix', 'admin').'/article');
28
        $this->crud->setEntityNameStrings('article', 'articles');
29
30
        /*
31
        |--------------------------------------------------------------------------
32
        | LIST OPERATION
33
        |--------------------------------------------------------------------------
34
        */
35
        $this->crud->operation('list', function () {
36
            $this->crud->addColumn('title');
37
            $this->crud->addColumn([
38
                'name' => 'date',
39
                'label' => 'Date',
40
                'type' => 'date',
41
            ]);
42
            $this->crud->addColumn('status');
43
            $this->crud->addColumn([
44
                'name' => 'featured',
45
                'label' => 'Featured',
46
                'type' => 'check',
47
            ]);
48
            $this->crud->addColumn([
49
                'label' => 'Category',
50
                'type' => 'select',
51
                'name' => 'category_id',
52
                'entity' => 'category',
53
                'attribute' => 'name',
54
            ]);
55
        });
56
57
        /*
58
        |--------------------------------------------------------------------------
59
        | CREATE & UPDATE OPERATIONS
60
        |--------------------------------------------------------------------------
61
        */
62
        $this->crud->operation(['create', 'update'], function () {
63
            $this->crud->setValidation(ArticleRequest::class);
64
65
            $this->crud->addField([
66
                'name' => 'title',
67
                'label' => 'Title',
68
                'type' => 'text',
69
                'placeholder' => 'Your title here',
70
            ]);
71
            $this->crud->addField([
72
                'name' => 'slug',
73
                'label' => 'Slug (URL)',
74
                'type' => 'text',
75
                'hint' => 'Will be automatically generated from your title, if left empty.',
76
                // 'disabled' => 'disabled'
77
            ]);
78
            $this->crud->addField([
79
                'name' => 'date',
80
                'label' => 'Date',
81
                'type' => 'date',
82
                'default' => date('Y-m-d'),
83
            ]);
84
            $this->crud->addField([
85
                'name' => 'content',
86
                'label' => 'Content',
87
                'type' => 'ckeditor',
88
                'placeholder' => 'Your textarea text here',
89
            ]);
90
            $this->crud->addField([
91
                'name' => 'image',
92
                'label' => 'Image',
93
                'type' => 'browse',
94
            ]);
95
            $this->crud->addField([
96
                'label' => 'Category',
97
                'type' => 'select2',
98
                'name' => 'category_id',
99
                'entity' => 'category',
100
                'attribute' => 'name',
101
            ]);
102
            $this->crud->addField([
103
                'label' => 'Tags',
104
                'type' => 'select2_multiple',
105
                'name' => 'tags', // the method that defines the relationship in your Model
106
                'entity' => 'tags', // the method that defines the relationship in your Model
107
                'attribute' => 'name', // foreign key attribute that is shown to user
108
                'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
109
            ]);
110
            $this->crud->addField([
111
                'name' => 'status',
112
                'label' => 'Status',
113
                'type' => 'enum',
114
            ]);
115
            $this->crud->addField([
116
                'name' => 'featured',
117
                'label' => 'Featured item',
118
                'type' => 'checkbox',
119
            ]);
120
        });
121
    }
122
}
123