NoCandidateFoundException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 58.81%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 36
ccs 10
cts 17
cp 0.5881
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A stringify() 0 12 5
1
<?php
2
3
namespace Http\Discovery\Exception;
4
5
use Http\Discovery\Exception;
6
7
/**
8
 * When we have used a strategy but no candidates provided by that strategy could be used.
9
 *
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
final class NoCandidateFoundException extends \Exception implements Exception
13
{
14
    /**
15
     * @param string $strategy
16
     */
17 7
    public function __construct($strategy, array $candidates)
18
    {
19 7
        $classes = array_map(
20
            function ($a) {
21
                return $a['class'];
22 7
            },
23 7
            $candidates
24
        );
25
26 7
        $message = sprintf(
27 7
            'No valid candidate found using strategy "%s". We tested the following candidates: %s.',
28 7
            $strategy,
29 7
            implode(', ', array_map([$this, 'stringify'], $classes))
30
        );
31
32 7
        parent::__construct($message);
33 7
    }
34
35
    private function stringify($mixed)
36
    {
37
        if (is_string($mixed)) {
38
            return $mixed;
39
        }
40
41
        if (is_array($mixed) && 2 === count($mixed)) {
42
            return sprintf('%s::%s', $this->stringify($mixed[0]), $mixed[1]);
43
        }
44
45
        return is_object($mixed) ? get_class($mixed) : gettype($mixed);
46
    }
47
}
48