Completed
Pull Request — master (#5)
by Nic
03:52
created

ManageableObjectDataExtension::getListingPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.032
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
}