ApplicationStartedListener::on()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Http\Listener;
15
16
use Micro\Component\EventEmitter\EventInterface;
17
use Micro\Component\EventEmitter\EventListenerInterface;
18
use Micro\Kernel\App\Business\Event\ApplicationReadyEvent;
19
use Micro\Kernel\App\Business\Event\ApplicationReadyEventInterface;
20
use Micro\Plugin\Http\Facade\HttpFacadeInterface;
21
use Symfony\Component\HttpFoundation\Request;
22
23
/**
24
 * @author Stanislau Komar <[email protected]>
25
 */
26
class ApplicationStartedListener implements EventListenerInterface
27
{
28
    public const ALLOWED_MODES = [
29
        'apache2handler',
30
        'apache',
31
        'cgi-fcgi',
32
        'fpm-fcgi',
33
        'litespeed',
34
        'cli-server',
35
    ];
36
37 7
    public function __construct(
38
        private readonly HttpFacadeInterface $httpFacade
39
    ) {
40 7
    }
41
42
    /**
43
     * @param ApplicationReadyEvent $event
44
     *
45
     * @psalm-suppress MoreSpecificImplementedParamType
46
     */
47 6
    public function on(EventInterface $event): void
48
    {
49 6
        $sysenv = $event->systemEnvironment();
0 ignored issues
show
Bug introduced by
The method systemEnvironment() does not exist on Micro\Component\EventEmitter\EventInterface. It seems like you code against a sub-type of Micro\Component\EventEmitter\EventInterface such as Micro\Kernel\App\Busines...tionReadyEventInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        /** @scrutinizer ignore-call */ 
50
        $sysenv = $event->systemEnvironment();
Loading history...
50 6
        if (!\in_array($sysenv, self::ALLOWED_MODES)) {
51
            return;
52
        }
53
54 6
        $request = Request::createFromGlobals();
55 6
        $this->httpFacade->execute($request);
56
    }
57
58 1
    public static function supports(EventInterface $event): bool
59
    {
60 1
        return $event instanceof ApplicationReadyEventInterface;
61
    }
62
}
63