Test Setup Failed
Branch feature/job-builder/work-env-r... (305963)
by Grant
52:57 queued 34:52
created

SkillCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
use Illuminate\Support\Facades\App;
7
use App\Models\Lookup\SkillType;
8
// Validation.
9
use App\Http\Requests\SkillCrudRequest as StoreRequest;
10
use App\Http\Requests\SkillCrudRequest as UpdateRequest;
11
12
class SkillCrudController extends CrudController
13
{
14
    /**
15
     * Prepare the admin interface by setting the associated
16
     * model, setting the route, and adding custom columns/fields.
17
     *
18
     * @return void
19
     */
20 1
    public function setup() : void
21
    {
22
        // Workaround for how the unique_translation validation
23
        // works in App\Http\Requests\SkillCrudRequest.
24 1
        $locale = 'en';
25 1
        if (null !== $this->request->input('locale')) {
26
            $locale = $this->request->input('locale');
27
        }
28 1
        App::setLocale($locale);
29
30
        // Eloquent model to associate with this collection
31
        // of views and controller actions.
32 1
        $this->crud->setModel('App\Models\Skill');
33
        // Custom backpack route.
34 1
        $this->crud->setRoute('admin/skill');
35
        // Custom strings to display within the backpack UI,
36
        // things like Create Skill, Delete Skills, etc.
37 1
        $this->crud->setEntityNameStrings('Skill', 'Skills');
38
39
        // Add custom columns to the Skill index view.
40 1
        $this->crud->addColumn([
41 1
            'name' => 'name',
42 1
            'type' => 'text',
43 1
            'label' => 'Name',
44
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
45
                $query->orWhere('name->' . $locale, 'like', "%$searchTerm%");
46 1
            },
47
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
48
                return $query->orderBy('name->' . $locale, $columnDirection)->select('*');
49 1
            }
50
        ]);
51 1
        $this->crud->addColumn([
52 1
            'name' => 'description',
53 1
            'type' => 'text',
54 1
            'label' => 'Description',
55
            'searchLogic' => function ($query, $column, $searchTerm) use ($locale) : void {
56
                $query->orWhere('description->' . $locale, 'like', "%$searchTerm%");
57 1
            },
58
            'orderable' => false,
59
        ]);
60 1
        $this->crud->addColumn([
61 1
            'name' => 'skill_type.name',
62 1
            'type' => 'text',
63 1
            'label' => 'Type',
64
            'orderable' => true,
65
            'orderLogic' => function ($query, $column, $columnDirection) use ($locale) {
66
                return $query->orderBy('skill_type_id', $columnDirection)->select('*');
67 1
            }
68
        ]);
69
70
        // Add custom fields to the create/update views.
71 1
        $this->crud->addField([
72 1
            'name' => 'name',
73
            'type' => 'text',
74
            'label' => 'Name',
75
        ]);
76 1
        $this->crud->addField([
77 1
            'name' => 'description',
78
            'type' => 'textarea',
79
            'label' => 'Description'
80
        ]);
81 1
        $this->crud->addField([
82 1
            'name' => 'skill_type_id',
83 1
            'label' => 'Type',
84 1
            'type' => 'select_from_array',
85 1
            'options' => SkillType::all()->pluck('name', 'id')->toArray(),
86
            'allow_null' => false,
87
        ]);
88 1
    }
89
90
    /**
91
     * Action for creating a new Skill in the database.
92
     *
93
     * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request.
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function store(StoreRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98
        return parent::storeCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (storeCrud() instead of store()). Are you sure this is correct? If so, you might want to change this to $this->storeCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
99
    }
100
101
    /**
102
     * Action for creating a new Skill in the database.
103
     *
104
     * @param  \App\Http\Requests\SkillCrudRequest $request Incoming form request.
105
     * @return \Illuminate\Http\RedirectResponse
106
     */
107
    public function update(UpdateRequest $request) // phpcs:ignore
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
    {
109
        return parent::updateCrud();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (updateCrud() instead of update()). Are you sure this is correct? If so, you might want to change this to $this->updateCrud().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
110
    }
111
}
112