Select   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gSelect() 0 3 1
A select() 0 17 4
1
<?php
2
/**
3
 * Select fields
4
 * User: moyo
5
 * Date: 25/12/2017
6
 * Time: 12:17 PM
7
 */
8
9
namespace Carno\Database\SQL\Builders;
10
11
use Carno\Database\SQL\Builder;
12
13
trait Select
14
{
15
    /**
16
     * @var string
17
     */
18
    private $bSelect = '*';
19
20
    /**
21
     * @return string
22
     */
23
    protected function gSelect() : string
24
    {
25
        return $this->bSelect;
26
    }
27
28
    /**
29
     * @param array ...$fields
30
     * @return Builder
31
     */
32
    public function select(...$fields) : Builder
33
    {
34
        if (is_string($fields[0] ?? false)) {
35
            if (count($fields) === 1) {
36
                // select(expr)
37
                $this->bSelect = $fields[0];
38
            } else {
39
                // select(f1, f2)
40
                $selects = [];
41
                array_walk($fields, function (string $val) use (&$selects) {
42
                    $selects[] = is_numeric(strpos($val, ' ')) ? $val : sprintf('`%s`', $val);
0 ignored issues
show
introduced by
The condition is_numeric(strpos($val, ' ')) is always true.
Loading history...
43
                });
44
                $this->bSelect = implode(',', $selects);
45
            }
46
        }
47
48
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Carno\Database\SQL\Builders\Select which includes types incompatible with the type-hinted return Carno\Database\SQL\Builder.
Loading history...
49
    }
50
}
51