Completed
Push — master ( 2edd34...81ce9d )
by Oleg
02:56
created

IdRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 9
cts 13
cp 0.6923
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generateStringId() 0 5 1
A __construct() 0 3 1
A getId() 0 3 1
A generateIntId() 0 9 3
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Tests;
5
6
use Faker\Factory;
7
8
class IdRegistry implements IdHandlerInterface
9
{
10
    private $ids = [];
11
    /**
12
     * @var \Faker\Generator
13
     */
14
    private $faker;
15
16 9
    public function __construct()
17
    {
18 9
        $this->faker = Factory::create();
19 9
    }
20
21
    public function generateStringId(string $entity): string
22
    {
23
        $this->ids[$entity] = $this->faker->unique()->word;
24
25
        return $this->ids[$entity];
26
    }
27
28 3
    public function generateIntId(string $entity, bool $increment): int
29
    {
30 3
        if ($increment) {
31 3
            $this->ids[$entity] = isset($this->ids[$entity]) ? ++$this->ids[$entity] : 1;
32
        } else {
33
            $this->ids[$entity] = $this->faker->unique()->numberBetween(0,100);
34
        }
35
36 3
        return $this->ids[$entity];
37
    }
38
39
    /**
40
     * @param string $entity
41
     * @return mixed
42
     */
43 3
    public function getId(string $entity)
44
    {
45 3
        return $this->ids[$entity] ?? null;
46
    }
47
}
48