Passed
Branch master (79937f)
by compolom
04:21 queued 01:56
created

Builder::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
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