Completed
Pull Request — master (#4)
by Nic
06:53 queued 05:29
created

ManageableObjectDataExtension::getEditLink()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 7
cts 7
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 0
crap 4
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
}