ExitHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addHandler() 0 4 1
A handleExit() 0 6 1
1
<?php
2
3
namespace Thruster\Component\ProcessExitHandler;
4
5
use Thruster\Component\EventEmitter\AdvanceEventEmitterInterface;
6
use Thruster\Component\EventEmitter\AdvanceEventEmitterTrait;
7
use Thruster\Component\EventLoop\EventLoopInterface;
8
9
/**
10
 * Class ExitHandler
11
 *
12
 * @package Thruster\Component\ProcessExitHandler
13
 * @author  Aurimas Niekis <[email protected]>
14
 */
15
class ExitHandler implements AdvanceEventEmitterInterface
16
{
17
    use AdvanceEventEmitterTrait;
18
19
    /**
20
     * @var EventLoopInterface
21
     */
22
    protected $loop;
23
24 2
    public function __construct(EventLoopInterface $loop)
25
    {
26 2
        $this->loop = $loop;
27
28 2
        $this->loop->addChild([$this, 'handleExit']);
29 2
    }
30
31 2
    public function addHandler(callable $handler)
32
    {
33 2
        $this->on('exit', $handler);
34 2
    }
35
36 2
    public function handleExit($child, $evChild)
37
    {
38 2
        $event = new ExitEvent($evChild->rpid, $evChild->rstatus);
39
40 2
        $this->emit('exit', $event);
41 2
    }
42
}
43