HomePage_Controller   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getActiveHomePageBlocks() 0 10 2
1
<?php
2
3
/**
4
 * StartGeneratedWithDataObjectAnnotator
5
 * @method DataList|HomePageBlock[] HomePageBlocks
6
 * EndGeneratedWithDataObjectAnnotator
7
 */
8
class HomePage extends Page
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
11
    private static $has_many = [
0 ignored issues
show
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
        'HomePageBlocks' => 'HomePageBlock'
13
    ];
14
15
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
16
    {
17
        $self =& $this;
18
        $this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) {
19
20
            /**
21
             * @var GridFieldConfig_RecordEditor $conf
22
             */
23
            $conf = GridFieldConfig_RecordEditor::create();
24
25
            $conf->addComponent(new GridFieldSortableRows('SortOrder'));
26
27
            $fields->addFieldToTab(
28
                "Root." . _t('HomePage.BlockTabName', 'Blocks'),
29
                Gridfield::create(
30
                    'HomePageBlocks',
31
                    _t('HomePage.Block', 'Blocks'),
32
                    $this->HomePageBlocks(),
33
                    $conf
34
                )
35
            );
36
        });
37
38
        $fields = parent::getCMSFields();
39
40
        return $fields;
41
    }
42
}
43
44
class HomePage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
45
{
46
    public function getActiveHomePageBlocks()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
47
    {
48
        $blocks = $this->data()->HomePageBlocks();
49
50
        if (Versioned::current_stage() === 'Live') {
51
            $blocks = $blocks->filter('IsActive', 1);
52
        }
53
54
        return $blocks;
55
    }
56
}
57