QueryAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A executeCommand() 0 4 1
A executeQuery() 0 10 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Agares\MicroORM;
5
6
final class QueryAdapter
7
{
8
    /**
9
     * @var DatabaseAdapterInterface
10
     */
11
    private $dbAdapter;
12
13
    /**
14
     * @var EntityMapperInterface
15
     */
16
    private $entityMapper;
17
18
    public function __construct(DatabaseAdapterInterface $dbAdapter, EntityMapperInterface $entityMapper)
19
    {
20
        $this->dbAdapter = $dbAdapter;
21
        $this->entityMapper = $entityMapper;
22
    }
23
24
    public function executeCommand($command, array $parameters = array())
25
    {
26
        $this->dbAdapter->executeCommand($command, $parameters);
27
    }
28
29
    public function executeQuery(string $query, EntityDefinition $entityDefinition, array $parameters = array())
30
    {
31
        $queryResult = $this->dbAdapter->executeQuery($query, $parameters);
32
        $entities = [];
33
        foreach($queryResult as $resultItem) {
34
            $entities[] = $this->entityMapper->map($resultItem, $entityDefinition);
35
        }
36
37
        return $entities;
38
    }
39
}