Completed
Pull Request — master (#84)
by Tobias
02:56
created

DiscoveryFailedException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Http\Discovery\Exception;
4
5
use Http\Discovery\Exception;
6
7
/**
8
 * Thrown when all discovery strategies fails to find a resource.
9
 *
10
 * @author Tobias Nyholm <[email protected]>
11
 */
12
final class DiscoveryFailedException extends \Exception implements Exception
13
{
14
    /**
15
     * @var \Exception[]
16
     */
17
    private $exceptions;
18
19
    /**
20
     *
21
     * @param string $message
22
     * @param \Exception[] $exceptions
23
     */
24 6
    public function __construct($message, array $exceptions = [])
25
    {
26 6
        $this->exceptions = $exceptions;
27
28 6
        parent::__construct($message);
29 6
    }
30
31
    /**
32
     * @param \Exception[] $exceptions
33
     */
34 6
    public static function create($exceptions)
35
    {
36 6
        $message = 'Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors';
37 6
        foreach ($exceptions as $e) {
38
            $message .= "\n - ".$e->getMessage();
39 6
        }
40 6
        $message.="\n\n";
41
42 6
        return new self($message, $exceptions);
43
    }
44
45
    /**
46
     * @return \Exception[]
47
     */
48
    public function getExceptions()
49
    {
50
        return $this->exceptions;
51
    }
52
}
53