Completed
Pull Request — master (#25)
by
unknown
05:59 queued 04:47
created

Command::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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
        } 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