We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 3 |
| Paths | 1 |
| Total Lines | 141 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 20 | public function setup() |
||
| 21 | { |
||
| 22 | /* |
||
| 23 | |-------------------------------------------------------------------------- |
||
| 24 | | BASIC CRUD INFORMATION |
||
| 25 | |-------------------------------------------------------------------------- |
||
| 26 | */ |
||
| 27 | $this->crud->setModel(\Backpack\NewsCRUD\app\Models\Article::class); |
||
| 28 | $this->crud->setRoute(config('backpack.base.route_prefix', 'admin').'/article'); |
||
| 29 | $this->crud->setEntityNameStrings('article', 'articles'); |
||
| 30 | |||
| 31 | /* |
||
| 32 | |-------------------------------------------------------------------------- |
||
| 33 | | LIST OPERATION |
||
| 34 | |-------------------------------------------------------------------------- |
||
| 35 | */ |
||
| 36 | $this->crud->operation('list', function () { |
||
| 37 | $this->crud->addColumn('title'); |
||
| 38 | $this->crud->addColumn([ |
||
| 39 | 'name' => 'date', |
||
| 40 | 'label' => 'Date', |
||
| 41 | 'type' => 'date', |
||
| 42 | ]); |
||
| 43 | $this->crud->addColumn('status'); |
||
| 44 | $this->crud->addColumn([ |
||
| 45 | 'name' => 'featured', |
||
| 46 | 'label' => 'Featured', |
||
| 47 | 'type' => 'check', |
||
| 48 | ]); |
||
| 49 | $this->crud->addColumn([ |
||
| 50 | 'label' => 'Category', |
||
| 51 | 'type' => 'select', |
||
| 52 | 'name' => 'category_id', |
||
| 53 | 'entity' => 'category', |
||
| 54 | 'attribute' => 'name', |
||
| 55 | 'wrapper' => [ |
||
| 56 | 'href' => function ($crud, $column, $entry, $related_key) { |
||
| 57 | return backpack_url('category/'.$related_key.'/show'); |
||
| 58 | }, |
||
| 59 | ], |
||
| 60 | ]); |
||
| 61 | $this->crud->addColumn('tags'); |
||
| 62 | |||
| 63 | $this->crud->addFilter([ // select2 filter |
||
| 64 | 'name' => 'category_id', |
||
| 65 | 'type' => 'select2', |
||
| 66 | 'label'=> 'Category', |
||
| 67 | ], function () { |
||
| 68 | return \Backpack\NewsCRUD\app\Models\Category::all()->keyBy('id')->pluck('name', 'id')->toArray(); |
||
| 69 | }, function ($value) { // if the filter is active |
||
| 70 | $this->crud->addClause('where', 'category_id', $value); |
||
| 71 | }); |
||
| 72 | |||
| 73 | $this->crud->addFilter([ // select2_multiple filter |
||
| 74 | 'name' => 'tags', |
||
| 75 | 'type' => 'select2_multiple', |
||
| 76 | 'label'=> 'Tags', |
||
| 77 | ], function () { |
||
| 78 | return \Backpack\NewsCRUD\app\Models\Tag::all()->keyBy('id')->pluck('name', 'id')->toArray(); |
||
| 79 | }, function ($values) { // if the filter is active |
||
| 80 | $this->crud->query = $this->crud->query->whereHas('tags', function ($q) use ($values) { |
||
| 81 | foreach (json_decode($values) as $key => $value) { |
||
| 82 | if ($key == 0) { |
||
| 83 | $q->where('tags.id', $value); |
||
| 84 | } else { |
||
| 85 | $q->orWhere('tags.id', $value); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | }); |
||
| 89 | }); |
||
| 90 | }); |
||
| 91 | |||
| 92 | /* |
||
| 93 | |-------------------------------------------------------------------------- |
||
| 94 | | CREATE & UPDATE OPERATIONS |
||
| 95 | |-------------------------------------------------------------------------- |
||
| 96 | */ |
||
| 97 | $this->crud->operation(['create', 'update'], function () { |
||
| 98 | $this->crud->setValidation(ArticleRequest::class); |
||
| 99 | |||
| 100 | $this->crud->addField([ |
||
| 101 | 'name' => 'title', |
||
| 102 | 'label' => 'Title', |
||
| 103 | 'type' => 'text', |
||
| 104 | 'placeholder' => 'Your title here', |
||
| 105 | ]); |
||
| 106 | $this->crud->addField([ |
||
| 107 | 'name' => 'slug', |
||
| 108 | 'label' => 'Slug (URL)', |
||
| 109 | 'type' => 'text', |
||
| 110 | 'hint' => 'Will be automatically generated from your title, if left empty.', |
||
| 111 | // 'disabled' => 'disabled' |
||
| 112 | ]); |
||
| 113 | $this->crud->addField([ |
||
| 114 | 'name' => 'date', |
||
| 115 | 'label' => 'Date', |
||
| 116 | 'type' => 'date', |
||
| 117 | 'default' => date('Y-m-d'), |
||
| 118 | ]); |
||
| 119 | $this->crud->addField([ |
||
| 120 | 'name' => 'content', |
||
| 121 | 'label' => 'Content', |
||
| 122 | 'type' => 'ckeditor', |
||
| 123 | 'placeholder' => 'Your textarea text here', |
||
| 124 | ]); |
||
| 125 | $this->crud->addField([ |
||
| 126 | 'name' => 'image', |
||
| 127 | 'label' => 'Image', |
||
| 128 | 'type' => 'browse', |
||
| 129 | ]); |
||
| 130 | $this->crud->addField([ |
||
| 131 | 'label' => 'Category', |
||
| 132 | 'type' => 'relationship', |
||
| 133 | 'name' => 'category_id', |
||
| 134 | 'entity' => 'category', |
||
| 135 | 'attribute' => 'name', |
||
| 136 | 'inline_create' => true, |
||
| 137 | 'ajax' => true, |
||
| 138 | ]); |
||
| 139 | $this->crud->addField([ |
||
| 140 | 'label' => 'Tags', |
||
| 141 | 'type' => 'relationship', |
||
| 142 | 'name' => 'tags', // the method that defines the relationship in your Model |
||
| 143 | 'entity' => 'tags', // the method that defines the relationship in your Model |
||
| 144 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 145 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
||
| 146 | 'inline_create' => ['entity' => 'tag'], |
||
| 147 | 'ajax' => true, |
||
| 148 | ]); |
||
| 149 | $this->crud->addField([ |
||
| 150 | 'name' => 'status', |
||
| 151 | 'label' => 'Status', |
||
| 152 | 'type' => 'enum', |
||
| 153 | ]); |
||
| 154 | $this->crud->addField([ |
||
| 155 | 'name' => 'featured', |
||
| 156 | 'label' => 'Featured item', |
||
| 157 | 'type' => 'checkbox', |
||
| 158 | ]); |
||
| 159 | }); |
||
| 160 | } |
||
| 161 | |||
| 180 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.