BlockArchiveExtension::getArchiveField()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 19
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 30
rs 9.6333
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\ORM\FieldType\DBDatetime;
9
use SilverStripe\Security\Member;
10
use SilverStripe\VersionedAdmin\ArchiveAdmin;
11
use SilverStripe\VersionedAdmin\Interfaces\ArchiveViewProvider;
12
13
/**
14
 * Adds a archive view for Elemental blocks
15
 */
16
class BlockArchiveExtension extends DataExtension implements ArchiveViewProvider
17
{
18
    /**
19
     * @inheritDoc
20
    */
21
    public function getArchiveFieldClass()
22
    {
23
        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...
24
    }
25
26
    /**
27
     * @inheritDoc
28
    */
29
    public function getArchiveField()
30
    {
31
        $listField = ArchiveAdmin::createArchiveGridField('Blocks', BaseElement::class);
32
33
        $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
34
        $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

34
        $listColumns->/** @scrutinizer ignore-call */ 
35
                      setDisplayFields([
Loading history...
35
            'Title' => BaseElement::singleton()->fieldLabel('Title'),
36
            'Type' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_TYPE', 'Type'),
37
            'Versions.first.LastEdited' => _t(
38
                'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_DATEARCHIVED',
39
                'Date Archived'
40
            ),
41
            'Breadcrumbs' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ORIGIN', 'Origin'),
42
            'Versions.first.Author.Name' => _t(
43
                'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ARCHIVEDBY',
44
                'Archived By'
45
            )
46
        ]);
47
        $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

47
        $listColumns->/** @scrutinizer ignore-call */ 
48
                      setFieldFormatting([
Loading history...
48
            'Breadcrumbs' => function ($val, $item) {
49
                $parent = $item->Page;
50
51
                return $parent ? $parent->Breadcrumbs() : null;
52
            },
53
            'Versions.first.LastEdited' => 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

53
            'Versions.first.LastEdited' => 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...
54
                return DBDatetime::create_field('Datetime', $val)->Ago();
55
            },
56
        ]);
57
58
        return $listField;
59
    }
60
61
    /**
62
     * @inheritDoc
63
    */
64
    public function isArchiveFieldEnabled()
65
    {
66
        return true;
67
    }
68
}
69