Completed
Pull Request — master (#23)
by Jason
08:45
created

CallToActionBlock::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
crap 1
1
<?php
2
3
class CallToActionBlock extends Block
4
{
5
    /**
6
     * @var string
7
     */
8
    private static $singular_name = 'Call To Action Block';
9
10
    /**
11
     * @var string
12
     */
13
    private static $plural_name = 'Call To Action Blocks';
14
15
    /**
16
     * @var array
17
     */
18
    private static $has_one = [
19
        'BlockLink' => 'Link',
20
    ];
21
22
    /**
23
     * @return FieldList
24
     */
25 1 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27 1
        $this->beforeUpdateCMSFields(function ($fields) {
28 1
            $fields->addFieldToTab(
29 1
                'Root.Main',
30 1
                LinkField::create('BlockLinkID', 'Link')
31 1
            );
32 1
        });
33
34 1
        $fields = parent::getCMSFields();
35
36 1
        $fields->removeByName([
37 1
            'Title',
38 1
        ]);
39
40 1
        return $fields;
41
    }
42
43 1
    public function getTitle()
44
    {
45 1
        if ($this->BlockLink()) {
0 ignored issues
show
Documentation Bug introduced by
The method BlockLink does not exist on object<CallToActionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
46 1
            return $this->BlockLink()->Title;
0 ignored issues
show
Documentation Bug introduced by
The method BlockLink does not exist on object<CallToActionBlock>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47
        }
48
    }
49
}