LocatorAwareTrait::setLocator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2016-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Dom\Locator;
12
13
use WebinoDraw\Dom\Locator;
14
use WebinoDraw\Exception;
15
16
/**
17
 * Class LocatorAwareTrait
18
 */
19
trait LocatorAwareTrait
20
{
21
    /**
22
     * @var Locator
23
     */
24
    private $locator;
25
26
    /**
27
     * @return Locator
28
     */
29
    protected function getLocator()
30
    {
31
        if (null === $this->locator) {
32
            throw new Exception\RuntimeException(
33
                'Expects `' . Locator::class . '` injected'
34
            );
35
        }
36
        return $this->locator;
37
    }
38
39
    /**
40
     * @param Locator $locator
41
     * @return $this
42
     */
43
    public function setLocator(Locator $locator)
44
    {
45
        $this->locator = $locator;
46
        return $this;
47
    }
48
}
49