Completed
Push — master ( 6815df...d4e03c )
by Jason
05:43
created

PageSectionBlock   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 36.21 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 21
loc 58
ccs 18
cts 22
cp 0.8182
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A singular_name() 0 4 1
A plural_name() 0 4 1
A getCMSFields() 21 21 3
A getPageSections() 0 4 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
/**
4
 * Class PageSectionBlock
5
 *
6
 * @method HasManyList $Sections
7
 */
8
class PageSectionBlock extends Block
9
{
10
    /**
11
     * @return string
12
     */
13 9
    public function singular_name()
14
    {
15 9
        return _t('PageSectionBlock.SINGULARNAME', 'Page Sections Block');
16
    }
17
18
    /**
19
     * @return string
20
     */
21
    public function plural_name()
22
    {
23
        return _t('PageSectionBlock.PLURALNAME', 'Page Sections Blocks');
24
    }
25
26
    /**
27
     * @var array
28
     */
29
    private static $has_many = [
30
        'Sections' => 'PageSectionObject',
31
    ];
32
33
    /**
34
     * @return FieldList
35
     */
36 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...
37
    {
38 1
        $fields = parent::getCMSFields();
39
40 1
        if ($this->ID) {
41
            // Sections
42 1
            $config = GridFieldConfig_RecordEditor::create();
43 1
            if (class_exists('GridFieldOrderableRows')) {
44 1
                $config->addComponent(new GridFieldOrderableRows('SortOrder'));
45 1
            }
46 1
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
47 1
            $config->removeComponentsByType('GridFieldDeleteAction');
48 1
            $config->addComponent(new GridFieldDeleteAction(false));
49 1
            $sectionsField = GridField::create('Sections', 'Sections', $this->Sections()->sort('SortOrder'), $config);
0 ignored issues
show
Bug introduced by
The method Sections() does not exist on PageSectionBlock. Did you maybe mean getPageSections()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50 1
            $fields->addFieldsToTab('Root.Sections', array(
51 1
                $sectionsField,
52 1
            ));
53 1
        }
54
55 1
        return $fields;
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getPageSections()
62
    {
63
        return $this->Sections()->sort('SortOrder');
0 ignored issues
show
Bug introduced by
The method Sections() does not exist on PageSectionBlock. Did you maybe mean getPageSections()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
    }
65
}