Completed
Push — master ( cad27a...4c05a1 )
by Elf
05:17
created

EloquentEngine::addColumn()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
ccs 0
cts 19
cp 0
rs 6.7272
cc 7
eloc 12
nc 12
nop 3
crap 56
1
<?php
2
3
namespace ElfSundae\Laravel\Datatables\Engines;
4
5
use Yajra\Datatables\Engines\EloquentEngine as BaseEngine;
6
7
class EloquentEngine extends BaseEngine
8
{
9
    /**
10
     * Add column in collection.
11
     *
12
     * @param  string|string[]  $name
13
     * @param  string|callable|bool|int|null  $content
14
     * @param  bool|int  $order
15
     * @return $this
16
     */
17
    public function addColumn($name, $content = null, $order = false)
18
    {
19
        if (is_bool($content) || is_int($content)) {
20
            $order = $content;
21
            $content = null;
22
        }
23
24
        if (is_null($content) && is_string($name)) {
25
            $content = function ($model) use ($name) {
26
                return $model->{$name};
27
            };
28
        }
29
30
        if (is_array($name)) {
31
            foreach ($name as $n) {
32
                $this->addColumn($n, $content, $order);
33
            }
34
35
            return $this;
36
        }
37
38
        return parent::addColumn($name, $content, $order);
1 ignored issue
show
Bug introduced by
It seems like $content can also be of type null; however, Yajra\Datatables\Engines...lderEngine::addColumn() does only seem to accept callable, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
39
    }
40
}
41