ContextContextDetector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A detectCurrentContext() 0 8 2
A runningInConsole() 0 8 2
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