DBALRepository::reset()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.2
ccs 11
cts 11
cp 1
cc 4
eloc 7
nc 8
nop 1
crap 4
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
}