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

CompositeNotFoundException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 11
cp 0.7272
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 4
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