Passed
Push — master ( 103a6d...826643 )
by compolom
01:40
created

Builder::__isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Compolomus\LSQLQueryBuilder;
4
5
use Compolomus\LSQLQueryBuilder\{
6
    System\Traits\Helper,
7
    Parts\Insert,
8
    Parts\Select,
9
    Parts\Update,
10
    Parts\Delete,
11
    Parts\Count
12
};
13
14
/**
15
 * @method Insert insert(array $args = [])
16
 * @method Select select(array $fields = [])
17
 * @method Update update(array $args = [])
18
 * @method Delete delete(integer $id = 0, string $field = 'id')
19
 * @method Count count(string $field = '*', ?string $alias = null)
20
 */
21
class Builder
22
{
23
    use Helper;
24
25
    private $table;
26
27
    private $placeholders = [];
28
29
    private $data = [];
30
31
    public function __construct(?string $table = null)
32
    {
33
        if ($table) {
34
            $this->setTable($table);
35
        }
36
    }
37
38
    public function setTable(string $table): Builder
39
    {
40
        $this->table = $table;
41
        return $this;
42
    }
43
44
    public function table(): string
45
    {
46
        return $this->escapeField($this->table);
47
    }
48
49
    public function placeholders(): array
50
    {
51
        $return = $this->placeholders;
52
        $this->placeholders = [];
53
        return $return;
54
    }
55
56
    public function addPlaceholders($placeholders): void
57
    {
58
        $this->placeholders = $this->placeholders + $placeholders;
59
    }
60
61
    public function __set(string $name, $value): void
62
    {
63
        $this->data[$name] = $value;
64
    }
65
66
    public function __get(string $name)
67
    {
68
        return $this->data[$name] ?? null;
69
    }
70
71
    public function __isset(string $name): bool
72
    {
73
        return isset($this->data[$name]);
74
    }
75
76
    public function __unset(string $name): void
77
    {
78
        unset($this->data[$name]);
79
    }
80
81
    public function __call(string $name, $args)
82
    {
83
        $class = "Compolomus\\LSQLQueryBuilder\\Parts\\" . ucfirst($name);
84
        if (class_exists($class)) {
85
            $this->$name = new $class(...$args);
86
            $this->$name->base($this);
87
            return $this->$name;
88
        }
89
    }
90
}
91