MemorySequenceRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generate() 0 12 3
A exists() 0 3 1
1
<?php
2
3
namespace BWC\Share\Data\Sequence;
4
5
6
class MemorySequenceRepository implements SequenceRepositoryInterface
7
{
8
    /** @var \BWC\Share\Data\Sequence\SequenceGeneratorInterface */
9
    private $_generator;
10
11
    /** @var array   name => value => true */
12
    private $_data = array();
13
14
15
16
    function __construct(SequenceGeneratorInterface $generator) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
        $this->_generator = $generator;
18
    }
19
20
21
    /**
22
     * @param string $name
23
     * @return string
24
     */
25
    function generate($name = 'default') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
        $result = null;
27
        for ($i=0; $i<10; $i++) {
28
            $value = $this->_generator->generate();
29
            if (!$this->exists($value, $name)) {
30
                $result = $value;
31
                $this->_data[$name][$result] = true;
32
                break;
33
            }
34
        }
35
        return $result;
36
    }
37
38
    /**
39
     * @param string $value
40
     * @param string $name
41
     * @return bool
42
     */
43
    function exists($value, $name = 'default') {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
44
        return @$this->_data[$name][$value];
45
    }
46
47
}