Completed
Pull Request — master (#30)
by Lhalaa
01:12
created

PartialFileFieldSubmission::canEdit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace Firesphere\PartialUserforms\Models;
4
5
use SilverStripe\Security\Member;
6
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
7
8
/**
9
 * Class \Firesphere\PartialUserforms\Models\PartialFileFieldSubmission
10
 *
11
 * @property int $SubmittedFormID
12
 * @method PartialFormSubmission SubmittedForm()
13
 */
14
class PartialFileFieldSubmission extends SubmittedFileField
15
{
16
    private static $table_name = 'PartialFileFieldSubmission';
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...
17
18
    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...
19
        'SubmittedForm' => PartialFormSubmission::class,
20
    ];
21
22
23
    /**
24
     * @param Member $member
25
     * @param array $context
26
     * @return boolean
27
     */
28 1
    public function canCreate($member = null, $context = [])
29
    {
30 1
        return false;
31
    }
32
33
    /**
34
     * @param Member $member
35
     *
36
     * @return bool
37
     */
38 2
    public function canView($member = null)
39
    {
40 2
        if ($this->SubmittedFormID) {
41 2
            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 41 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ittedFormField::canView of type boolean.
Loading history...
42
        }
43
44
        return parent::canView($member);
45
    }
46
47
    /**
48
     * @param Member $member
49
     *
50
     * @return bool
51
     */
52 1
    public function canEdit($member = null)
53
    {
54 1
        if ($this->SubmittedFormID) {
55 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 55 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...ittedFormField::canEdit of type boolean.
Loading history...
56
        }
57
58
        return parent::canEdit($member);
59
    }
60
61
    /**
62
     * @param Member $member
63
     *
64
     * @return bool
65
     */
66 1
    public function canDelete($member = null)
67
    {
68 1
        if ($this->SubmittedFormID) {
69 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 69 which is incompatible with the return type of the parent method SilverStripe\UserForms\M...tedFormField::canDelete of type boolean.
Loading history...
70
        }
71
72
        return parent::canDelete($member);
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getFilename()
79
    {
80
        return $this->UploadedFileID ? $this->UploadedFile()->Name : '';
0 ignored issues
show
Documentation introduced by
The property UploadedFileID does not exist on object<Firesphere\Partia...ialFileFieldSubmission>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read 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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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...
Documentation Bug introduced by
The method UploadedFile does not exist on object<Firesphere\Partia...ialFileFieldSubmission>? 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...
81
    }
82
}
83