ReferenceCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createReference() 0 7 1
A toArray() 0 4 1
A generateNextReference() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of UnderQuery 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\UnderQuery\Reference;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class ReferenceCollection implements ReferenceCollectionInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $references = [];
23
24
    /**
25
     * @var int
26
     */
27
    private $referenceCounter = 0;
28
29
    /**
30
     * @param mixed $value
31
     *
32
     * @return string
33
     */
34 3
    public function createReference($value)
35
    {
36 3
        $ref = $this->generateNextReference();
37 3
        $this->references[$ref] = $value;
38
39 3
        return $ref;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 3
    public function toArray()
46
    {
47 3
        return $this->references;
48
    }
49
50
    /**
51
     * @return string
52
     */
53 3
    private function generateNextReference()
54
    {
55 3
        return sprintf('@ref[%d]', $this->referenceCounter++);
56
    }
57
}