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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 7 1
A getCMSValidator() 0 6 1
A onBeforeWrite() 0 8 2
A getTemplateName() 0 6 1
A RenderBlock() 0 8 2
A getBlockType() 0 4 1
1
<?php
2
3
/**
4
 * Models a Content Block - a base class for different types of Content Blocks
5
 *
6
 * @since 1.0.0
7
 */
8
class ContentBlock extends DataObject
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 $casting = [
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 $casting 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
        'RenderBlock' => 'HTMLText'
13
    ];
14
15
    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...
16
        'Sort' => 'Int',
17
        'Title' => 'Text',
18
    ];
19
20
    private static $has_one = [
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_one 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...
21
        'ParentPage' => 'SiteTree',
22
    ];
23
24
    private static $default_sort = 'Sort ASC';
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 $default_sort 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...
25
26
27
    public function getCMSFields()
28
    {
29
        return FieldList::create([
30
            TextField::create('Title')
31
            ->setDescription('For CMS Identification')
32
        ]);
33
    }
34
35
    /**
36
     * @return RequiredFields
37
     */
38
    public function getCMSValidator()
39
    {
40
        return RequiredFields::create([
41
            'Title'
42
        ]);
43
    }
44
45
    public function onBeforeWrite()
46
    {
47
        parent::onBeforeWrite();
48
49
        if (!$this->getField('Title')) {
50
            $this->Title = sprintf('New %s', $this->getBlockType());
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<ContentBlock>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
51
        }
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getTemplateName()
58
    {
59
        $template = $this->getField('ClassName');
60
        $this->extend('updateTemplateName', $template);
61
        return $template;
62
    }
63
64
    /**
65
     * Renders the block for template
66
     *
67
     * @return string
68
     */
69
    public function RenderBlock()
70
    {
71
        if (Config::inst()->get('ContentBlock', 'include_bootstrap')) {
72
            Requirements::javascript(CONTENTBLOCKS_DIR . '/javascript/lib/bootstrap.min.js');
73
            Requirements::css(CONTENTBLOCKS_DIR . '/css/lib/bootstrap.min.css');
74
        }
75
        return $this->renderWith($this->getTemplateName());
76
    }
77
78
    /**
79
     * Gets the block type for CMS display
80
     *
81
     * @return string
82
     */
83
    public function getBlockType()
84
    {
85
        return 'Content Block';
86
    }
87
88
}
89