IdGenerator::newIdFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Infrastructure\IdentityManagement;
4
5
use LogicException;
6
use Ramsey\Uuid\UuidFactoryInterface;
7
use Ramsey\Uuid\UuidInterface;
8
use Throwable;
9
10
abstract class IdGenerator
11
{
12
    private $uuidFactory;
13
14
    public function __construct(UuidFactoryInterface $uuidFactory)
15
    {
16
        $this->uuidFactory = $uuidFactory;
17
    }
18
19
    protected function newIdFor(string $type): UuidInterface
20
    {
21
        try {
22
            return $this->uuidFactory->uuid4();
23
        } catch (Throwable $uuidException) {
24
            throw new LogicException(sprintf(
25
                'Could not generate the %s id: %s',
26
                $type,
27
                $uuidException->getMessage()
28
            ), $uuidException->getCode(), $uuidException);
29
        }
30
    }
31
}
32