Passed
Pull Request — master (#19)
by
unknown
04:48 queued 01:58
created

YiiRequestFetcher::fetchRequest()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 11.1035

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 4
nop 0
dl 0
loc 16
ccs 3
cts 8
cp 0.375
crap 11.1035
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry\Http;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Sentry\Integration\RequestFetcher;
10
use Sentry\Integration\RequestFetcherInterface;
11
12
use const PHP_SAPI;
13
14
class YiiRequestFetcher implements RequestFetcherInterface
15
{
16 13
    public function __construct(
17
        private ContainerInterface $container
18
    ) {
19
    }
20
21
    /** @psalm-suppress  MixedInferredReturnType */
22 9
    public function fetchRequest(): ?ServerRequestInterface
23
    {
24 9
        if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
25 9
            return null;
26
        }
27
28
        if ($this->container->has(ServerRequestInterface::class)) {
29
            /** @psalm-suppress  MixedAssignment */
30
            $result = $this->container->get(ServerRequestInterface::class);
31
32
            if ($result instanceof ServerRequestInterface) {
33
                return $result;
34
            }
35
        }
36
37
        return (new RequestFetcher())->fetchRequest();
38
    }
39
}
40