Kit::table()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Database/SQL kit
4
 * User: moyo
5
 * Date: 22/12/2017
6
 * Time: 3:37 PM
7
 */
8
9
namespace Carno\Database\SQL;
10
11
use Carno\Database\Contracts\Executable;
12
13
trait Kit
14
{
15
    /**
16
     * available features
17
     * @var array
18
     */
19
    private $features = [
20
        'timestamps',
21
    ];
22
23
    /**
24
     * loaded chips
25
     * @var array
26
     */
27
    private $chips = [];
28
29
    /**
30
     * @param string $name
31
     * @param Executable $executable
32
     * @return Builder
33
     */
34
    final public function table(string $name, Executable $executable = null) : Builder
35
    {
36
        return new Builder($name, $executable ?: $this, $this->fcInjectors());
0 ignored issues
show
Bug introduced by
It seems like $executable ?: $this can also be of type Carno\Database\SQL\Kit; however, parameter $executor of Carno\Database\SQL\Builder::__construct() does only seem to accept Carno\Database\Contracts\Executable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        return new Builder($name, /** @scrutinizer ignore-type */ $executable ?: $this, $this->fcInjectors());
Loading history...
37
    }
38
39
    /**
40
     * @return array
41
     */
42
    final private function fcInjectors() : array
43
    {
44
        if ($this->chips) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->chips of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
45
            return $this->chips;
46
        }
47
48
        foreach ($this->features as $feature) {
49
            if (method_exists($this, $chip = sprintf('%sChip', $feature))) {
50
                $observers = $this->$chip();
51
                foreach ($observers as $observer) {
52
                    list($action, $program) = $observer;
53
                    $this->chips[$action][] = $program;
54
                }
55
            }
56
        }
57
58
        return $this->chips;
59
    }
60
}
61