RuntimeHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B setupHome() 0 16 5
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\Util;
22
23
/**
24
 * Generic helper method collection for being able to provide an web entry point and an cli entry point.
25
 */
26
class RuntimeHelper
27
{
28
    /**
29
     * Detect the correct tenside home dir and set the environment variable.
30
     *
31
     * @param string $home The home directory.
32
     *
33
     * @return void
34
     *
35
     * @throws \InvalidArgumentException For empty value of $home.
36
     */
37
    public static function setupHome($home)
38
    {
39
        if (empty($home)) {
40
            throw new \InvalidArgumentException('Empty home directory encountered.');
41
        }
42
43
        if (false === getenv('COMPOSER')) {
44
            putenv('COMPOSER=' . $home . DIRECTORY_SEPARATOR . 'composer.json');
45
        }
46
        chdir($home);
47
48
        // Ensure at least one of the environment variables is available.
49
        if (!getenv('COMPOSER_HOME') && !getenv('HOME')) {
50
            putenv('COMPOSER_HOME=' . $home);
51
        }
52
    }
53
}
54