carno-php /
mysql
| 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
Loading history...
|
|||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | final private function fcInjectors() : array |
||
| 43 | { |
||
| 44 | if ($this->chips) { |
||
|
0 ignored issues
–
show
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 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 |