updateCMSFields()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 26
Code Lines 18

Duplication

Lines 22
Ratio 84.62 %

Importance

Changes 0
Metric Value
dl 22
loc 26
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 18
nc 4
nop 1
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