Completed
Pull Request — master (#195)
by Damian
01:56
created

CommentableItem::canEdit()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 6
nop 1
1
<?php
2
3
namespace SilverStripe\Comments\Tests\Stubs;
4
5
use SilverStripe\Comments\Extensions\CommentsExtension;
6
use SilverStripe\Control\Director;
7
use SilverStripe\Dev\TestOnly;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\Security\Member;
10
use SilverStripe\Security\Permission;
11
12
/**
13
 * @package comments
14
 * @subpackage tests
15
 */
16
class CommentableItem extends DataObject implements TestOnly
17
{
18
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db 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...
19
        'Title' => 'Varchar'
20
    );
21
22
    private static $extensions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $extensions 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...
23
        CommentsExtension::class
24
    );
25
26
    public function RelativeLink()
27
    {
28
        return 'CommentableItemController';
29
    }
30
31
    public function canView($member = null)
32
    {
33
        return true;
34
    }
35
36
    // This is needed for canModerateComments
37
    public function canEdit($member = null)
38
    {
39
        if ($member instanceof Member) {
40
            $memberID = $member->ID;
41
        } elseif (is_numeric($member)) {
42
            $memberID = $member;
43
        } else {
44
            $memberID = Member::currentUserID();
45
        }
46
47
        if ($memberID && Permission::checkMember($memberID, array('ADMIN', 'CMS_ACCESS_CommentAdmin'))) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $memberID && \Sil...ACCESS_CommentAdmin'));.
Loading history...
48
            return true;
49
        }
50
        return false;
51
    }
52
53
    public function Link()
54
    {
55
        return $this->RelativeLink();
56
    }
57
58
    public function AbsoluteLink()
59
    {
60
        return Director::absoluteURL($this->RelativeLink());
61
    }
62
}
63