Checkbox   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A addCheckbox() 0 26 4
1
<?php
2
3
namespace Yajra\DataTables\Html\Columns;
4
5
use Yajra\DataTables\Html\Column;
6
7
trait Checkbox
8
{
9
    /**
10
     * Add a checkbox column.
11
     *
12
     * @param  array $attributes
13
     * @param  bool|int $position true to prepend, false to append or a zero-based index for positioning
14
     * @return $this
15
     */
16
    public function addCheckbox(array $attributes = [], $position = false)
17
    {
18
        $attributes = array_merge([
19
            'defaultContent' => '<input type="checkbox" ' . $this->html->attributes($attributes) . '/>',
0 ignored issues
show
Bug introduced by
The property html 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...
20
            'title' => '<input type="checkbox" ' . $this->html->attributes($attributes + ['id' => 'dataTablesCheckbox']) . '/>',
21
            'data' => 'checkbox',
22
            'name' => 'checkbox',
23
            'orderable' => false,
24
            'searchable' => false,
25
            'exportable' => false,
26
            'printable' => true,
27
            'width' => '10px',
28
        ], $attributes);
29
30
        $column = new Column($attributes);
31
32
        if ($position === true) {
33
            $this->collection->prepend($column);
0 ignored issues
show
Bug introduced by
The property collection 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...
34
        } elseif ($position === false || $position >= $this->collection->count()) {
35
            $this->collection->push($column);
36
        } else {
37
            $this->collection->splice($position, 0, [$column]);
38
        }
39
40
        return $this;
41
    }
42
}
43