ConcurrentUpdateOccurred::renderIdentifier()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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