Passed
Push — master ( a4c5f9...448818 )
by Keoghan
18:30
created

EventSubscriber::setXDebug()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 10
cc 4
nc 3
nop 1
crap 4.074
1
<?php
2
3
namespace App\Support\XDebug;
4
5
use App\Events\StartedPorter;
6
use App\Events\StartedPorterService;
7
8
class EventSubscriber
9
{
10
    /** @var XDebug */
11
    protected $xdebug;
12
13 213
    public function __construct(XDebug $xdebug)
14
    {
15 213
        $this->xdebug = $xdebug;
16
    }
17
18 3
    public function setXDebug($event)
19
    {
20 3
        if (($event->service ?? false) && strpos('php_fpm', $event->service) === false) {
21 2
            return;
22
        }
23
24 1
        if (setting('use_xdebug', 'on') === 'off') {
25
            $this->xdebug->turnOff();
26
        }
27
28 1
        $this->xdebug->turnOn();
29
    }
30
31
    /**
32
     * Register the listeners for the subscriber.
33
     *
34
     * @param \Illuminate\Events\Dispatcher $events
35
     *
36
     * @return void
37
     */
38 213
    public function subscribe($events)
39
    {
40 213
        $events->listen(StartedPorter::class, static::class.'@setXDebug');
41 213
        $events->listen(StartedPorterService::class, static::class.'@setXDebug');
42
    }
43
}
44