Completed
Push — master ( d10f54...00ced4 )
by
unknown
05:32
created

AbstractDefinition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 02.08.16
6
 * Time: 0:46.
7
 */
8
namespace samsonframework\container\definition;
9
10
use samsonframework\container\definition\exception\ParentDefinitionNotFoundException;
11
12
/**
13
 * Class AbstractDefinition
14
 *
15
 * @package samsonframework\container\definition
16
 */
17
abstract class AbstractDefinition
18
{
19
    /** @var AbstractDefinition Parent definition */
20
    protected $parentDefinition;
21
22
    /**
23
     * AbstractDefinition constructor.
24
     *
25
     * @param AbstractDefinition $parentDefinition
26
     */
27 46
    public function __construct(AbstractDefinition $parentDefinition = null)
28
    {
29 46
        $this->parentDefinition = $parentDefinition;
30 46
    }
31
32
    /**
33
     * End definition and get control to parent
34
     *
35
     * @return AbstractDefinition
36
     * @throws ParentDefinitionNotFoundException
37
     */
38 24
    public function end(): AbstractDefinition
39
    {
40 24
        return $this->getParentDefinition();
41
    }
42
43
    /**
44
     * Get parent definition
45
     *
46
     * @return AbstractDefinition
47
     * @throws ParentDefinitionNotFoundException
48
     */
49 26
    public function getParentDefinition(): AbstractDefinition
50
    {
51 26
        if ($this->parentDefinition === null) {
52 2
            throw new ParentDefinitionNotFoundException();
53
        }
54
55 25
        return $this->parentDefinition;
56
    }
57
}
58