Completed
Push — master ( f85faa...6214aa )
by Jason
10s
created

RecentBlogPostsBlock::getCMSFields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2.3931

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
ccs 7
cts 13
cp 0.5385
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 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
75
        // Standard mechanism for accepting permission changes from extensions
76
        $extended = $this->extendedCan('canCreate', $member);
77
        if ($extended !== null) {
78
            return $extended;
79
        }
80
81
        return parent::canCreate();
82
    }
83
84
    /**
85
     * @param null $member
86
     * @return bool
87
     */
88 1 View Code Duplication
    public function canView($member = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90 1
        if (!class_exists('Blog')) {
91 1
            return false;
92
        }
93
94
        // Standard mechanism for accepting permission changes from extensions
95
        $extended = $this->extendedCan('canView', $member);
96
        if ($extended !== null) {
97
            return $extended;
98
        }
99
100
        return parent::canView();
101
    }
102
}