Completed
Push — master ( 61603b...2e6646 )
by Alec
02:56
created

System   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 23
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A inContainer() 0 11 5
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
        if(isset($content)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
30 2
            var_dump('Contents: ' . $content);
0 ignored issues
show
Security Debugging Code introduced by
var_dump('Contents: ' . $content) looks like debug code. Are you sure you do not want to remove it?
Loading history...
31
        }
32 2
        return false;
33
    }
34
}
35