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

DestinationException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizationFailed() 0 12 3
A inferenceFailed() 0 11 1
A circularInference() 0 4 1
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