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

Revisions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A listRevisions() 0 17 1
A restoreRevision() 0 19 2
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\Operations;
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
    public function listRevisions($id)
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 entry ID from Request (makes sure its the last ID for nested resources)
19
        $id = $this->crud->getCurrentEntryId() ?? $id;
20
21
        // get the info for that entry
22
        $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...
23
        $this->data['crud'] = $this->crud;
24
        $this->data['title'] = ucfirst($this->crud->entity_name).' '.trans('backpack::crud.revisions');
25
        $this->data['id'] = $id;
26
        $this->data['revisions'] = $this->crud->listRevisions($id);
27
28
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
29
        return view($this->crud->getRevisionsView(), $this->data);
30
    }
31
32
    /**
33
     * Restore a specific revision for the specified resource.
34
     *
35
     * Used via AJAX in the revisions view
36
     *
37
     * @param int $id
38
     *
39
     * @return JSON Response containing the new revision that was created from the update
40
     * @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...
41
     */
42
    public function restoreRevision($id)
43
    {
44
        $this->crud->hasAccessOrFail('revisions');
45
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($this->crud->getRevisionsTimelineView(), $this->data);
59
        }
60
    }
61
}
62