Completed
Push — master ( c612e7...f3e1c8 )
by Christian
06:23
created

RuntimeHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B setupHome() 0 17 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
1 ignored issue
show
Coding Style introduced by
RuntimeHelper does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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
        // FIXME: check that this really works correctly in CLI mode, maybe the chdir is already enough?
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "check that this really works correctly in CLI mode, maybe the chdir is already enough?"
Loading history...
44
        if (false === getenv('COMPOSER')) {
45
            putenv('COMPOSER=' . $home . DIRECTORY_SEPARATOR . 'composer.json');
46
        }
47
        chdir($home);
48
49
        // Ensure at least one of the environment variables is available.
50
        if (!getenv('COMPOSER_HOME') && !getenv('HOME')) {
51
            putenv('COMPOSER_HOME=' . $home);
52
        }
53
    }
54
}
55