CreatesIdentities   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDomainId() 0 14 3
1
<?php
2
3
namespace Nord\Lumen\Core\Traits;
4
5
use Closure;
6
use Nord\Lumen\Core\Domain\DomainId;
7
use Nord\Lumen\Core\Exceptions\FatalError;
8
9
trait CreatesIdentities
10
{
11
    /**
12
     * @param Closure $objectIdExists
13
     *
14
     * @return DomainId
15
     * @throws FatalError
16
     */
17
    private function createDomainId(Closure $objectIdExists)
18
    {
19
        $numTries = 0;
20
21
        do {
22
            $domainId = new DomainId();
23
24
            if ($numTries++ >= 10) {
25
                throw new FatalError('Failed to generate a unique identifier.');
26
            }
27
        } while (call_user_func($objectIdExists, $domainId->getValue()));
28
29
        return $domainId;
30
    }
31
}
32