Completed
Push — master ( 3c894a...a7b807 )
by Thomas
02:36
created

Indexer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 6
c 3
b 0
f 1
lcom 1
cbo 0
dl 0
loc 60
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getConnection() 0 3 1
A index() 0 6 2
A lookup() 0 4 2
1
<?php
2
3
namespace Gielfeldt\TransactionalPHP;
4
5
/**
6
 * Class Indexer
7
 *
8
 * @package Gielfeldt\TransactionalPHP
9
 */
10
class Indexer
11
{
12
    /**
13
     * @var int[]
14
     */
15
    protected $index = [];
16
17
    /**
18
     * @var Connection
19
     */
20
    protected $connection;
21
22
    /**
23
     * Indexer constructor.
24
     *
25
     * @param Connection $connection
26
     */
27 2
    public function __construct(Connection $connection)
28
    {
29 2
        $this->connection = $connection;
30 2
    }
31
32
    /**
33
     * Get connection.
34
     *
35
     * @return Connection
36
     */
37 1
    public function getConnection() {
38 1
        return $this->connection;
39
    }
40
41
    /**
42
     * Index operation.
43
     *
44
     * @param string $key
45
     *   The key to index undeer.
46
     * @param Operation|null $operation
47
     *   The operation to index.
48
     */
49 1
    public function index($key, Operation $operation = null)
50
    {
51 1
        if ($operation) {
52 1
            $this->index[$key][] = $operation;
53 1
        }
54 1
    }
55
56
    /**
57
     * Lookup operation.
58
     *
59
     * @param string $key
60
     *   The key to look up.
61
     *
62
     * @return array
63
     *   Operations.
64
     */
65 1
    public function lookup($key)
66
    {
67 1
        return isset($this->index[$key]) ? $this->index[$key] : [];
68
    }
69
}
70