Completed
Push — master ( 6ffec3...6f905d )
by Oleg
06:32
created

IdRegistry   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateStringId() 0 5 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
    public function __construct()
17
    {
18
        $this->faker = Factory::create();
19
    }
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
    public function generateIntId(string $entity, bool $increment): int
29
    {
30
        if ($increment) {
31
            $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
        return $this->ids[$entity];
37
    }
38
39
    /**
40
     * @param string $entity
41
     * @return mixed
42
     */
43
    public function getId(string $entity)
44
    {
45
        return $this->ids[$entity] ?? null;
46
    }
47
}
48