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

YiiRequestFetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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