Completed
Pull Request — master (#24)
by Jason
21:08 queued 06:10
created

SpecSheet   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 76
loc 76
c 0
b 0
f 0
ccs 18
cts 18
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 8 8 1
A providePermissions() 8 8 1
A canCreate() 4 4 1
A canEdit() 4 4 1
A canDelete() 4 4 1
A canView() 4 4 1

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 Dynamic\ProductCatalog\Docs;
4
5
use SilverStripe\Security\Permission;
6
use SilverStripe\Security\PermissionProvider;
7
8 View Code Duplication
class SpecSheet extends ProductDoc implements PermissionProvider
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @var string
12
     */
13
    private static $singular_name = 'Spec Sheet';
14
15
    /**
16
     * @var string
17
     */
18 1
    private static $plural_name = 'Spec Sheets';
19
20 1
    /**
21
     * @return FieldList
22 1
     */
23
    public function getCMSFields()
24 1
    {
25
        $fields = parent::getCMSFields();
26
27
        $fields->dataFieldByName('Download')->setFolderName('Uploads/Products/SpecSheets');
28
29
        return $fields;
30 1
    }
31
32
    /**
33 1
     * @return array
34 1
     */
35 1
    public function providePermissions()
36 1
    {
37
        return array(
38
            'Spec_EDIT' => 'Edit Spec Sheets',
39
            'Spec_DELETE' => 'Delete Spec Sheets',
40
            'Spec_CREATE' => 'Create Spec Sheets',
41
        );
42
    }
43
44 1
    /**
45
     * @param null $member
46 1
     *
47
     * @return bool|int
48
     */
49
    public function canCreate($member = null, $context = [])
50
    {
51
        return Permission::check('Spec_CREATE', 'any', $member);
52
    }
53
54 1
    /**
55
     * @param null $member
56 1
     *
57
     * @return bool|int
58
     */
59
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context 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...
60
    {
61
        return Permission::check('Spec_EDIT', 'any', $member);
62
    }
63
64 1
    /**
65
     * @param null $member
66 1
     *
67
     * @return bool|int
68
     */
69
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context 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...
70
    {
71
        return Permission::check('Spec_DELETE', 'any', $member);
72
    }
73
74 1
    /**
75
     * @param null $member
76 1
     *
77
     * @return bool
78
     */
79 1
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context 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...
80
    {
81
        return true;
82
    }
83
}
84