Issues (51)

src/SiteTreeExtension.php (2 issues)

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
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
$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