Completed
Push — master ( 037c01...3910ea )
by Oscar
01:42
created

Query   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 4 1
A __call() 0 10 2
A __toString() 0 4 1
A getValues() 0 5 1
A run() 0 4 1
A __invoke() 0 4 1
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 run()
45
    {
46
        $this->__invoke();
47
    }
48
49
    public function __invoke(): PDOStatement
50
    {
51
        return $this->query->perform();
52
    }
53
}
54