BlogPostSharedCategoriesExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 37.93 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 22
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A UsedCategories() 0 4 1
A UsedTags() 0 4 1
B updateCMSFields() 22 26 3

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
/**
4
 * extends BlogPost
5
 *
6
 */
7
8
class BlogPostSharedCategoriesExtension extends DataExtension
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...
9
{
10
    private static $categories_checkboxes = true;
0 ignored issues
show
Unused Code introduced by
The property $categories_checkboxes 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...
11
12
    private static $tags_checkboxes = true;
0 ignored issues
show
Unused Code introduced by
The property $tags_checkboxes 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...
13
    /**
14
     * overrules has_many method
15
     * to return ALL categories
16
     *
17
     * @return DataList
18
     */
19
    public function UsedCategories()
20
    {
21
        return $this->owner->Parent()->UsedCategories();
22
    }
23
24
    /**
25
     * overrules has_many method
26
     * to return ALL categories
27
     *
28
     * @return DataList
29
     */
30
    public function UsedTags()
31
    {
32
        return $this->owner->Parent()->UsedTags();
33
    }
34
35
    /**
36
     * Update Fields
37
     * @return FieldList
38
     */
39
    public function updateCMSFields(FieldList $fields)
40
    {
41 View Code Duplication
        if (Config::inst()->get("BlogPostSharedCategoriesExtension", "categories_checkboxes") == true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
42
            $fields->replaceField(
43
                "Categories",
44
                CheckboxSetField::create(
45
                    'Categories',
46
                    _t('BlogPost.Categories', 'Categories'),
47
                    BlogCategory::get()->sort(array('Title'=>'ASC'))->map("ID", "Title"),
48
                    $this->owner->Categories()
49
                )
50
            );
51
        }
52 View Code Duplication
        if (Config::inst()->get("BlogPostSharedCategoriesExtension", "tags_checkboxes") == true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
53
            $fields->replaceField(
54
                "Tags",
55
                CheckboxSetField::create(
56
                    'Tags',
57
                    _t('BlogPost.Tags', 'Tags'),
58
                    BlogTag::get()->sort(array('Title'=>'ASC'))->map("ID", "Title"),
59
                    $this->owner->Tags()
60
                )
61
            );
62
        }
63
        return $fields;
64
    }
65
}
66