GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 3e31cc...2c1bfd )
by Leonardo
10:36
created

PluginEnvironment::isPluginEnvironmentDev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI;
6
7
use GraphQLAPI\GraphQLAPI\Config\PluginConfigurationHelpers;
8
9
class PluginEnvironment
10
{
11
    public const PLUGIN_ENVIRONMENT = 'PLUGIN_ENVIRONMENT';
12
13
    /**
14
     * The plugins runs in PROD
15
     */
16
    public const PLUGIN_ENVIRONMENT_PROD = 'production';
17
    /**
18
     * The plugins runs in DEV
19
     */
20
    public const PLUGIN_ENVIRONMENT_DEV = 'development';
21
22
    /**
23
     * Return a value for a variable, checking if it is defined in the environment
24
     * first, and in the wp-config.php second
25
     *
26
     * @return mixed
27
     */
28
    protected static function getValueFromEnvironmentOrWPConfig(string $envVariable)
29
    {
30
        if (getenv($envVariable) !== false) {
31
            return getenv($envVariable);
32
        }
33
34
        if (PluginConfigurationHelpers::isWPConfigConstantDefined($envVariable)) {
35
            return PluginConfigurationHelpers::getWPConfigConstantValue($envVariable);
36
        };
37
38
        return null;
39
    }
40
41
    /**
42
     * The label to show when the value is empty
43
     */
44
    public static function getPluginEnvironment(): string
45
    {
46
        $environments = [
47
            self::PLUGIN_ENVIRONMENT_PROD,
48
            self::PLUGIN_ENVIRONMENT_DEV,
49
        ];
50
        $value = self::getValueFromEnvironmentOrWPConfig(self::PLUGIN_ENVIRONMENT);
51
        if (!is_null($value) && in_array($value, $environments)) {
52
            return $value;
53
        }
54
        // Default value
55
        return self::PLUGIN_ENVIRONMENT_PROD;
56
    }
57
58
    public static function isPluginEnvironmentProd(): bool
59
    {
60
        return self::getPluginEnvironment() == self::PLUGIN_ENVIRONMENT_PROD;
61
    }
62
63
    public static function isPluginEnvironmentDev(): bool
64
    {
65
        return self::getPluginEnvironment() == self::PLUGIN_ENVIRONMENT_DEV;
66
    }
67
}
68