MemorySequenceRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
}