Completed
Pull Request — master (#34)
by Jason
05:39
created

RecentBlogPostsBlock::canCreate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3 1
if (class_exists('Blog')) {
4
5
    /**
6
     * Class RecentBlogPostsBlock
7
     */
8
    class RecentBlogPostsBlock extends Block
9
    {
10
        /**
11
         * @var string
12
         */
13
        private static $singular_name = 'Recent Blog Posts Block';
14
15
        /**
16
         * @var string
17
         */
18
        private static $plural_name = 'Recent Blog Posts Blocks';
19
20
        /**
21
         * @var array
22
         */
23
        private static $db = array(
24
            'Limit' => 'Int',
25
        );
26
27
        /**
28
         * @var array
29
         */
30
        private static $has_one = array(
31
            'Blog' => 'Blog',
32
        );
33
34
        /**
35
         * @var array
36
         */
37
        private static $defaults = array(
38
            'Limit' => 3,
39
        );
40
41
        /**
42
         * @return FieldList
43
         */
44 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...
45
        {
46
            $fields = singleton('Block')->getCMSFields();
47
48
            $fields->addFieldsToTab('Root.Main', array(
49
                NumericField::create('Limit'),
50
            ));
51
52
            if (class_exists('Blog')) {
53
                $fields->addFieldToTab(
54
                    'Root.Main',
55
                    DropdownField::create('BlogID', 'Featured Blog', Blog::get()->map())
56
                        ->setEmptyString('')
57
                );
58
            }
59
60
            return $fields;
61
        }
62
    }
63
64
}
65
66