Passed
Push — master ( 2e6646...d21bed )
by Alec
02:36
created

System   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 4

1 Method

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