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 ( 7a24d5...09959f )
by Cristian
02:56
created

Revisions::restoreRevision()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 11
nc 2
nop 1
dl 0
loc 22
rs 9.2
c 1
b 1
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures;
4
5
trait Revisions {
6
7
    /**
8
     * Display the revisions for specified resource.
9
     *
10
     * @param int $id
11
     *
12
     * @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...
13
     */
14 View Code Duplication
    public function listRevisions($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
15
    {
16
        $this->crud->hasAccessOrFail('revisions');
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...
17
18
        // get the info for that entry
19
        $this->data['entry'] = $this->crud->getEntry($id);
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...
20
        $this->data['crud'] = $this->crud;
21
        $this->data['title'] = ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions');
22
        $this->data['id'] = $id;
23
        $this->data['revisions'] = $this->crud->listRevisions($id);
24
25
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
26
        return view('crud::revisions', $this->data);
27
    }
28
29
    /**
30
     * Restore a specific revision for the specified resource.
31
     *
32
     * Used via AJAX in the revisions view
33
     *
34
     * @param int $id
35
     *
36
     * @return JSON Response containing the new revision that was created from the update
37
     * @return HTTP 500 if the request did not contain the revision ID
0 ignored issues
show
Documentation introduced by
Should the return type not be null|\Illuminate\View\Vi...\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...
38
     */
39
    public function restoreRevision($id)
40
    {
41
        $this->crud->hasAccessOrFail('revisions');
42
43
        // @TODO: Currently the route already contains the revision ID, so passing it as a POST param
44
        // is somewhat superfluous.. however if we are POSTing, it makes sense to actually have data to post.
45
        // Perhaps the route shoud be better named to reflect this (e.g. just /model/{id}/revisions) (??)
46
        $revisionId = \Request::input('revision_id', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string|array|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        if (! $revisionId) {
48
            abort(500, 'Can\'t restore revision without revision_id');
49
        } else {
50
            $this->crud->restoreRevision($id, $revisionId); // do the update
51
52
            $this->data['entry'] = $this->crud->getEntry($id);
53
            $this->data['crud'] = $this->crud;
54
            $this->data['revisions'] = $this->crud->listRevisions($id); // Reload revisions as they have changed
55
56
            // Rebuild the revision timeline HTML and return it to the AJAX call
57
            // @TODO: Return only the latest revision to save bandwidth - 15/9/16 @se1exin
58
            return view('crud::inc.revision_timeline', $this->data);
59
        }
60
    }
61
62
}