Passed
Push — master ( b101db...a45b24 )
by Robbie
05:17
created

BlockArchiveExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getArchiveField() 0 25 3
A isArchiveFieldEnabled() 0 3 1
A getArchiveFieldClass() 0 3 1
1
<?php
2
3
namespace SilverStripe\VersionedAdmin\Extensions;
4
5
use DNADesign\Elemental\Models\BaseElement;
0 ignored issues
show
Bug introduced by
The type DNADesign\Elemental\Models\BaseElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use SilverStripe\Forms\GridField\GridFieldDataColumns;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\Security\Member;
9
use SilverStripe\VersionedAdmin\ArchiveAdmin;
10
use SilverStripe\VersionedAdmin\ArchiveViewProvider;
11
12
/**
13
 * Adds a archive view for Elemental blocks
14
 */
15
class BlockArchiveExtension extends DataExtension implements ArchiveViewProvider
16
{
17
    /**
18
     * @inheritDoc
19
    */
20
    public function getArchiveFieldClass()
21
    {
22
        return BaseElement::class;
0 ignored issues
show
Bug Best Practice introduced by
The expression return DNADesign\Element...dels\BaseElement::class returns the type string which is incompatible with the return type mandated by SilverStripe\VersionedAd...:getArchiveFieldClass() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
23
    }
24
25
    /**
26
     * @inheritDoc
27
    */
28
    public function getArchiveField()
29
    {
30
        $listField = ArchiveAdmin::createArchiveGridField('Blocks', BaseElement::class);
31
32
        $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
33
        $listColumns->setDisplayFields([
0 ignored issues
show
Bug introduced by
The method setDisplayFields() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldDataColumns or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $listColumns->/** @scrutinizer ignore-call */ 
34
                      setDisplayFields([
Loading history...
34
            'Title' => BaseElement::singleton()->fieldLabel('Title'),
35
            'Type' => _t(ArchiveAdmin::class . '.COLUMN_TYPE', 'Type'),
36
            'LastEdited.Ago' => _t(ArchiveAdmin::class . '.COLUMN_DATEARCHIVED', 'Date Archived'),
37
            'Breadcrumbs' => _t(ArchiveAdmin::class . '.COLUMN_ORIGIN', 'Origin'),
38
            'AuthorID' => _t(ArchiveAdmin::class . '.COLUMN_ARCHIVEDBY', 'Archived By')
39
        ]);
40
        $listColumns->setFieldFormatting([
0 ignored issues
show
Bug introduced by
The method setFieldFormatting() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldDataColumns or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $listColumns->/** @scrutinizer ignore-call */ 
41
                      setFieldFormatting([
Loading history...
41
            'Breadcrumbs' => function ($val, $item) {
42
                $parent = $item->Page;
43
44
                return $parent ? $parent->Breadcrumbs() : null;
45
            },
46
            'AuthorID' => function ($val, $item) {
0 ignored issues
show
Unused Code introduced by
The parameter $item is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
            'AuthorID' => function ($val, /** @scrutinizer ignore-unused */ $item) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
                $member = Member::get_by_id($val);
48
                return $member ? $member->Name : null;
0 ignored issues
show
introduced by
$member is of type SilverStripe\ORM\DataObject, thus it always evaluated to true.
Loading history...
49
            },
50
        ]);
51
52
        return $listField;
53
    }
54
55
    /**
56
     * @inheritDoc
57
    */
58
    public function isArchiveFieldEnabled()
59
    {
60
        return true;
61
    }
62
}
63