DBALRepository   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 4
Metric Value
wmc 11
c 4
b 0
f 4
lcom 1
cbo 2
dl 0
loc 61
rs 10
ccs 33
cts 33
cp 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A markAsAdded() 0 4 1
A markAsModified() 0 4 1
A markAsDeleted() 0 4 1
A reset() 0 11 4
A getAdded() 0 4 1
A getModified() 0 4 1
A getDeleted() 0 4 1
1
<?php
2
namespace OpenTribes\Core\Silex\Repository;
3
4
use Doctrine\DBAL\Connection;
5
use Psr\Log\LoggerAwareInterface;
6
use Psr\Log\LoggerAwareTrait;
7
use Psr\Log\NullLogger;
8
9
class DBALRepository implements LoggerAwareInterface{
10
    use LoggerAwareTrait;
11
    /**
12
     * @var Connection
13
     */
14
    protected $connection;
15
    private $added = [];
16
    private $modified = [];
17
    private $deleted = [];
18 33
    public function __construct(Connection $connection){
19 33
        $this->connection = $connection;
20 33
        $this->logger = new NullLogger();
21 33
    }
22 19
    protected function markAsAdded($id){
23 19
        $this->reset($id);
24 19
        $this->added[$id] = $id;
25 19
    }
26 4
    protected function markAsModified($id){
27 4
        $this->reset($id);
28 4
        $this->modified[$id] = $id;
29 4
    }
30 2
    protected function markAsDeleted($id){
31 2
        $this->reset($id);
32 2
        $this->deleted[$id] = $id;
33 2
    }
34 19
    protected function reset($id){
35 19
        if(isset($this->added[$id])){
36 5
            unset($this->added[$id]);
37 5
        }
38 19
        if(isset($this->modified[$id])){
39 2
            unset($this->modified[$id]);
40 2
        }
41 19
        if(isset($this->deleted[$id])){
42 2
            unset($this->deleted[$id]);
43 2
        }
44 19
    }
45
    /**
46
     * @return array
47
     */
48 9
    protected function getAdded()
49
    {
50 9
        return $this->added;
51
    }
52
53
    /**
54
     * @return array
55
     */
56 9
    protected function getModified()
57
    {
58 9
        return $this->modified;
59
    }
60
61
    /**
62
     * @return array
63
     */
64 9
    protected function getDeleted()
65
    {
66 9
        return $this->deleted;
67
    }
68
69
}