Completed
Push — master ( 998c8e...4e843c )
by Hong
03:08
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 0
Metric Value
c 1
b 0
f 0
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\Delegator;
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
 * @since   2.0.15 moved to new namespace
31
 */
32
trait DelegatorAwareTrait
33
{
34
    /**
35
     * the delegator
36
     *
37
     * @var    DelegatorInterface
38
     * @access protected
39
     */
40
    protected $delegator;
41
42
    /**
43
     * {@inheritDoc}
44
     */
45
    public function setDelegator(DelegatorInterface $delegator)
46
    {
47
        $this->delegator = $delegator;
48
        return $this;
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function hasDelegator()/*# : bool */
55
    {
56
        return null !== $this->delegator;
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function getDelegator()/*# : DelegatorInterface */
63
    {
64
        if ($this->hasDelegator()) {
65
            return $this->delegator;
66
        }
67
68
        throw new NotFoundException(
69
            Message::get(Message::MSG_DELEGATOR_UNKNOWN, get_called_class()),
70
            Message::MSG_DELEGATOR_UNKNOWN
71
        );
72
    }
73
}
74