Test Failed
Push — master ( 02a63f...ddb4ba )
by Oliver
05:18
created

DocumentCrudController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Webfactor\Laravel\Backpack\Documents\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
use Webfactor\Laravel\Backpack\Documents\Requests\DocumentRequest as StoreRequest;
8
use Webfactor\Laravel\Backpack\Documents\Requests\DocumentRequest as UpdateRequest;
9
10
class DocumentCrudController extends CrudController
11
{
12
    public function setup()
13
    {
14
        /*
15
        |--------------------------------------------------------------------------
16
        | BASIC CRUD INFORMATION
17
        |--------------------------------------------------------------------------
18
        */
19
        $this->crud->setModel(config('webfactor.documents.model_class'));
20
        $this->crud->setRoute(config('webfactor.documents.backend.route_prefix').'/'.config('webfactor.documents.backend.route'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
21
        $this->crud->setEntityNameStrings(trans('webfactor::documents.entity_name_singular'),
22
            trans('webfactor::documents.entity_name_plural'));
23
24
        /*
25
        |--------------------------------------------------------------------------
26
        | BASIC CRUD INFORMATION
27
        |--------------------------------------------------------------------------
28
        */
29
30
        // ------ CRUD FIELDS
31
32
        $this->crud->addField([
33
            'name'  => 'type',
34
            'label' => 'Dokumentenart',
35
            'type'  => 'select_from_array',
36
            'options' => $this->getTypeOptions(),
37
            'allows_null' => false,
38
            'allows_multiple' => false
39
        ]);
40
41
        $this->crud->addField([
42
            'name' => 'title',
43
            'label' => trans('webfactor::documents.title')
44
        ]);
45
        
46
        $this->crud->addField([
47
            'name' => 'body',
48
            'label' => trans('webfactor::documents.body'),
49
            'type' => $this->bodyFieldType()
50
        ]);
51
52
        // ------ CRUD COLUMNS
53
54
        $this->crud->addColumns([
55
            [
56
                'name'  => 'type',
57
                'label' => trans('webfactor::documents.type')
58
            ],
59
            [
60
                'name'  => 'title',
61
                'label' => trans('webfactor::documents.title')
62
            ],
63
            [
64
                'name'  => 'body',
65
                'label' => trans('webfactor::documents.body')
66
            ]
67
        ]);
68
69
        // ------ CRUD BUTTONS
70
71
        // ------ CRUD ACCESS
72
73
        // ------ CRUD REORDER
74
75
        // ------ CRUD DETAILS ROW
76
77
        // ------ REVISIONS
78
79
        // ------ AJAX TABLE VIEW
80
81
        // ------ DATATABLE EXPORT BUTTONS
82
83
        // ------ ADVANCED QUERIES
84
    }
85
86
    public function getTypeOptions()
87
    {
88
        $types = collect(config('webfactor.documents.types'));
89
90
        return $types->mapWithKeys(function ($type) {
91
            return [$type => trans('webfactor::documents.types.'.$type)];
92
        });
93
    }
94
95
    public function bodyFieldType()
96
    {
97
        $types = [
98
            'plaintext' => 'textarea',
99
            'html' => 'summernote',
100
            'md' => 'simplemde'
101
        ];
102
103
        return $types[config('webfactor.documents.body_type', 'plaintext')];
104
    }
105
106
    public function store(StoreRequest $request)
107
    {
108
        // your additional operations before save here
109
        $redirect_location = parent::storeCrud($request);
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...
110
        // your additional operations after save here
111
        // use $this->data['entry'] or $this->crud->entry
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...
112
        return $redirect_location;
113
    }
114
115
    public function update(UpdateRequest $request)
116
    {
117
        // your additional operations before save here
118
        $redirect_location = parent::updateCrud($request);
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...
119
        // your additional operations after save here
120
        // use $this->data['entry'] or $this->crud->entry
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...
121
        return $redirect_location;
122
    }
123
}
124