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

Query   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

7 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 get() 0 4 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 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