Completed
Pull Request — master (#119)
by Tobias
05:34
created

NoCandidateFoundException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1.0004

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 12
cts 13
cp 0.9231
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1.0004
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\Discovery\Exception;
6
7
use Http\Discovery\Exception;
8
9
/**
10
 * When we have used a strategy but no candidates provided by that strategy could be used.
11
 *
12
 * @author Tobias Nyholm <[email protected]>
13
 */
14
final class NoCandidateFoundException extends \Exception implements Exception
15
{
16
    /**
17
     * @param string $strategy
18
     * @param array  $candidates
19
     */
20 7
    public function __construct($strategy, array $candidates)
21
    {
22 7
        $classes = array_map(
23 7
            function ($a) {
24
                return $a['class'];
25 7
            },
26
            $candidates
27 7
        );
28
29 7
        $message = sprintf(
30 7
            'No valid candidate found using strategy "%s". We tested the following candidates: %s.',
31 7
            $strategy,
32 7
            implode(', ', $classes)
33 7
        );
34
35 7
        parent::__construct($message);
36 7
    }
37
}
38