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
Pull Request — master (#109)
by
unknown
08:27
created

ViewsAndRestoresRevisions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A listRevisions() 0 23 3
A restoreRevision() 0 11 1
1
<?php
2
3
namespace Backpack\CRUD\PanelTraits;
4
5
use Venturecraft\Revisionable\Revision;
6
7
trait ViewsAndRestoresRevisions
8
{
9
    /**
10
     * Build a list of Revisions, grouped by revision date
11
     * 
12
     * @return [Array] of revision groups, keyed by revision date
0 ignored issues
show
Documentation introduced by
The doc-type [Array] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
13
     */
14
    public function listRevisions($id)
15
    {
16
        $revisions = [];
17
        // Group revisions by change date
18
        foreach($this->getEntry($id)->revisionHistory as $history) {
0 ignored issues
show
Bug introduced by
It seems like getEntry() 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
20
            // Get just the date from the revision created timestamp
21
            $revisionDate = date('Y-m-d', strtotime((string)$history->created_at));
22
23
            // Be sure to instantiate the initial grouping array
24
            if(!array_key_exists($revisionDate, $revisions)) {
25
                $revisions[$revisionDate] = [];
26
            }
27
28
            // Push onto the top of the current group - so we get orderBy decending timestamp
29
            array_unshift($revisions[$revisionDate], $history);
30
        }
31
32
        // Sort the array by timestamp descending (so that the most recent are at the top)
33
        arsort($revisions);
34
35
        return $revisions;
36
    }
37
38
    /**
39
     * Restore a single revision
40
     * 
41
     * @param  [int] $id         The ID of the source CRUD Model instance to update
0 ignored issues
show
Documentation introduced by
The doc-type [int] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
42
     * @param  [int] $revisionId The ID of the revision to use for the update
0 ignored issues
show
Documentation introduced by
The doc-type [int] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
43
     */
44
    public function restoreRevision($id, $revisionId) {
45
        $entry = $this->getEntry($id);
0 ignored issues
show
Bug introduced by
It seems like getEntry() 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...
46
        $revision = Revision::findOrFail($revisionId);
47
48
        // Update the revisioned field with the old value
49
        $entry->{$revision->fieldName()} = $revision->oldValue();
50
        $entry->save();
51
52
        // Reload the entry so we have the latest revisions
53
        $entry = $this->getEntry($id);
0 ignored issues
show
Bug introduced by
It seems like getEntry() 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...
Unused Code introduced by
$entry is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
    }
55
}
56