AppEventTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getTarget() 0 1 ?
A getApp() 0 8 3
A setApp() 0 5 1
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Event;
12
13
use WebinoAppLib\Application\AbstractApplication;
14
15
/**
16
 * Class AppEventTrait
17
 */
18
trait AppEventTrait
19
{
20
    /**
21
     * @var AbstractApplication
22
     */
23
    private $app;
24
25
    /**
26
     * Get the event target
27
     *
28
     * This may be either an object, or the name of a static method.
29
     *
30
     * @return string|object
31
     */
32
    abstract public function getTarget();
33
34
    /**
35
     * @return AbstractApplication
36
     */
37
    public function getApp()
38
    {
39
        $target = $this->getTarget();
40
        if (null === $this->app && $target instanceof AbstractApplication) {
41
            $this->setApp($target);
42
        }
43
        return $this->app;
44
    }
45
46
    /**
47
     * @param AbstractApplication $app
48
     * @return $this
49
     */
50
    protected function setApp(AbstractApplication $app)
51
    {
52
        $this->app = $app;
53
        return $this;
54
    }
55
}
56