Completed
Push — master ( 8c1f56...d9e017 )
by wen
14:37
created

File::getActionUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
class File extends Element
6
{
7
    protected $type = 'file';
8
9
    protected $actionUrl;
10
11
    protected $multiple = false;
12
13
    protected $showFileList = true;
14
15
    protected $withCredentials = false;
16
17
    public function getValue()
18
    {
19
        $value = parent::getValue();
20
        if (empty($value)) {
21
            return [];
22
        }
23
24
        return [
25
            [
26
                'name' => '',
27
                'url'  => asset('vendor/admin/images/1200.jpg'),
28
            ],
29
        ];
30
    }
31
32
    public function getActionUrl()
33
    {
34
        if ($this->actionUrl) {
35
            return $this->actionUrl;
36
        }
37
        route('admin.dashboard');
38
    }
39
40
    public function setActionUrl($value)
41
    {
42
        $this->actionUrl = $value;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Allow multiple selection files
49
     *
50
     * @return $this
51
     */
52
    public function isMultiple()
53
    {
54
        $this->multiple = true;
55
56
        return $this;
57
    }
58
59
    /**
60
     * Do not show file list
61
     *
62
     * @return $this
63
     */
64
    public function hideFileList()
65
    {
66
        $this->showFileList = true;
67
68
        return $this;
69
    }
70
71
    /**
72
     * Indicates whether or not cross-site Access-Control requests
73
     * should be made using credentials
74
     *
75
     * @return $this
76
     */
77
    public function withCredentials()
78
    {
79
        $this->withCredentials = true;
80
81
        return $this;
82
    }
83
84
    public function setMaxSize($value)
85
    {
86
        $this->addValidationRule('max:' . $value);
0 ignored issues
show
Bug introduced by
The method addValidationRule() does not seem to exist on object<Sco\Admin\Form\Elements\File>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
88
        return $this;
89
    }
90
91
    public function toArray()
92
    {
93
        return parent::toArray() + [
94
                'action'       => $this->getActionUrl(),
95
                'showFileList' => $this->showFileList,
96
                'multiple'     => $this->multiple,
97
            ];
98
    }
99
}
100