Completed
Push — master ( 88ab05...dae06d )
by Song
02:49
created

InlineEditing::decimal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Grid\Column;
4
5
use Encore\Admin\Grid\Column;
6
use Encore\Admin\Grid\Displayers;
7
8
trait InlineEditing
9
{
10
    /**
11
     * @param string $selectable
12
     *
13
     * @return $this
14
     */
15 View Code Duplication
    public function belongsTo($selectable)
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...
16
    {
17
        if (method_exists($selectable, 'display')) {
18
            $this->display($selectable::display());
0 ignored issues
show
Bug introduced by
It seems like display() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
        }
20
21
        return $this->displayUsing(Displayers\BelongsTo::class, [$selectable]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
22
    }
23
24
    /**
25
     * @param string $selectable
26
     *
27
     * @return $this
28
     */
29 View Code Duplication
    public function belongsToMany($selectable)
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...
30
    {
31
        if (method_exists($selectable, 'display')) {
32
            $this->display($selectable::display());
0 ignored issues
show
Bug introduced by
It seems like display() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
        }
34
35
        return $this->displayUsing(Displayers\BelongsToMany::class, [$selectable]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
36
    }
37
38
    /**
39
     * Upload file.
40
     *
41
     * @return $this
42
     */
43
    public function upload()
44
    {
45
        return $this->displayUsing(Displayers\Upload::class);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
46
    }
47
48
    /**
49
     * Upload many files.
50
     *
51
     * @return $this
52
     */
53
    public function uplaodMany()
54
    {
55
        return $this->displayUsing(Displayers\Upload::class, [true]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56
    }
57
58
    /**
59
     * Grid inline datetime picker.
60
     *
61
     * @param string $format
62
     *
63
     * @return $this
64
     */
65
    public function datetime($format = 'YYYY-MM-DD HH:mm:ss')
66
    {
67
        return $this->displayUsing(Displayers\Datetime::class, [$format]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
68
    }
69
70
    /**
71
     * Grid inline date picker.
72
     *
73
     * @param string $format
0 ignored issues
show
Bug introduced by
There is no parameter named $format. 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...
74
     *
75
     * @return $this
76
     */
77
    public function date()
78
    {
79
        return $this->datetime('YYYY-MM-DD');
80
    }
81
82
    /**
83
     * Grid inline time picker.
84
     *
85
     * @param string $format
0 ignored issues
show
Bug introduced by
There is no parameter named $format. 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...
86
     *
87
     * @return $this
88
     */
89
    public function time()
90
    {
91
        return $this->datetime('HH:mm:ss');
92
    }
93
94
    /**
95
     * Grid inline year picker.
96
     *
97
     * @return $this
98
     */
99
    public function year()
100
    {
101
        return $this->datetime('YYYY');
102
    }
103
104
    /**
105
     * Grid inline month picker.
106
     *
107
     * @return $this
108
     */
109
    public function month()
110
    {
111
        return $this->datetime('MM');
112
    }
113
114
    /**
115
     * Grid inline day picker.
116
     *
117
     * @return $this
118
     */
119
    public function day()
120
    {
121
        return $this->datetime('DD');
122
    }
123
124
    /**
125
     * Grid inline input.
126
     *
127
     * @return $this
128
     */
129
    protected function input($mask = [])
130
    {
131
        return $this->displayUsing(Displayers\Input::class, [$mask]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
132
    }
133
134
    /**
135
     * Grid inline text input.
136
     *
137
     * @return $this
138
     */
139
    public function text()
140
    {
141
        return $this->input();
142
    }
143
144
    /**
145
     * Grid inline ip input.
146
     *
147
     * @return $this
148
     */
149
    public function ip()
150
    {
151
        return $this->input(['alias' => 'ip']);
152
    }
153
154
    /**
155
     * Grid inline email input.
156
     *
157
     * @return $this
158
     */
159
    public function email()
160
    {
161
        return $this->input(['alias' => 'email']);
162
    }
163
164
    /**
165
     * Grid inline url input.
166
     *
167
     * @return $this
168
     */
169
    public function url()
170
    {
171
        return $this->input(['alias' => 'url']);
172
    }
173
174
    /**
175
     * Grid inline currency input.
176
     *
177
     * @return $this
178
     */
179
    public function currency()
180
    {
181
        return $this->input([
182
            'alias'              => 'currency',
183
            'radixPoint'         => '.',
184
            'prefix'             => '',
185
            'removeMaskOnSubmit' => true,
186
        ]);
187
    }
188
189
    /**
190
     * Grid inline decimal input.
191
     *
192
     * @return $this
193
     */
194
    public function decimal()
195
    {
196
        return $this->input([
197
            'alias'      => 'decimal',
198
            'rightAlign' => true,
199
        ]);
200
    }
201
202
    /**
203
     * Grid inline integer input.
204
     *
205
     * @return $this
206
     */
207
    public function integer()
208
    {
209
        return $this->input([
210
            'alias' => 'integer',
211
        ]);
212
    }
213
214
    /**
215
     * Grid inline textarea.
216
     *
217
     * @param int $rows
218
     *
219
     * @return $this
220
     */
221
    public function textarea($rows = 5)
222
    {
223
        return $this->displayUsing(Displayers\Textarea::class, [$rows]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
224
    }
225
226
    /**
227
     * Grid inline tiemzone select.
228
     *
229
     * @return $this
230
     */
231
    public function timezone()
232
    {
233
        $identifiers = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
234
235
        $options = collect($identifiers)->mapWithKeys(function ($timezone) {
236
            return [$timezone => $timezone];
237
        })->toArray();
238
239
        return $this->select($options);
240
    }
241
242
    /**
243
     * Grid inline select.
244
     *
245
     * @param array $options
246
     *
247
     * @return mixed
248
     */
249
    public function select(array $options)
250
    {
251
        return $this->displayUsing(Displayers\Select::class, [$options]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
252
    }
253
254
    /**
255
     * Grid inline multiple-select input.
256
     *
257
     * @param array $options
258
     *
259
     * @return $this
260
     */
261
    public function multipleSelect(array $options)
262
    {
263
        return $this->displayUsing(Displayers\MultipleSelect::class, [$options]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
264
    }
265
266
    /**
267
     * Grid inline checkbox.
268
     *
269
     * @param array $options
270
     *
271
     * @return $this
272
     */
273
    public function checkbox(array $options)
274
    {
275
        return $this->displayUsing(Displayers\Checkbox::class, [$options]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
276
    }
277
278
    /**
279
     * Grid inline checkbox.
280
     *
281
     * @param array $options
282
     *
283
     * @return $this
284
     */
285
    public function radio(array $options)
286
    {
287
        return $this->displayUsing(Displayers\Radio::class, [$options]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
288
    }
289
290
    /**
291
     * Grid inline switch.
292
     *
293
     * @param array $states
294
     *
295
     * @return $this
296
     */
297
    public function switch(array $states = [])
298
    {
299
        return $this->displayUsing(Displayers\SwitchDisplay::class, [$states]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
300
    }
301
302
    /**
303
     * Grid inline switch group.
304
     *
305
     * @param array $states
306
     *
307
     * @return $this
308
     */
309
    public function switchGroup(array $columns = [], array $states = [])
310
    {
311
        return $this->displayUsing(Displayers\SwitchGroup::class, [$columns, $states]);
0 ignored issues
show
Bug introduced by
It seems like displayUsing() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
312
    }
313
}
314