Completed
Push — master ( 5d4578...5f67d7 )
by Filipe
02:35
created

AbstractEvent::getEntityName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of slick/orm package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Orm\Event;
11
12
use \League\Event\AbstractEvent as LeagueAbstractEvent;
13
use Slick\Orm\EntityInterface;
14
15
/**
16
 * Abstract ORM Event
17
 *
18
 * @package Slick\Orm\Event
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
abstract class AbstractEvent extends LeagueAbstractEvent implements EventInterface
22
{
23
24
    /**
25
     * @var string
26
     */
27
    protected $entityName;
28
29
    /**
30
     * @var EntityInterface
31
     */
32
    protected $entity;
33
34
    /**
35
     * @var string
36
     */
37
    protected $action = 'none';
38
39
    /**
40
     * @var mixed
41
     */
42
    protected $params;
43
44
    /**
45
     * All ORM events are from entities
46
     *
47
     * @param EntityInterface $entity
48
     * @param mixed $params additional parameters
49
     */
50 8
    public function __construct(EntityInterface $entity, $params = null)
51
    {
52 8
        $this->setEntity($entity);
53 8
        $this->params = $params;
54 8
    }
55
56
    /**
57
     * Sets the name of the class that triggers the event
58
     *
59
     * @param string $className
60
     * @return self|EventInterface|$this
61
     */
62 2
    public function setEntityName($className)
63
    {
64 2
        $this->entityName = $className;
65 2
        return $this;
66
    }
67
68
    /**
69
     * Gets the entity class name that triggers the event
70
     *
71
     * @return string
72
     */
73 2
    public function getEntityName()
74
    {
75 2
        if (null == $this->entityName) {
76 2
            $this->setEntityName(get_class($this->getEntity()));
77 2
        }
78 2
        return $this->entityName;
79
    }
80
81
    /**
82
     * Set event's action
83
     *
84
     * @param string $action
85
     * @return self|EventInterface|$this
86
     */
87 6
    public function setAction($action)
88
    {
89 6
        $this->action = $action;
90 6
        return $this;
91
    }
92
93
    /**
94
     * Sets the entity object that triggers the event
95
     *
96
     * @param EntityInterface $entity
97
     * @return self|EventInterface|$this
98
     */
99 8
    public function setEntity(EntityInterface $entity)
100
    {
101 8
        $this->entity = $entity;
102 8
        return $this;
103
    }
104
105
    /**
106
     * Gets the entity object that triggers the event
107
     *
108
     * @return EntityInterface
109
     */
110 2
    public function getEntity()
111
    {
112 2
        return $this->entity;
113
    }
114
115
    /**
116
     * Get the event name.
117
     *
118
     * @return string
119
     */
120 6
    public function getName()
121
    {
122 6
        return $this->action;
123
    }
124
}