RestfulServerTestComment   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canEdit() 0 3 1
A canCreate() 0 3 1
A canView() 0 3 1
A canDelete() 0 3 1
A providePermissions() 0 6 1
1
<?php
2
3
namespace SilverStripe\RestfulServer\Tests\Stubs;
4
5
use SilverStripe\Dev\TestOnly;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\Security\Permission;
8
use SilverStripe\Security\PermissionProvider;
9
10
/**
11
 * Everybody can view comments, logged in members in the "users" group can create comments,
12
 * but only "editors" can edit or delete them.
13
 *
14
 */
15
class RestfulServerTestComment extends DataObject implements PermissionProvider, TestOnly
16
{
17
    private static $api_access = true;
0 ignored issues
show
introduced by
The private property $api_access is not used, and could be removed.
Loading history...
18
19
    private static $table_name = 'RestfulServerTestComment';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
20
21
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
22
        "Name" => "Varchar(255)",
23
        "Comment" => "Text"
24
    );
25
26
    private static $has_one = array(
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
27
        'Page' => RestfulServerTestPage::class,
28
        'Author' => RestfulServerTestAuthor::class,
29
    );
30
31
    public function providePermissions()
32
    {
33
        return array(
34
            'EDIT_Comment' => 'Edit Comment Objects',
35
            'CREATE_Comment' => 'Create Comment Objects',
36
            'DELETE_Comment' => 'Delete Comment Objects',
37
        );
38
    }
39
40
    public function canView($member = null)
41
    {
42
        return true;
43
    }
44
45
    public function canEdit($member = null)
46
    {
47
        return Permission::checkMember($member, 'EDIT_Comment');
48
    }
49
50
    public function canDelete($member = null)
51
    {
52
        return Permission::checkMember($member, 'DELETE_Comment');
53
    }
54
55
    public function canCreate($member = null, $context = array())
56
    {
57
        return Permission::checkMember($member, 'CREATE_Comment');
58
    }
59
}
60