Completed
Push — master ( 316ddc...4c01ea )
by Beniamin
02:32
created

ReferenceManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 7 1
A all() 0 4 1
A generateNextReference() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\SQLBuilder\ReferenceManager;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class ReferenceManager implements ReferenceManagerInterface
18
{
19
    /**
20
     * @var array $references
21
     */
22
    private $references = [];
23
24
    /**
25
     * @var int $referenceCounter
26
     */
27
    private $referenceCounter = 0;
28
29
    /**
30
     * @param mixed $value
31
     *
32
     * @return string
33
     */
34 25
    public function register($value)
35
    {
36 25
        $ref = $this->generateNextReference();
37 25
        $this->references[$ref] = $value;
38
39 25
        return $ref;
40
    }
41
42
    /**
43
     * @return array
44
     */
45 34
    public function all()
46
    {
47 34
        return $this->references;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 25
    private function generateNextReference()
54
    {
55 25
        return sprintf('@[%d]', $this->referenceCounter++);
56
    }
57
}