StandardPermissions   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 72
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A canPublish() 0 4 1
A canUnpublish() 0 4 1
A canArchive() 0 4 1
A canView() 0 4 1
A canEdit() 0 4 1
A canDelete() 0 4 1
A canCreate() 0 4 1
B providePermissions() 0 24 4
1
<?php
2
/**
3
 * @file StandardPermissions.php
4
 * Adds CMS defined permissions for publishing
5
 */
6
7
/**
8
 * An extension which controls the 'can*' functions in an object.
9
 */
10
class StandardPermissions extends DataExtension implements PermissionProvider
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
13
    /**
14
     * Can the user publish this?
15
     */
16
    public function canPublish($member = false)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    {
18
        return Permission::check(get_class($this->owner) . '_publish');
19
    }
20
21
    /**
22
     * Can the user unpublish this?
23
     */
24
    public function canUnpublish($member = false)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        return Permission::check(get_class($this->owner) . '_unpublish');
27
    }
28
29
    /**
30
     * Can the user archive this?
31
     */
32
    public function canArchive($member = false)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
    {
34
        return Permission::check(get_class($this->owner) . '_archive');
35
    }
36
37
    public function canView($member = false)
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        return Permission::check(get_class($this->owner) . '_view');
40
    }
41
    public function canEdit($member = false)
42
    {
43
        return Permission::check(get_class($this->owner) . '_edit');
44
    }
45
    public function canDelete($member = false)
46
    {
47
        return Permission::check(get_class($this->owner) . '_delete');
48
    }
49
    public function canCreate($member = false)
50
    {
51
        return Permission::check(get_class($this->owner) . '_create');
52
    }
53
54
    /**
55
     * Get a complete list of all the permissions this class uses.
56
     */
57
    public function providePermissions()
58
    {
59
        $permissions = array();
60
        $config = Config::inst()->get('PublishProvider', 'classes');
61
62
        foreach ($config as $class) {
63
            $subClasses = array_keys(ClassInfo::subclassesFor($class));
64
            
65
            foreach ($subClasses as $subClass) {
66
                foreach (array(
67
                        'publish',
68
                        'unpublish',
69
                        'archive',
70
                        'view',
71
                        'edit',
72
                        'delete',
73
                        'create') as $name) {
74
                    $permissions[$subClass . '_' . $name] = singleton($subClass)->singular_name(). ' ' . $name;
75
                }
76
            }
77
        }
78
        
79
        return $permissions;
80
    }
81
}
82