Passed
Push — master ( 349aa8...349aa8 )
by Alec
02:18
created

EnvCheck   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isXterm() 0 5 2
A checkEnvVariable() 0 7 2
A has256ColorSupport() 0 5 2
A hasTrueColorSupport() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Cli\Tools;
4
5
use const AlecRabbit\ENV_COLORTERM;
6
use const AlecRabbit\ENV_DOCKER_TERM;
7
use const AlecRabbit\ENV_TERM;
8
use const AlecRabbit\NEEDLE_256_COLOR;
9
use const AlecRabbit\NEEDLE_TRUECOLOR;
10
use const AlecRabbit\XTERM;
11
12
class EnvCheck
13
{
14
    /**
15
     * @return bool
16
     */
17 1
    public static function isXterm(): bool
18
    {
19
        return
20 1
            static::checkEnvVariable(ENV_TERM, XTERM) ||
21 1
            static::checkEnvVariable(ENV_DOCKER_TERM, XTERM);
22
    }
23
24
    /**
25
     * @param string $varName
26
     * @param string $checkFor
27
     * @return bool
28
     */
29 6
    protected static function checkEnvVariable(string $varName, string $checkFor): bool
30
    {
31 6
        if ($t = getenv($varName)) {
32
            return
33 6
                false !== strpos($t, $checkFor);
34
        }
35 5
        return false;
36
    }
37
38
    /**
39
     * @return bool
40
     */
41 5
    public static function has256ColorSupport(): bool
42
    {
43
        return
44 5
            static::checkEnvVariable(ENV_TERM, NEEDLE_256_COLOR) ||
45 5
            static::checkEnvVariable(ENV_DOCKER_TERM, NEEDLE_256_COLOR);
46
    }
47
48
    /**
49
     * @return bool
50
     */
51 5
    public static function hasTrueColorSupport(): bool
52
    {
53
        return
54 5
            static::checkEnvVariable(ENV_COLORTERM, NEEDLE_TRUECOLOR);
55
    }
56
}
57