Completed
Pull Request — master (#4)
by Nic
09:10
created

ManageableObjectDataExtension   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 65
Duplicated Lines 36.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 3
dl 24
loc 65
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getListingPage() 0 11 2
A getAddLink() 0 8 3
A getEditLink() 12 12 4
A getDeleteLink() 12 12 4

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
 * Class GridObject
5
 */
6
class ManageableObjectDataExtension extends DataExtension
7
{
8
9
    /**
10
     * Get the listing page to view this Event on (used in Link functions below)
11
     *
12
     * @return mixed
13
     */
14 4
    public function getListingPage()
15
    {
16
17 4
        $listingClass = $this->owner->config()->get('listing_page_class');
18
19 4
        if ($listingPage = $listingClass::get()->first()) {
20 4
            return $listingPage;
21
        }
22
23
        return false;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29 1
    public function getAddLink()
30
    {
31 1
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canCreate(Member::currentUser())) {
32 1
            return $this->owner->getListingPage()->Link('add');
33
        }
34
35 1
        return false;
36
    }
37
38
    /**
39
     * @return bool|String
40
     */
41 1 View Code Duplication
    public function getEditLink()
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...
42
    {
43 1
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canEdit(Member::currentUser())) {
44 1
            $field = ($this->owner->config()->get('query_field'))
45 1
                ? $this->owner->config()->get('query_field')
46 1
                : 'ID';
47
48 1
            return Controller::join_links($this->owner->getListingPage()->Link('edit'), $this->owner->$field);
49
        }
50
51 1
        return false;
52
    }
53
54
    /**
55
     * @return bool|String
56
     */
57 1 View Code Duplication
    public function getDeleteLink()
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...
58
    {
59 1
        if ($this->owner->getListingPage()->hasMethod('Link') && $this->owner->canDelete(Member::currentUser())) {
60 1
            $field = ($this->owner->config()->get('query_field'))
61 1
                ? $this->owner->config()->get('query_field')
62 1
                : 'ID';
63
64 1
            return Controller::join_links($this->owner->getListingPage()->Link('delete'), $this->owner->$field);
65
        }
66
67 1
        return false;
68
    }
69
70
}