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

Indexer::getConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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