Completed
Push — master ( bab916...1c5f6e )
by Jason
10:56
created

EmbedBlock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 43
loc 43
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A singular_name() 4 4 1
A plural_name() 4 4 1
A getCMSFields() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3 View Code Duplication
class EmbedBlock extends Block
0 ignored issues
show
Duplication introduced by
This class 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...
4
{
5
    /**
6
     * @return string
7
     */
8 13
    public function singular_name()
9
    {
10 13
        return _t('AccordionBlock.SINGULARNAME', 'Embed Block');
11
    }
12
13
    /**
14
     * @return string
15
     */
16
    public function plural_name()
17
    {
18
        return _t('AccordionBlock.PLURALNAME', 'Embed Blocks');
19
    }
20
21
    /**
22
     * @var array
23
     */
24
    private static $has_one = [
25
        'EmbeddedObject' => 'EmbeddedObject',
26
    ];
27
28
    /**
29
     * @return FieldList
30
     */
31 1
    public function getCMSFields(){
32 1
        $fields = parent::getCMSFields();
33
34 1
        $fields->removeByName([
35 1
            'EmbeddedObjectID',
36 1
        ]);
37
38 1
        $fields->addFieldToTab(
39 1
            'Root.Embed',
40 1
            EmbeddedObjectField::create('EmbeddedObject', 'Content from oEmbed URL', $this->EmbeddedObject())
0 ignored issues
show
Documentation Bug introduced by
The method EmbeddedObject does not exist on object<EmbedBlock>? 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...
41 1
        );
42
43 1
        return $fields;
44
    }
45
}