RecentBlogPostsBlock::getCMSFields()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.3931

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 13
cp 0.5385
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 2.3931
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3 1
if (!class_exists('Blog')) {
4 1
    return;
5
}
6
7
/**
8
 * Class RecentBlogPostsBlock
9
 */
10
class RecentBlogPostsBlock extends Block
11
{
12
    /**
13
     * @var string
14
     */
15
    private static $singular_name = 'Recent Blog Posts Block';
16
17
    /**
18
     * @var string
19
     */
20
    private static $plural_name = 'Recent Blog Posts Blocks';
21
22
    /**
23
     * @var array
24
     */
25
    private static $db = array(
26
        'Limit' => 'Int',
27
    );
28
29
    /**
30
     * @var array
31
     */
32
    private static $has_one = array(
33
        'Blog' => 'Blog',
34
    );
35
36
    /**
37
     * @var array
38
     */
39
    private static $defaults = array(
40
        'Limit' => 3,
41
    );
42
43
    /**
44
     * @return FieldList
45
     */
46 1
    public function getCMSFields()
47
    {
48 1
        $fields = singleton('Block')->getCMSFields();
49
50 1
        $fields->addFieldsToTab('Root.Main', array(
51 1
            NumericField::create('Limit'),
52 1
        ));
53
54 1
        if (class_exists('Blog')) {
55
            $fields->addFieldToTab(
56
                'Root.Main',
57
                DropdownField::create('BlogID', 'Featured Blog', Blog::get()->map())
58
                    ->setEmptyString('')
59
            );
60
        }
61
62 1
        return $fields;
63
    }
64
65
    /**
66
     * @param null $member
67
     * @return bool
68
     */
69 1
    public function canCreate($member = null)
70
    {
71 1
        if (!class_exists('Blog')) {
72 1
            return false;
73
        }
74
        return parent::canCreate();
75
    }
76
77
    /**
78
     * @param null $member
79
     * @return bool
80
     */
81 1
    public function canView($member = null)
82
    {
83 1
        if (!class_exists('Blog')) {
84 1
            return false;
85
        }
86
        return parent::canView();
87
    }
88
}