GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ContentBlock_TileSection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 8
dl 0
loc 74
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getCMSFields() 0 37 2
A getAvailableTemplates() 0 8 2
A getBlockType() 0 4 1
1
<?php
2
3
/**
4
 * Models a Content Block Tile Section
5
 *
6
 * @since 1.0.0
7
 */
8
class ContentBlock_TileSection extends ContentBlock
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
    private static $db = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db 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...
11
        'TilesPerRow' => 'Enum("One, Two, Three")',
12
        'TileTemplate' => 'Text'
13
    ];
14
15
    private static $has_many = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
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...
16
        'ContentTiles' => 'TileSection_ContentTile',
17
    ];
18
19
    public function getCMSFields()
20
    {
21
        $fields = parent::getCMSFields();
22
23
        $fields->push(DropdownField::create(
24
            'TilesPerRow',
25
            'Tiles Per Row',
26
            singleton('ContentBlock_TileSection')
27
            ->dbObject('TilesPerRow')
28
            ->enumValues()
29
        ));
30
31
        $fields->push(DropdownField::create(
32
            'TileTemplate',
33
            'Tile Template',
34
            $this->getAvailableTemplates()
35
        ));
36
37
        if ($this->getField('ID')) {
38
            $fields->push(GridField::create(
39
                'ContentTiles',
40
                'Content Tiles',
41
                $this->ContentTiles(),
0 ignored issues
show
Documentation Bug introduced by
The method ContentTiles does not exist on object<ContentBlock_TileSection>? 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...
42
                GridFieldConfig_RecordEditor::create()
43
                ->addComponent(new GridFieldOrderableRows('Sort'))
44
            ));
45
        } else {
46
            $fields->push(LiteralField::create(
47
                'Unsaved',
48
                '<p class="message info">Please save first, to begin adding Tiles </p>'
49
            ));
50
        }
51
52
        $this->extend('updateCMSFields', $fields);
53
54
        return $fields;
55
    }
56
57
    /**
58
     * Gets available templates from the static configuration
59
     *
60
     * @return array
61
     */
62
     public function getAvailableTemplates()
63
     {
64
         $templates = Config::inst()->get('ContentBlock_TileSection', 'tile_templates');
65
66
         $this->extend('updateAvailableTemplates', $templates);
67
68
         return (!empty($templates)) ? $templates : [] ;
69
     }
70
71
72
    /**
73
     * Gets the block type for CMS display
74
     *
75
     * @return string
76
     */
77
    public function getBlockType()
78
    {
79
        return 'Tile Section';
80
    }
81
}
82