PartialFieldSubmission   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 66
loc 66
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreate() 4 4 1
A canView() 8 8 2
A canEdit() 8 8 2
A canDelete() 8 8 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 Firesphere\PartialUserforms\Models;
4
5
use SilverStripe\Security\Member;
6
use SilverStripe\UserForms\Model\Submission\SubmittedFormField;
7
8
/**
9
 * Class PartialFieldSubmission
10
 *
11
 * @package Firesphere\PartialUserforms\Models
12
 * @property int $SubmittedFormID
13
 * @method PartialFormSubmission SubmittedForm()
14
 */
15 View Code Duplication
class PartialFieldSubmission extends SubmittedFormField
16
{
17
    /**
18
     * @var string
19
     */
20
    private static $table_name = 'PartialFieldSubmission';
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...
21
22
    /**
23
     * @var array
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
        'SubmittedForm' => PartialFormSubmission::class,
27
    ];
28
29
    /**
30
     * @param Member $member
31
     * @param array $context
32
     * @return boolean
33
     */
34 1
    public function canCreate($member = null, $context = [])
35
    {
36 1
        return false;
37
    }
38
39
    /**
40
     * @param Member $member
41
     *
42
     * @return boolean|string
43
     */
44 14
    public function canView($member = null)
45
    {
46 14
        if ($this->SubmittedFormID) {
47 14
            return $this->SubmittedForm()->canView($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->SubmittedForm()->canView($member); of type boolean|string adds the type string to the return on line 47 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ittedFormField::canView of type boolean.
Loading history...
48
        }
49
50 5
        return parent::canView($member);
51
    }
52
53
    /**
54
     * @param Member $member
55
     *
56
     * @return boolean|string
57
     */
58 1
    public function canEdit($member = null)
59
    {
60 1
        if ($this->SubmittedFormID) {
61 1
            return $this->SubmittedForm()->canEdit($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->SubmittedForm()->canEdit($member); of type boolean|string adds the type string to the return on line 61 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ittedFormField::canEdit of type boolean.
Loading history...
62
        }
63
64
        return parent::canEdit($member);
65
    }
66
67
    /**
68
     * @param Member $member
69
     *
70
     * @return boolean|string
71
     */
72 1
    public function canDelete($member = null)
73
    {
74 1
        if ($this->SubmittedFormID) {
75 1
            return $this->SubmittedForm()->canDelete($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->SubmittedForm()->canDelete($member); of type boolean|string adds the type string to the return on line 75 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...tedFormField::canDelete of type boolean.
Loading history...
76
        }
77
78
        return parent::canDelete($member);
79
    }
80
}
81