Passed
Pull Request — master (#274)
by Alexander
07:59
created

CompositeNotFoundException::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.3244

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 17
ccs 8
cts 11
cp 0.7272
crap 4.3244
rs 9.9332
1
<?php
2
3
namespace Yiisoft\Di;
4
5
use Exception;
6
use Throwable;
7
use InvalidArgumentException;
8
use Psr\Container\NotFoundExceptionInterface;
9
10
/**
11
 * CompositeNotFoundException is thrown when no definition or class was found in the composite container for a given ID.
12
 * It contains all exceptions thrown by containers registered in the composite container.
13
 */
14
final class CompositeNotFoundException extends Exception implements NotFoundExceptionInterface
15
{
16
    /**
17
     * @param Throwable[] $exceptions Exceptions of parent containers.
18
     */
19 7
    public function __construct(array $exceptions)
20
    {
21 7
        $message = '';
22
23 7
        $number = 1;
24 7
        foreach ($exceptions as $exception) {
25 5
            if (!$exception instanceof Throwable) {
26
                $type = is_object($exception) ? get_class($exception) : gettype($exception);
27
                $message = sprintf('An array of \Throwable is expected, "%s" given.', $type);
28
                throw new InvalidArgumentException($message);
29
            }
30
31 5
            $message .= "\n    Container #$number: {$exception->getMessage()}";
32 5
            $number++;
33
        }
34
35 7
        parent::__construct(sprintf("No definition or class found or resolvable in composite container:%s", $message));
36 7
    }
37
}
38