System   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 7
c 4
b 0
f 1
dl 0
loc 20
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A inContainer() 0 6 3
1
<?php
2
declare(strict_types=1);
3
4
namespace AlecRabbit\Helpers\Classes;
5
6
/**
7
 * Class System
8
 *
9
 * @internal
10
 */
11
final class System
12
{
13
    protected const CGROUP_FILE = '/proc/1/cgroup';
14
    protected const CGROUP_PATTERN = '(lxc|docker|kubepods)';
15
16
    /**
17
     * Determine if run in container
18
     *
19
     * @return bool
20
     *
21
     * @codeCoverageIgnore
22
     *
23
     * @link https://stackoverflow.com/a/20012536
24
     */
25
    public static function inContainer(): bool
26
    {
27
        return
28
            file_exists(self::CGROUP_FILE)
29
            && ($content = file_get_contents(self::CGROUP_FILE))
30
            && preg_match(self::CGROUP_PATTERN, $content);
31
    }
32
}
33