Completed
Push — master ( 74e06b...f0c430 )
by Simon
13:56
created

PartialFormSubmission::getCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Firesphere\PartialUserforms\Models;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
8
use SilverStripe\Forms\GridField\GridFieldConfig;
9
use SilverStripe\Forms\GridField\GridFieldDataColumns;
10
use SilverStripe\Forms\GridField\GridFieldExportButton;
11
use SilverStripe\Forms\GridField\GridFieldPrintButton;
12
/**
13
 * Class \Firesphere\PartialUserforms\Models\PartialFormSubmission
14
 *
15
 * @property boolean $IsSend
16
 * @property int $UserDefinedFormID
17
 * @method \SilverStripe\ORM\DataObject UserDefinedForm()
18
 * @method \SilverStripe\ORM\DataList|\Firesphere\PartialUserforms\Models\PartialFieldSubmission[] PartialFields()
19
 */
20
class PartialFormSubmission extends SubmittedForm
21
{
22
    private static $table_name = 'PartialFormSubmission';
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...
Unused Code introduced by
The property $table_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
23
24
    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...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
25
        'IsSend' => 'Boolean(false)'
26
    ];
27
28
    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...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
29
        'UserDefinedForm' => DataObject::class
30
    ];
31
32
    private static $has_many = [
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...
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
33
        'PartialFields' => PartialFieldSubmission::class
34
    ];
35
36
    public function getCMSFields()
37
    {
38
        /** @var FieldList $fields */
39
        $fields = parent::getCMSFields();
40
        $fields->removeByName(['Values', 'IsSend']);
41
        $config = new GridFieldConfig();
42
        $config->addComponent(new GridFieldDataColumns());
43
        $config->addComponent(new GridFieldPrintButton());
44
45
        $fields->dataFieldByName('PartialFields')->setConfig($config);
0 ignored issues
show
Bug introduced by
The method setConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
47
        return $fields;
48
    }
49
50
    /**
51
     * @param Member
52
     *
53
     * @return boolean
54
     */
55
    public function canCreate($member = null, $context = [])
56
    {
57
        $extended = $this->extendedCan(__FUNCTION__, $member);
58
        if ($extended !== null) {
59
            return $extended;
60
        }
61
62
        if ($this->UserDefinedForm()) {
63
            return $this->UserDefinedForm()->canCreate($member, $context);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()...ate($member, $context); of type boolean|string adds the type string to the return on line 63 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ubmittedForm::canCreate of type boolean.
Loading history...
64
        }
65
66
        if (!$this->Parent()) {
0 ignored issues
show
Documentation Bug introduced by
The method Parent does not exist on object<Firesphere\Partia...\PartialFormSubmission>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
67
            $this->ParentID = $this->UserDefinedFormID;
0 ignored issues
show
Documentation introduced by
The property ParentID does not exist on object<Firesphere\Partia...\PartialFormSubmission>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
68
        }
69
70
        return parent::canCreate($member);
71
    }
72
73
    /**
74
     * @param Member
75
     *
76
     * @return boolean
77
     */
78 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...
79
    {
80
        $extended = $this->extendedCan(__FUNCTION__, $member);
81
82
        if ($extended !== null) {
83
            return $extended;
84
        }
85
86
        if ($this->UserDefinedForm()) {
87
            return $this->UserDefinedForm()->canView($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canView($member); of type boolean|string adds the type string to the return on line 87 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...\SubmittedForm::canView of type boolean.
Loading history...
88
        }
89
90
        return parent::canView($member);
91
    }
92
93
    /**
94
     * @param Member
95
     *
96
     * @return boolean
97
     */
98 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...
99
    {
100
        $extended = $this->extendedCan(__FUNCTION__, $member);
101
102
        if ($extended !== null) {
103
            return $extended;
104
        }
105
106
        if ($this->UserDefinedForm()) {
107
            return $this->UserDefinedForm()->canEdit($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canEdit($member); of type boolean|string adds the type string to the return on line 107 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...\SubmittedForm::canEdit of type boolean.
Loading history...
108
        }
109
110
        return parent::canEdit($member);
111
    }
112
113
    /**
114
     * @param Member
115
     *
116
     * @return boolean
117
     */
118 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...
119
    {
120
        $extended = $this->extendedCan(__FUNCTION__, $member);
121
122
        if ($extended !== null) {
123
            return $extended;
124
        }
125
126
        if ($this->UserDefinedForm()) {
127
            return $this->UserDefinedForm()->canDelete($member);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->UserDefinedForm()->canDelete($member); of type boolean|string adds the type string to the return on line 127 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ubmittedForm::canDelete of type boolean.
Loading history...
128
        }
129
130
        return parent::canDelete($member);
131
    }
132
133
}
134