Completed
Push — master ( 038254...115ca0 )
by Alejandro
06:27
created

EntityDoesNotExistException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromEntityAndConditions() 0 6 1
A serializeParams() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Core\Exception;
6
7
use function implode;
8
use function sprintf;
9
10
class EntityDoesNotExistException extends RuntimeException
11
{
12 1
    public static function createFromEntityAndConditions($entityName, array $conditions)
13
    {
14 1
        return new self(sprintf(
15 1
            'Entity of type %s with params [%s] does not exist',
16 1
            $entityName,
17 1
            static::serializeParams($conditions)
18
        ));
19
    }
20
21 1
    private static function serializeParams(array $params)
22
    {
23 1
        $result = [];
24 1
        foreach ($params as $key => $value) {
25 1
            $result[] = sprintf('"%s" => "%s"', $key, $value);
26
        }
27
28 1
        return implode(', ', $result);
29
    }
30
}
31