Completed
Push — master ( 1f3fa8...7d4b61 )
by Mike
03:08
created

env.php ➔ setenv()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 22.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use Symfony\Component\Dotenv\Dotenv;
4
5
const APPLICATION_ROOT = __DIR__ . '/../';
6
const DS = DIRECTORY_SEPARATOR;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
7
8
/**
9
 * Sets env variable
10
 *
11
 * @param $name
12
 * @param $value
13
 */
14
function setenv($name, $value)
15
{
16
    putenv($name); // unset variable
17
    putenv("$name=$value");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $name instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $value instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
18
    $_ENV[$name] = $value;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
19
    $_SERVER[$name] = $value;
20
}
21
22
$env = new Dotenv();
23
24
$envPath = __DIR__ . '/../.env';
25
if (file_exists($envPath)) {
26
    $env->populate($env->parse(file_get_contents($envPath), $envPath));
27
}
28
29
$envPath = __DIR__ . '/../.env.dist';
30
$env->populate($env->parse(file_get_contents($envPath), $envPath));
31
32
putenv(sprintf('APPLICATION_VERSION=%s', '@package_version@'));
33
34
$basename = basename(getenv('PHAR_NAME'), '.phar');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
35
$defaultPath = sys_get_temp_dir() . '/.' . $basename;
36
if (!getenv('BACKUP_PATH')) {
37
    setenv('BACKUP_PATH', $defaultPath . '/' . $basename . '-old.phar');
38
}
39
40
if (!getenv('CACHE_PATH')) {
41
    setenv('CACHE_PATH', $defaultPath . '/cache');
42
}
43
44
if (!getenv('TEMPLATE_PATH')) {
45
    setenv('TEMPLATE_PATH', __DIR__ . '/../resources/templates');
46
}
47
48
// use "default format" until architecture is clean enough for "format" parameter
49
setenv('TEMPLATE_PATH', getenv('TEMPLATE_PATH') . '/' . getenv('DEFAULT_FORMAT'));
50