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.

LoadEnvironmentVariables::setEnvironmentFilePath()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Application\Bootstrap\Bootstrapers;
4
5
use Dotenv\Dotenv;
6
use Dotenv\Exception\InvalidPathException;
7
use Symfony\Component\Console\Input\ArgvInput;
8
use Nip\Application;
9
10
/**
11
 * Class LoadEnvironmentVariables
12
 *
13
 * @package Nip\Application\Bootstrap\Bootstrapers
14
 */
15
class LoadEnvironmentVariables extends AbstractBootstraper
16
{
17
    /**
18
     * Bootstrap the given application.
19
     *
20
     * @param  Application $app
21
     * @return void
22
     */
23
    public function bootstrap(Application $app)
24
    {
25
        if ($app->configurationIsCached()) {
26
            return;
27
        }
28
29
        $this->checkForSpecificEnvironmentFile($app);
30
        try {
31
            (new Dotenv($app->environmentPath(), $app->environmentFile()))->load();
32
        } catch (InvalidPathException $e) {
33
            //
34
        }
35
    }
36
37
    /**
38
     * Detect if a custom environment file matching the APP_ENV exists.
39
     *
40
     * @param  Application $app
41
     * @return void
42
     */
43
    protected function checkForSpecificEnvironmentFile($app)
44
    {
45
//        if (php_sapi_name() == 'cli' && with($input = new ArgvInput)->hasParameterOption('--env')) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
//            $this->setEnvironmentFilePath(
47
//                $app, $app->environmentFile() . '.' . $input->getParameterOption('--env')
48
//            );
49
//        }
50
        if (!env('APP_ENV') || empty($file)) {
0 ignored issues
show
Bug introduced by
The variable $file seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
51
            return;
52
        }
53
        $this->setEnvironmentFilePath(
54
            $app,
55
            $app->environmentFile() . '.' . env('APP_ENV')
56
        );
57
    }
58
59
    /**
60
     * Load a custom environment file.
61
     *
62
     * @param  Application $app
63
     * @param  string $file
64
     * @return void
65
     */
66
    protected function setEnvironmentFilePath($app, $file)
67
    {
68
        if (file_exists($app->environmentPath() . '/' . $file)) {
69
            $app->loadEnvironmentFrom($file);
70
        }
71
    }
72
}
73