Completed
Push — fix-2494 ( 3153ee )
by Sam
07:19
created

TestPermissionNode::canEdit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Security\Test\InheritedPermissionsTest;
4
5
use SilverStripe\Core\Injector\Injector;
6
use SilverStripe\Dev\TestOnly;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Security\InheritedPermissions;
9
use SilverStripe\Security\InheritedPermissionsExtension;
10
use SilverStripe\Security\Member;
11
use SilverStripe\Security\PermissionChecker;
12
use SilverStripe\Versioned\Versioned;
13
14
/**
15
 * @method TestPermissionNode Parent()
16
 * @mixin Versioned
17
 * @mixin InheritedPermissionsExtension
18
 */
19
class TestPermissionNode extends DataObject implements TestOnly
20
{
21
    private static $db = [
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...
22
        "Title" => "Varchar(255)",
23
    ];
24
25
    private static $has_one = [
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...
26
        "Parent" => self::class,
27
    ];
28
29
    private static $table_name = 'InheritedPermissionsTest_TestPermissionNode';
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...
30
31
    private static $extensions = [
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...
32
        Versioned::class,
33
        InheritedPermissionsExtension::class,
34
    ];
35
36
    /**
37
     * @return InheritedPermissions
38
     */
39
    public static function getInheritedPermissions()
40
    {
41
        /** @var InheritedPermissions $permissions */
42
        return Injector::inst()->get(PermissionChecker::class.'.testpermissions');
43
    }
44
45 View Code Duplication
    public function canEdit($member = null)
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...
46
    {
47
        if (!$member) {
48
            $member = Member::currentUser();
49
        }
50
        return static::getInheritedPermissions()->canEdit($this->ID, $member);
51
    }
52
53 View Code Duplication
    public function canView($member = null)
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...
54
    {
55
        if (!$member) {
56
            $member = Member::currentUser();
57
        }
58
        return static::getInheritedPermissions()->canView($this->ID, $member);
59
    }
60
61 View Code Duplication
    public function canDelete($member = null)
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...
62
    {
63
        if (!$member) {
64
            $member = Member::currentUser();
65
        }
66
        return static::getInheritedPermissions()->canDelete($this->ID, $member);
67
    }
68
}
69