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

IdRegistry::generateStringId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
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