Completed
Push — master ( 39986e...13eb1c )
by Christian
02:43
created

SelfTestEnvPopulated::isPopulated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\SelfTest\Php;
22
23
use Tenside\Core\SelfTest\AbstractSelfTest;
24
25
/**
26
 * This class tests the that the $_ENV gets populated.
27
 */
28
class SelfTestEnvPopulated extends AbstractSelfTest
29
{
30
    /**
31
     * Check that Suhosin is correctly configured.
32
     *
33
     * @return void
34
     */
35
    public function doTest()
36
    {
37
        $this->setMessage('Check if $_ENV is populated.');
38
39
        if (!$this->isConfigured()) {
40
            $this->markWarning('The php.ini value variables_order should contain "E".');
41
            return;
42
        }
43
44
        if (!$this->isPopulated()) {
45
            $this->markWarning('The super global $_ENV is empty, this will impose problems for spawned processes.');
46
            return;
47
        }
48
49
        $this->markSuccess();
50
    }
51
52
    /**
53
     * Check if php.ini tells to populate.
54
     *
55
     * @return bool
56
     */
57
    private function isConfigured()
58
    {
59
        return (strpos(ini_get('variables_order'), 'E') !== false);
60
    }
61
62
    /**
63
     * Check if Suhosin is loaded.
64
     *
65
     * @return bool
66
     *
67
     * @SuppressWarnings(PHPMD.Superglobals)
68
     * @SuppressWarnings(PHPMD.CamelCaseVariableName)
69
     */
70
    private function isPopulated()
71
    {
72
        $keys = array_keys($_ENV);
73
        return !empty($keys);
74
    }
75
}
76