Passed
Branch master (117216)
by Pavel
08:06
created

DestinationException::inferenceFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
namespace Bankiru\Seo\Exception;
3
4
class DestinationException extends \RuntimeException implements SeoExceptionInterface
5
{
6
    public static function normalizationFailed($item, $expected = null)
7
    {
8
        $message = sprintf(
9
            'Cannot get slug for item of type %s.',
10
            is_object($item) ? get_class($item) : gettype($item)
11
        );
12
        if ($expected) {
13
            $message .= sprintf(' Item of type %s expected.', $expected);
14
        }
15
16
        return new static($message);
17
    }
18
19
    public static function inferenceFailed($code, array $item, array $fillers)
20
    {
21
        return new static(
22
            sprintf(
23
                'Unable to infer item code %s from %s (known fillers are %s)',
24
                $code,
25
                implode(',', array_keys($item)),
26
                implode(',', array_keys($fillers))
27
            )
28
        );
29
    }
30
31
    public static function circularInference($code, $visited)
32
    {
33
        return new static(sprintf('Circular inference detected: %s <- %s', $code, implode(',', $visited)));
34
    }
35
}
36