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

RecentBlogPostsBlock   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 32.73 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 18
loc 55
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 18 18 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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