ExitHandler::handleExit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4286
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 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