Completed
Push — master ( c3b1de...399698 )
by Oscar
01:38
created

Query::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Queries;
5
6
use BadMethodCallException;
7
use PDOStatement;
8
use SimpleCrud\Table;
9
10
abstract class Query
11
{
12
    protected const ALLOWED_METHODS = [];
13
14
    protected $table;
15
    protected $query;
16
17
    public function getTable(): Table
18
    {
19
        return $this->table;
20
    }
21
22
    public function __call(string $name, array $arguments)
23
    {
24
        if (!in_array($name, static::ALLOWED_METHODS)) {
25
            throw new BadMethodCallException(sprintf('The method "%s" is not valid', $name));
26
        }
27
28
        $this->query->{$name}(...$arguments);
29
30
        return $this;
31
    }
32
33
    public function __toString()
34
    {
35
        return $this->query->getStatement();
36
    }
37
38
    public function getValues(): array
39
    {
40
        $values = $this->query->getBindValues();
41
        return array_column($values, 0);
42
    }
43
44
    public function get()
45
    {
46
        return $this->run();
47
    }
48
49
    public function run()
50
    {
51
        $this->__invoke();
52
    }
53
54
    public function __invoke(): PDOStatement
55
    {
56
        return $this->query->perform();
57
    }
58
}
59