Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
32 | 2 | public function generate(string $name, callable $callback): mixed |
|
33 | { |
||
34 | 2 | if (!isset($this->previous[$name])) { |
|
35 | 2 | $this->previous[$name] = []; |
|
36 | } |
||
37 | |||
38 | 2 | $tries = 0; |
|
39 | |||
40 | do { |
||
41 | 2 | $response = $callback(); |
|
42 | |||
43 | 2 | ++$tries; |
|
44 | |||
45 | 2 | if ($tries > $this->retries) { |
|
46 | 1 | throw new \OverflowException(sprintf('Maximum retries of %d reached without finding a unique value', $this->retries)); |
|
47 | } |
||
48 | 2 | } while (array_key_exists(serialize($response), $this->previous[$name])); |
|
49 | |||
50 | 2 | $this->previous[$name][serialize($response)] = null; |
|
51 | |||
52 | 2 | return $response; |
|
53 | } |
||
55 |