SiteTreeExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateCMSActions() 0 21 6
1
<?php
2
3
namespace SilverStripe\CampaignAdmin;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\Tab;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\Security\Permission;
9
10
/**
11
 * Handles adding the "Add to Campaign" button to a page's secondary actions menu
12
 */
13
class SiteTreeExtension extends DataExtension
14
{
15
    public function updateCMSActions(FieldList $actions)
16
    {
17
        // Add to campaign option if not-archived and has publish permission
18
        if ((!$this->owner->isPublished() && !$this->owner->isOnDraft())
19
            || !$this->owner->canPublish()
20
            || !Permission::check('CMS_ACCESS_CampaignAdmin')
21
        ) {
22
            return;
23
        }
24
25
        /** @var Tab $moreOptions */
26
        $moreOptions = $actions->fieldByName('ActionMenus.MoreOptions');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $moreOptions is correct as $actions->fieldByName('ActionMenus.MoreOptions') targeting SilverStripe\Forms\FieldList::fieldByName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

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

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

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

Loading history...
27
        if (!$moreOptions) {
0 ignored issues
show
introduced by
$moreOptions is of type SilverStripe\Forms\Tab, thus it always evaluated to true.
Loading history...
28
            return;
29
        }
30
31
        $moreOptions->insertAfter(
32
            'Information',
33
            AddToCampaignHandler_FormAction::create()
34
                ->removeExtraClass('btn-primary')
35
                ->addExtraClass('btn-secondary')
36
        );
37
    }
38
}
39