CrudClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 5 1
A read() 0 11 1
A update() 0 5 1
A delete() 0 5 1
1
<?php
2
3
namespace Hgraca\MicroDbal\Crud;
4
5
use Hgraca\MicroDbal\CrudClientInterface;
6
use Hgraca\MicroDbal\RawClientInterface;
7
8
final class CrudClient implements CrudClientInterface
9
{
10
    /**
11
     * @var RawClientInterface
12
     */
13
    private $client;
14
15
    /**
16
     * @var CrudQueryBuilderInterface
17
     */
18
    private $crudQueryBuilder;
19
20 10
    public function __construct(RawClientInterface $client, CrudQueryBuilderInterface $crudQueryBuilder)
21
    {
22 10
        $this->client = $client;
23 10
        $this->crudQueryBuilder = $crudQueryBuilder;
24 10
    }
25
26 2
    public function create(string $table, array $data)
27
    {
28 2
        list($queryString, $dataBindingsList) = $this->crudQueryBuilder->buildCreateQuery($table, $data);
29 2
        $this->client->executeCommand($queryString, $dataBindingsList);
30 2
    }
31
32 10
    public function read(
33
        string $table,
34
        array $filter = [],
35
        array $orderBy = [],
36
        int $limit = null,
37
        int $offset = 1
38
    ): array {
39 10
        list($queryString, $filterBindingsList) = $this->crudQueryBuilder
40 10
            ->buildReadQuery($table, $filter, $orderBy, $limit, $offset);
41 10
        return $this->client->executeQuery($queryString, $filterBindingsList);
42
    }
43
44 1
    public function update(string $table, array $data, array $filter = [])
45
    {
46 1
        list($queryString, $bindingsList) = $this->crudQueryBuilder->buildUpdateQuery($table, $data, $filter);
47 1
        $this->client->executeCommand($queryString, $bindingsList);
48 1
    }
49
50 2
    public function delete(string $table, array $filter = [])
51
    {
52 2
        list($queryString, $filterBindingsList) = $this->crudQueryBuilder->buildDeleteQuery($table, $filter);
53 2
        $this->client->executeCommand($queryString, $filterBindingsList);
54 2
    }
55
}
56