1
|
|
|
<?php |
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
|
|
|
}; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @method Insert insert(array $args = []) |
15
|
|
|
* @method Select select(array $fields = []) |
16
|
|
|
* @method Update update(array $args = []) |
17
|
|
|
* @method Delete delete(integer $id = 0, string $field = 'id') |
18
|
|
|
*/ |
19
|
|
|
class Builder |
20
|
|
|
{ |
21
|
|
|
use Helper; |
22
|
|
|
|
23
|
|
|
private $table; |
24
|
|
|
|
25
|
|
|
private $placeholders = []; |
26
|
|
|
|
27
|
|
|
private $data = []; |
28
|
|
|
|
29
|
16 |
|
public function __construct(?string $table = null) |
30
|
|
|
{ |
31
|
16 |
|
if ($table) { |
32
|
13 |
|
$this->setTable($table); |
33
|
|
|
} |
34
|
16 |
|
} |
35
|
|
|
|
36
|
13 |
|
public function setTable(string $table): Builder |
37
|
|
|
{ |
38
|
13 |
|
$this->table = $table; |
39
|
13 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
6 |
|
public function table(): string |
43
|
|
|
{ |
44
|
6 |
|
return $this->table ? $this->escapeField($this->table) : ''; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
public function placeholders(): array |
48
|
|
|
{ |
49
|
1 |
|
$return = $this->placeholders; |
50
|
1 |
|
$this->placeholders = []; |
51
|
1 |
|
return $return; |
52
|
|
|
} |
53
|
|
|
|
54
|
1 |
|
public function addPlaceholders($placeholders): void |
55
|
|
|
{ |
56
|
1 |
|
$this->placeholders += $placeholders; |
57
|
1 |
|
} |
58
|
|
|
|
59
|
4 |
|
public function __set(string $name, $value): void |
60
|
|
|
{ |
61
|
4 |
|
$this->data[$name] = $value; |
62
|
4 |
|
} |
63
|
|
|
|
64
|
4 |
|
public function __get(string $name) |
65
|
|
|
{ |
66
|
4 |
|
return $this->data[$name] ?? null; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// public function __isset(string $name): bool |
|
|
|
|
70
|
|
|
// { |
71
|
|
|
// return isset($this->data[$name]); |
72
|
|
|
// } |
73
|
|
|
// |
74
|
|
|
// public function __unset(string $name): void |
75
|
|
|
// { |
76
|
|
|
// unset($this->data[$name]); |
77
|
|
|
// } |
78
|
|
|
|
79
|
6 |
|
public function __call(string $name, $args) |
80
|
|
|
{ |
81
|
6 |
|
$class = "Compolomus\\LSQLQueryBuilder\\Parts\\" . ucfirst($name); |
82
|
6 |
|
if (class_exists($class)) { |
83
|
5 |
|
$this->$name = new $class(...$args); |
84
|
4 |
|
$this->$name->setBase($this); |
85
|
4 |
|
return $this->$name; |
86
|
|
|
} |
87
|
1 |
|
throw new BuilderException('Undefined class ' . $class . ' |Builder call|'); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
public function __toString(): string |
91
|
|
|
{ |
92
|
1 |
|
return current($this->data)->__toString(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.