ContextContextDetector::runningInConsole()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Facade\FlareClient\Context;
4
5
class ContextContextDetector implements ContextDetectorInterface
6
{
7
    public function detectCurrentContext(): ContextInterface
8
    {
9
        if ($this->runningInConsole()) {
10
            return new ConsoleContext($_SERVER['argv'] ?? []);
11
        }
12
13
        return new RequestContext();
14
    }
15
16
    private function runningInConsole(): bool
17
    {
18
        if (isset($_ENV['APP_RUNNING_IN_CONSOLE'])) {
19
            return $_ENV['APP_RUNNING_IN_CONSOLE'] === 'true';
20
        }
21
22
        return in_array(php_sapi_name(), ['cli', 'phpdb']);
23
    }
24
}
25