Completed
Pull Request — master (#30)
by Jason
17:47 queued 02:47
created

CareCleaningDoc   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 79
loc 79
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 7 7 1
A canView() 3 3 1
A providePermissions() 6 6 1
A canDelete() 3 3 1
A canEdit() 3 3 1
A canCreate() 3 3 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\Forms\FieldList;
6
use SilverStripe\Security\Permission;
7
use SilverStripe\Security\PermissionProvider;
8
9 View Code Duplication
class CareCleaningDoc 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...
10
{
11
    /**
12
     * @var string
13
     */
14
    private static $singular_name = 'Care & Cleaning Doc';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
15
16
    /**
17
     * @var string
18
     */
19
    private static $plural_name = 'Care & Cleaning Docs';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    private static $table_name = 'CareCleaningDoc';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
25
26
    /**
27
     * @return FieldList
28
     */
29
    public function getCMSFields()
30
    {
31
        $fields = parent::getCMSFields();
32
33
        $fields->dataFieldByName('Download')->setFolderName('Uploads/Products/CareCleaningDocs');
34
35
        return $fields;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function providePermissions()
42
    {
43
        return array(
44
            'Care_EDIT' => 'Edit Care and Cleaning Docs',
45
            'Care_DELETE' => 'Delete Care and Cleaning Docs',
46
            'Care_CREATE' => 'Create Care and Cleaning Docs',
47
        );
48
    }
49
50
    /**
51
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
52
     *
53
     * @return bool|int
54
     */
55
    public function canCreate($member = null, $context = [])
56
    {
57
        return Permission::check('Care_CREATE', 'any', $member);
58
    }
59
60
    /**
61
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
62
     *
63
     * @return bool|int
64
     */
65
    public function canEdit($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

65
    public function canEdit($member = null, /** @scrutinizer ignore-unused */ $context = [])

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

Loading history...
66
    {
67
        return Permission::check('Care_EDIT', 'any', $member);
68
    }
69
70
    /**
71
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
72
     *
73
     * @return bool|int
74
     */
75
    public function canDelete($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function canDelete($member = null, /** @scrutinizer ignore-unused */ $context = [])

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

Loading history...
76
    {
77
        return Permission::check('Care_DELETE', 'any', $member);
78
    }
79
80
    /**
81
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
82
     *
83
     * @return bool
84
     */
85
    public function canView($member = null, $context = [])
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

85
    public function canView($member = null, /** @scrutinizer ignore-unused */ $context = [])

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

Loading history...
86
    {
87
        return true;
88
    }
89
}
90