Passed
Branch master (ae28f9)
by Alexey
03:06
created

ContainerException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1.0046
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Container\Exception;
4
5
use Exception;
6
use Interop\Container\Exception\ContainerException as ContainerExceptionInterface;
7
use RuntimeException;
8
9
/**
10
 * Class ContainerException
11
 *
12
 * @package Venta\Container\Exception
13
 */
14
abstract class ContainerException extends RuntimeException implements ContainerExceptionInterface
15
{
16
    /**
17
     * List of entries referred to cause a circular reference.
18
     *
19
     * @var array
20
     */
21
    protected $referenceChain;
22
23
    /**
24
     * Container entry identifier.
25
     *
26
     * @var string
27
     */
28
    protected $serviceId;
29
30
    /**
31
     * CircularReferenceException constructor.
32
     *
33
     * @param string $entryId
34
     * @param array $referenceChain
35
     * @param Exception|null $previous
36
     * @internal param string $message
37
     */
38 7
    public function __construct(string $entryId, array $referenceChain = [], Exception $previous = null)
39
    {
40 7
        $referenceChain[] = $this->serviceId = $entryId;
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
41 7
        $this->referenceChain = $referenceChain;
42 7
        parent::__construct($this->createMessage($previous), 0, $previous);
43 7
    }
44
45
    /**
46
     * Get reference chain.
47
     *
48
     * @return array
49
     */
50
    public function getReferenceChain(): array
51
    {
52
        return $this->referenceChain;
53
    }
54
55
    /**
56
     * Get container entry identifier which caused a circular reference error.
57
     *
58
     * @return string
59
     */
60
    public function getServiceId(): string
61
    {
62
        return $this->serviceId;
63
    }
64
65
    /**
66
     * Returns exception message
67
     *
68
     * @param Exception $previous
1 ignored issue
show
Documentation introduced by
Should the type for parameter $previous not be null|Exception?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
69
     * @return string
70
     */
71
    abstract protected function createMessage(Exception $previous = null): string;
72
73
}