Passed
Push — master ( 606bf7...dde9c0 )
by Matthew
01:54
created

SalsifyIDExtension::updateCMSFields()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 18
rs 9.9332
cc 4
nc 8
nop 1
1
<?php
2
3
namespace Dyanmic\Salsify\ORM;
4
5
use SilverStripe\Admin\LeftAndMain;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Admin\LeftAndMain 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\Control\Controller;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\FormAction;
9
use SilverStripe\Forms\TextField;
10
use SilverStripe\ORM\DataExtension;
11
12
/**
13
 * Class FileExtension
14
 *
15
 * @property string SalsifyID
16
 * @property string SalsifyUpdatedAt
17
 *
18
 * @property-read \SilverStripe\ORM\DataObject|\Dyanmic\Salsify\ORM\SalsifyIDExtension $owner
19
 */
20
class SalsifyIDExtension extends DataExtension
21
{
22
23
    /**
24
     * @var array
25
     */
26
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
27
        'SalsifyID' => 'Varchar(255)',
28
        'SalsifyUpdatedAt' => 'Varchar(255)'
29
    ];
30
31
    /**
32
     * @param \SilverStripe\Forms\FieldList $fields
33
     */
34
    public function updateCMSFields(FieldList $fields)
35
    {
36
        $salsifyID = $fields->dataFieldByName('SalsifyID');
37
        if (!$salsifyID) {
0 ignored issues
show
introduced by
$salsifyID is of type SilverStripe\Forms\FormField, thus it always evaluated to true.
Loading history...
38
            $fields->push($salsifyID = TextField::create('SalsifyID'));
39
        }
40
41
        $salsifyUpdatedAt = $fields->dataFieldByName('SalsifyUpdatedAt');
42
        if (!$salsifyUpdatedAt) {
0 ignored issues
show
introduced by
$salsifyUpdatedAt is of type SilverStripe\Forms\FormField, thus it always evaluated to true.
Loading history...
43
            $fields->push($salsifyUpdatedAt = TextField::create('SalsifyUpdatedAt'));
44
        }
45
46
        if ($this->owner->SalsifyID) {
47
            $salsifyID->setReadonly(true);
48
        }
49
        $salsifyUpdatedAt->setReadonly(true);
50
51
        return parent::updateCMSFields($fields);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::updateCMSFields($fields) targeting SilverStripe\ORM\DataExtension::updateCMSFields() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
52
    }
53
54
    /**
55
     * @param \SilverStripe\Forms\FieldList $actions
56
     */
57
    public function updateCMSActions(FieldList $actions)
58
    {
59
        parent::updateCMSActions($actions);
60
61
        if (!$this->owner->SalsifyID) {
62
            return;
63
        }
64
65
        $controller = Controller::curr();
66
        if ($controller instanceof LeftAndMain && $controller->canFetchSalsify()) {
67
            /** @var FormAction $action */
68
            $action = FormAction::create('salsifyFetch', 'Re-fetch Salsify')
69
                ->addExtraClass('btn-primary font-icon-sync')
70
                ->setUseButtonTag(true);
71
72
            $actions->push($action);
73
        }
74
    }
75
}
76