CallToActionBlock   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 56
ccs 19
cts 20
cp 0.95
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A singular_name() 0 4 1
A getCMSFields() 0 17 1
A plural_name() 0 4 1
A getTitle() 0 6 2
1
<?php
2
3
class CallToActionBlock extends Block
4
{
5
    /**
6
     * @return string
7
     */
8 12
    public function singular_name()
9
    {
10 12
        return _t('CallToActionBlock.SINGULARNAME', 'Call To Action Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16 1
    public function plural_name()
17
    {
18 1
        return _t('CallToActionBlock.PLURALNAME', 'Call To Action Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $has_one = [
25
        'BlockLink' => 'Link',
26
    ];
27
28
    /**
29
     * @return FieldList
30
     */
31 1
    public function getCMSFields()
32
    {
33 1
        $this->beforeUpdateCMSFields(function ($fields) {
34 1
            $fields->addFieldToTab(
35 1
                'Root.Main',
36 1
                LinkField::create('BlockLinkID', 'Link')
37 1
            );
38 1
        });
39
40 1
        $fields = parent::getCMSFields();
41
42 1
        $fields->removeByName([
43 1
            'Title',
44 1
        ]);
45
46 1
        return $fields;
47
    }
48
49
    /**
50
     * @return mixed
51
     */
52 2
    public function getTitle()
53
    {
54 2
        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...
55 2
            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...
56
        }
57
    }
58
}