Completed
Push — master ( db026b...56b106 )
by Oliver
04:09 queued 02:28
created

Command   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 11 3
A __toString() 0 4 1
1
<?php
2
3
namespace Metabor\Statemachine;
4
5
use MetaborStd\Event\EventInterface;
6
7
/**
8
 * @author Oliver Tischlinger
9
 */
10
abstract class Command implements \SplObserver
11
{
12
    /**
13
     * @param \SplSubject $subject
14
     *
15
     * @throws \InvalidArgumentException
16
     */
17 6
    public function update(\SplSubject $subject)
18
    {
19 6
        if (!$subject instanceof EventInterface) {
20 2
            throw new \InvalidArgumentException('Command can only be attached to an event!');
21
        }
22 4
        if (method_exists($this, '__invoke')) {
23 2
            call_user_func_array($this, $subject->getInvokeArgs());
24 2
        } else {
25 2
            throw new \Exception('Command should have at least one __invoke method');
26
        }
27 2
    }
28
29
    /**
30
     * Overwrite this to change the name for the Command that is displayed in the graph.
31
     *
32
     * @return string
33
     */
34 1
    public function __toString()
35
    {
36 1
        return get_class($this);
37
    }
38
}
39