Completed
Branch master (755019)
by Oliver
12:48 queued 05:47
created

OnEnterObserver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 37.5%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 27
ccs 3
cts 8
cp 0.375
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A update() 0 8 3
1
<?php
2
3
namespace Metabor\Statemachine\Observer;
4
5
use MetaborStd\Statemachine\StatemachineInterface;
6
7
/**
8
 * Triggers automatically an event if the status changes and the new status has it.
9
 *
10
 * @author otischlinger
11
 */
12
class OnEnterObserver implements \SplObserver
13
{
14
    /**
15
     * @var string
16
     */
17
    private $eventName;
18
19
    /**
20
     * @param string $eventName
21
     */
22 1
    public function __construct($eventName = 'onEnter')
23
    {
24 1
        $this->eventName = $eventName;
25 1
    }
26
27
    /**
28
     * @see SplObserver::update()
29
     */
30
    public function update(\SplSubject $stateMachine)
31
    {
32
        if ($stateMachine instanceof StatemachineInterface) {
33
            if ($stateMachine->getCurrentState()->hasEvent($this->eventName)) {
34
                $stateMachine->triggerEvent($this->eventName);
35
            }
36
        }
37
    }
38
}
39