Buttons::buttons()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 6
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Options\Plugins;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
7
/**
8
 * DataTables - Buttons plugin option builder.
9
 *
10
 * @see https://datatables.net/extensions/buttons/
11
 * @see https://datatables.net/reference/option/buttons
12
 */
13
trait Buttons
14
{
15
    /**
16
     * Attach multiple buttons to builder.
17
     *
18
     * @param array|mixed ...$buttons
19
     * @return $this
20
     * @see https://www.datatables.net/extensions/buttons/
21
     */
22
    public function buttons(...$buttons)
23
    {
24
        if (is_array($buttons[0])) {
25
            $buttons = $buttons[0];
26
        }
27
28
        foreach ($buttons as $button) {
29
            $this->attributes['buttons'][] = $button instanceof Arrayable ? $button->toArray() : $button;
0 ignored issues
show
Bug introduced by
The property attributes does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
        }
31
32
        return $this;
33
    }
34
}
35