FileField   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 126
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A uploadType() 0 3 1
A usingOwnMarkup() 0 3 1
A __construct() 0 5 1
A asRemovable() 0 3 1
A uploadUrl() 0 3 1
A withUploadType() 0 3 1
A removable() 0 3 1
A withDisplayName() 0 3 1
A getUpload() 0 3 1
A displayName() 0 3 1
A withUploadUrl() 0 3 1
1
<?php
2
3
namespace ArgentCrusade\Forms\Fields;
4
5
use ArgentCrusade\Forms\FormField;
6
7
class FileField extends FormField
8
{
9
    protected $type = 'file';
10
11
    /** @var mixed|null */
12
    protected $upload;
13
14
    /**
15
     * FileField constructor.
16
     *
17
     * @param string $label
18
     * @param mixed  $upload = null
19
     */
20
    public function __construct(string $label, $upload = null)
21
    {
22
        parent::__construct($label);
23
24
        $this->upload = $upload;
25
    }
26
27
    /**
28
     * Determines whether the field is using its own markup.
29
     *
30
     * @return bool
31
     */
32
    public function usingOwnMarkup()
33
    {
34
        return true;
35
    }
36
37
    /**
38
     * Get uploaded file instance.
39
     *
40
     * @return mixed
41
     */
42
    public function getUpload()
43
    {
44
        return $this->upload;
45
    }
46
47
    /**
48
     * Mark field as removable.
49
     *
50
     * @param bool $state
51
     *
52
     * @return FileField
53
     */
54
    public function asRemovable(bool $state = true)
55
    {
56
        return $this->withParameter('removable', $state);
57
    }
58
59
    /**
60
     * Determines whether the field is removable.
61
     *
62
     * @return bool
63
     */
64
    public function removable()
65
    {
66
        return $this->getParameter('removable', false) === true;
67
    }
68
69
    /**
70
     * Set upload type.
71
     *
72
     * @param string $uploadType
73
     *
74
     * @return FileField
75
     */
76
    public function withUploadType(string $uploadType)
77
    {
78
        return $this->withParameter('upload_type', $uploadType);
79
    }
80
81
    /**
82
     * Get upload type.
83
     *
84
     * @return string
85
     */
86
    public function uploadType()
87
    {
88
        return $this->getParameter('upload_type');
89
    }
90
91
    /**
92
     * Set upload URL.
93
     *
94
     * @param string $url
95
     *
96
     * @return FileField
97
     */
98
    public function withUploadUrl(string $url)
99
    {
100
        return $this->withParameter('upload_url', $url);
101
    }
102
103
    /**
104
     * Get upload URL.
105
     *
106
     * @return string
107
     */
108
    public function uploadUrl()
109
    {
110
        return $this->getParameter('upload_url');
111
    }
112
113
    /**
114
     * Get uploadede file's display name.
115
     *
116
     * @param string $name
117
     *
118
     * @return FileField
119
     */
120
    public function withDisplayName(string $name)
121
    {
122
        return $this->withParameter('display_name', $name);
123
    }
124
125
    /**
126
     * Get uploaded file's display name.
127
     *
128
     * @return string|null
129
     */
130
    public function displayName()
131
    {
132
        return $this->getParameter('display_name');
133
    }
134
}
135