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

TestPermissionNode   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 42 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 21
loc 50
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getInheritedPermissions() 0 5 1
A canEdit() 7 7 2
A canView() 7 7 2
A canDelete() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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