PDODbAdapter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A executeCommand() 0 4 1
A executeQuery() 0 6 1
A executeParameterisedQuery() 0 12 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Agares\MicroORM;
5
6
final class PDODbAdapter implements DatabaseAdapterInterface
7
{
8
    /** @var \PDO */
9
    private $pdo;
10
11
    public function __construct(\PDO $pdo)
12
    {
13
        $this->pdo = $pdo;
14
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
15
    }
16
17
    /**
18
     * {@inheritdoc}
19
    */
20
    public function executeCommand(string $command, array $parameters = array())
21
    {
22
        $this->executeParameterisedQuery($command, $parameters);
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function executeQuery(string $query, array $parameters = array()) : array
29
    {
30
        $statement = $this->executeParameterisedQuery($query, $parameters);
31
32
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
33
    }
34
35
    private function executeParameterisedQuery($query, array $parameters) : \PDOStatement
36
    {
37
        $statement = $this->pdo->prepare($query);
38
39
        foreach ($parameters as $name => $value) {
40
            $statement->bindValue($name, $value);
41
        }
42
43
        $statement->execute();
44
45
        return $statement;
46
    }
47
}