CommentableItem   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 19
c 3
b 0
f 0
dl 0
loc 47
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canEdit() 0 14 5
A Link() 0 3 1
A RelativeLink() 0 3 1
A canView() 0 3 1
A AbsoluteLink() 0 3 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
class CommentableItem extends DataObject implements TestOnly
13
{
14
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
15
        'Title' => 'Varchar'
16
    );
17
18
    private static $extensions = array(
0 ignored issues
show
introduced by
The private property $extensions is not used, and could be removed.
Loading history...
19
        CommentsExtension::class
20
    );
21
22
    private static $table_name = 'CommentableItem';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
23
24
    public function RelativeLink()
25
    {
26
        return 'CommentableItemController';
27
    }
28
29
    public function canView($member = null)
30
    {
31
        return true;
32
    }
33
34
    // This is needed for canModerateComments
35
    public function canEdit($member = null)
36
    {
37
        if ($member instanceof Member) {
38
            $memberID = $member->ID;
39
        } elseif (is_numeric($member)) {
40
            $memberID = $member;
41
        } else {
42
            $memberID = Member::currentUserID();
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Security\Member::currentUserID() has been deprecated: 5.0.0 use Security::getCurrentUser() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

42
            $memberID = /** @scrutinizer ignore-deprecated */ Member::currentUserID();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
43
        }
44
45
        if ($memberID && Permission::checkMember($memberID, array('ADMIN', 'CMS_ACCESS_CommentAdmin'))) {
46
            return true;
47
        }
48
        return false;
49
    }
50
51
    public function Link()
52
    {
53
        return $this->RelativeLink();
54
    }
55
56
    public function AbsoluteLink()
57
    {
58
        return Director::absoluteURL($this->RelativeLink());
59
    }
60
}
61