Completed
Push — master ( 26275a...558df7 )
by Hong
02:43
created

DelegatorAwareTrait::getDelegator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Reference;
16
17
use Phossa2\Shared\Message\Message;
18
use Phossa2\Shared\Exception\NotFoundException;
19
20
/**
21
 * DelegatorAwareTrait
22
 *
23
 * Implmentation of DelegatorAwareInterface
24
 *
25
 * @package Phossa2\Shared
26
 * @author  Hong Zhang <[email protected]>
27
 * @see     DelegatorAwareInterface
28
 * @version 2.0.8
29
 * @since   2.0.8 added
30
 */
31
trait DelegatorAwareTrait
32
{
33
    /**
34
     * the delegator
35
     *
36
     * @var    DelegatorInterface
37
     * @access protected
38
     */
39
    protected $delegator;
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function setDelegator(DelegatorInterface $delegator)
45
    {
46
        $this->delegator = $delegator;
47
        $delegator->addToLookup($this);
48
49
        return $this;
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function hasDelegator()/*# : bool */
56
    {
57
        return null !== $this->delegator;
58
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    public function getDelegator()/*# : DelegatorInterface */
64
    {
65
        if ($this->hasDelegator()) {
66
            return $this->delegator;
67
        }
68
69
        throw new NotFoundException(
70
            Message::get(Message::MSG_DELEGATOR_UNKNOWN, get_called_class()),
71
            Message::MSG_DELEGATOR_UNKNOWN
72
        );
73
    }
74
}
75