ConcurrentUpdateOccurred::ofEntity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
namespace TalisOrm;
4
5
use RuntimeException;
6
7
final class ConcurrentUpdateOccurred extends RuntimeException
8
{
9 4
    public static function ofEntity(Entity $entity): ConcurrentUpdateOccurred
10
    {
11 4
        return new self(sprintf(
12 4
            'A concurrent update occurred of an entity of type "%s" with identifier: %s',
13 4
            get_class($entity),
14 4
            self::renderIdentifier($entity->identifier())
15
        ));
16
    }
17
18
    /**
19
     * @param array<string, mixed> $identifier
20
     */
21 4
    private static function renderIdentifier(array $identifier): string
22
    {
23 4
        $parts = [];
24
25 4
        foreach ($identifier as $columnName => $value) {
26 4
            $parts[] = $columnName . ' = ' . var_export($value, true);
27
        }
28
29 4
        return implode(', ', $parts);
30
    }
31
}
32