Completed
Push — master ( a9c12c...991987 )
by Oliver
02:03
created

DocumentCrudController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Webfactor\LaravelBackpackDocuments\Controllers;
4
5
use Backpack\CRUD\app\Http\Controllers\CrudController;
6
7
use Webfactor\LaravelBackpackDocuments\app\Http\Requests\app\Models\Document;
8
use Webfactor\LaravelBackpackDocuments\app\Http\Requests\DocumentRequest as StoreRequest;
9
use Webfactor\LaravelBackpackDocuments\app\Http\Requests\DocumentRequest as UpdateRequest;
10
11
class DocumentCrudController extends CrudController
12
{
13
    public function setup()
14
    {
15
        /*
16
        |--------------------------------------------------------------------------
17
        | BASIC CRUD INFORMATION
18
        |--------------------------------------------------------------------------
19
        */
20
        $this->crud->setModel(config('webfactor.documents.model_class'));
21
        $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...
22
        $this->crud->setEntityNameStrings(trans('webfactor::documents.entity_name_singular'),
23
            trans('webfactor::documents.entity_name_plural'));
24
25
        /*
26
        |--------------------------------------------------------------------------
27
        | BASIC CRUD INFORMATION
28
        |--------------------------------------------------------------------------
29
        */
30
31
        // ------ CRUD FIELDS
32
33
        $this->crud->addField([
34
            'name'  => 'type',
35
            'label' => 'Dokumentenart',
36
            'type'  => 'select_from_array',
37
            'options' => $this->getTypeOptions(),
38
            'allows_null' => false,
39
            'allows_multiple' => false
40
        ]);
41
42
        $this->crud->addField([
43
            'name' => 'title',
44
            'label' => trans('webfactor::documents.title')
45
        ]);
46
        
47
        $this->crud->addField([
48
            'name' => 'body',
49
            'label' => trans('webfactor::documents.body'),
50
            'type' => $this->bodyFieldType()
51
        ]);
52
53
        // ------ CRUD COLUMNS
54
55
        $this->crud->addColumns([
56
            [
57
                'name'  => 'type',
58
                'label' => trans('webfactor::documents.type')
59
            ],
60
            [
61
                'name'  => 'title',
62
                'label' => trans('webfactor::documents.title')
63
            ],
64
            [
65
                'name'  => 'body',
66
                'label' => trans('webfactor::documents.body')
67
            ]
68
        ]);
69
70
        // ------ CRUD BUTTONS
71
72
        // ------ CRUD ACCESS
73
74
        // ------ CRUD REORDER
75
76
        // ------ CRUD DETAILS ROW
77
78
        // ------ REVISIONS
79
80
        // ------ AJAX TABLE VIEW
81
82
        // ------ DATATABLE EXPORT BUTTONS
83
84
        // ------ ADVANCED QUERIES
85
    }
86
87
    public function getTypeOptions()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
88
    {
89
        $types = collect(config('webfactor.documents.types'));
90
91
        return $types->mapWithKeys(function ($type) {
92
            return [$type => trans('webfactor::documents.types.'.$type)];
93
        });
94
    }
95
96
    public function bodyFieldType()
97
    {
98
        $types = [
99
            'plaintext' => 'textarea',
100
            'html' => 'summernote',
101
            'md' => 'simplemde'
102
        ];
103
104
        return $types[config('webfactor.documents.body_type', 'plaintext')];
105
    }
106
107
    public function store(StoreRequest $request)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
108
    {
109
        // your additional operations before save here
110
        $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...
111
        // your additional operations after save here
112
        // 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...
113
        return $redirect_location;
114
    }
115
116
    public function update(UpdateRequest $request)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
117
    {
118
        // your additional operations before save here
119
        $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...
120
        // your additional operations after save here
121
        // 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...
122
        return $redirect_location;
123
    }
124
}
125