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 ( 6bda91...26ffdc )
by Cristian
03:56 queued 24s
created

Create::storeCrud()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 28

Duplication

Lines 5
Ratio 17.86 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 1
dl 5
loc 28
rs 9.1608
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\Operations;
4
5
trait Create
6
{
7
    /**
8
     * Show the form for creating inserting a new row.
9
     *
10
     * @return Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\View\View|\I...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
11
     */
12
    public function create()
13
    {
14
        $this->crud->hasAccessOrFail('create');
0 ignored issues
show
Bug introduced by
The property crud does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
16
        // prepare the fields you need to show
17
        $this->data['crud'] = $this->crud;
0 ignored issues
show
Bug introduced by
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
        $this->data['saveAction'] = $this->getSaveAction();
0 ignored issues
show
Bug introduced by
It seems like getSaveAction() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
        $this->data['fields'] = $this->crud->getCreateFields();
20
        $this->data['title'] = trans('backpack::crud.add').' '.$this->crud->entity_name;
21
22
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
23
        return view($this->crud->getCreateView(), $this->data);
24
    }
25
26
    /**
27
     * Store a newly created resource in the database.
28
     *
29
     * @param StoreRequest $request - type injection used for validation using Requests
0 ignored issues
show
Documentation introduced by
Should the type for parameter $request not be null|StoreRequest?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
30
     *
31
     * @return \Illuminate\Http\RedirectResponse
32
     */
33
    public function storeCrud(StoreRequest $request = null)
34
    {
35
        $this->crud->hasAccessOrFail('create');
36
37
        // fallback to global request instance
38
        if (is_null($request)) {
39
            $request = \Request::instance();
40
        }
41
42
        // replace empty values with NULL, so that it will work with MySQL strict mode on
43 View Code Duplication
        foreach ($request->input() as $key => $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            if (empty($value) && $value !== '0') {
45
                $request->request->set($key, null);
46
            }
47
        }
48
49
        // insert item in the db
50
        $item = $this->crud->create($request->except(['save_action', '_token', '_method', 'current_tab']));
51
        $this->data['entry'] = $this->crud->entry = $item;
52
53
        // show a success message
54
        \Alert::success(trans('backpack::crud.insert_success'))->flash();
55
56
        // save the redirect choice for next time
57
        $this->setSaveAction();
0 ignored issues
show
Bug introduced by
It seems like setSaveAction() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
59
        return $this->performSaveAction($item->getKey());
0 ignored issues
show
Bug introduced by
It seems like performSaveAction() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
60
    }
61
}
62