Completed
Push — master ( 68e08f...b73a8d )
by Arjay
01:14
created

File::editor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Editor\Fields;
4
5
/**
6
 * @see https://editor.datatables.net/reference/field/upload
7
 * @see https://editor.datatables.net/examples/advanced/upload.html
8
 * @see https://editor.datatables.net/examples/advanced/upload-many.html
9
 */
10
class File extends Field
11
{
12
    protected $type = 'upload';
13
14
    /**
15
     * Editor instance.
16
     *
17
     * @var string
18
     */
19
    protected $editor = 'editor';
20
21
    /**
22
     * @param string $name
23
     * @param string $label
24
     * @return \Yajra\DataTables\Html\Editor\Fields\Field|static
25
     */
26
    public static function make($name, $label = '')
27
    {
28
        return parent::make($name, $label)->displayFile()->clearText()->noImageText();
29
    }
30
31
    /**
32
     * Set editor instance for file upload.
33
     *
34
     * @param string $editor
35
     * @return $this
36
     */
37
    public function editor($editor)
38
    {
39
        $this->editor = $editor;
40
41
        return $this;
42
    }
43
44
    /**
45
     * Display image upon upload.
46
     *
47
     * @return $this
48
     */
49
    public function displayImage()
50
    {
51
        return $this->display("function (file_id) { return file_id ? '<img src=\"' + {$this->editor}.file('files', file_id).url + '\"/>' : null; }");
52
    }
53
54
    /**
55
     * @param string $label
0 ignored issues
show
Bug introduced by
There is no parameter named $label. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     * @return $this
57
     */
58
    public function display($value)
59
    {
60
        $this->attributes['display'] = $value;
61
62
        return $this;
63
    }
64
65
    /**
66
     * Display the file path.
67
     *
68
     * @return $this
69
     */
70
    public function displayFile()
71
    {
72
        return $this->display("function (file_id) { return file_id; }");
73
    }
74
75
    /**
76
     * @param string $value
77
     * @return $this
78
     */
79
    public function clearText($value = 'Clear')
80
    {
81
        $this->attributes['clearText'] = $value;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @param string $value
88
     * @return $this
89
     */
90
    public function noImageText($value = 'No image')
91
    {
92
        $this->attributes['noImageText'] = $value;
93
94
        return $this;
95
    }
96
97
    /**
98
     * @param bool $state
99
     * @return $this
100
     */
101
    public function multiple($state = true)
102
    {
103
        if ($state) {
104
            $this->type('uploadMany');
105
        }
106
107
        return $this;
108
    }
109
}
110