HomePageBlock   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 14 1
A getLink() 0 10 3
1
<?php
2
/**
3
 * Created by IntelliJ IDEA.
4
 * User: Werner M. Krauß <[email protected]>
5
 * Date: 28.10.2015
6
 * Time: 12:02
7
 */
8
9
/**
10
 * StartGeneratedWithDataObjectAnnotator
11
 * @property string Title
12
 * @property string Content
13
 * @property string LinkText
14
 * @property string ExternalLinkURL
15
 * @property boolean IsActive
16
 * @property int SortOrder
17
 * @property int HomePageID
18
 * @property int LinkToPageID
19
 * @method HomePage HomePage
20
 * @method Page LinkToPage
21
 * EndGeneratedWithDataObjectAnnotator
22
 */
23
class HomePageBlock 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...
24
{
25
26
    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...
27
        'Title' => 'Varchar(64)',
28
        'Content' => 'HTMLText',
29
        'LinkText' => 'Varchar(64)',
30
        'ExternalLinkURL' => 'Varchar(255)',
31
        'IsActive' => 'Boolean',
32
        'SortOrder' => 'Int'
33
    ];
34
35
    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...
36
        'HomePage' => 'HomePage',
37
        'LinkToPage' => 'Page'
38
    ];
39
40
    private static $singular_name = 'Home page block';
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 $singular_name 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...
41
42
    private static $plural_name = 'Home page blocks';
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 $plural_name 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...
43
44
    private static $summary_fields = [
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 $summary_fields 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...
45
        'Title', 'IsActive'
46
    ];
47
48
    private static $default_sort = 'SortOrder';
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...
49
50
    /**
51
     * for configuring fluent
52
     * @var array
53
     */
54
    private static $translate = [
0 ignored issues
show
Unused Code introduced by
The property $translate 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...
55
        'Title',
56
        'Content',
57
        'LinkText',
58
        'ExternalLinkURL'
59
    ];
60
61
    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...
62
    {
63
        $fields = parent::getCMSFields();
64
65
        $linkTo = $fields->dataFieldByName('LinkToPageID')->setEmptyString('-- bitte auswählen --');
66
67
        $fields->removeByName(['SortOrder', 'HomePageID', 'LinkToPageID']);
68
69
        $fields->insertAfter('LinkText', $linkTo);
70
71
        $this->extend('updateCMSFields', $fields);
72
73
        return $fields;
74
    }
75
76
    public function getLink()
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...
77
    {
78
        $link = $this->LinkToPageID && $this->LinkToPage()
0 ignored issues
show
Documentation Bug introduced by
The method LinkToPage does not exist on object<HomePageBlock>? 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...
79
            ? $this->LinkToPage()->Link()
0 ignored issues
show
Documentation Bug introduced by
The method LinkToPage does not exist on object<HomePageBlock>? 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...
80
            : $this->ExternalLinkURL;
81
82
        $this->extend('updateLink', $link);
83
84
        return $link;
85
    }
86
}
87