Passed
Push — master ( b817d9...04ae87 )
by 世昌
02:23
created

Event   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 17 2
A __construct() 0 3 1
1
<?php
2
3
4
namespace suda\application;
5
6
use suda\framework\runnable\Runnable;
7
8
class Event extends \suda\framework\Event
9
{
10
    /**
11
     * @var Application
12
     */
13
    protected $application;
14
15
    /**
16
     * Event constructor.
17
     * @param Application $application
18
     */
19
    public function __construct(Application $application)
20
    {
21
        $this->application = $application;
22
    }
23
24
    /**
25
     * @param string $event
26
     * @param mixed $command
27
     * @param array $args
28
     * @return mixed
29
     */
30
    protected function call(string $event, $command, array &$args)
31
    {
32
        $runnable = new Runnable($command);
33
        $this->application->debug()->debug('invoke {event} event run {runnable}', [
34
            'runnable' => $runnable->getName(),
35
            'event' => $event
36
        ]);
37
        try {
38
            return $runnable->apply($args);
39
        } catch (\Throwable $e) {
40
            $this->application->debug()->error('invoke {event} event run {runnable} error', [
41
                'runnable' => $runnable->getName(),
42
                'event' => $event
43
            ]);
44
            $this->application->debug()->uncaughtException($e);
45
            $this->application->dumpException($e);
46
            return null;
47
        }
48
    }
49
}
50