Passed
Branch master (0da502)
by F. Javier
02:00
created

Utils::loadEnv()   B

Complexity

Conditions 7
Paths 14

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 19
c 2
b 0
f 0
nc 14
nop 1
dl 0
loc 30
rs 8.8333
1
<?php
0 ignored issues
show
Coding Style introduced by
Trait found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
There must be no blank lines before the file comment
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "Utils.php" doesn't match the expected filename "utils.php"
Loading history...
introduced by
An error occurred during processing; checking has been aborted. The error message was: implode(): Passing glue string after array is deprecated. Swap the parameters in /home/scrutinizer/.analysis/phpcs/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Commenting/FunctionCommentSniff.php on line 467
Loading history...
2
3
/**
4
 * src/Utility/Utils.php
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
5
 *
6
 * @license  https://opensource.org/licenses/MIT MIT License
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Tag value for @license tag indented incorrectly; expected 1 spaces but found 2
Loading history...
7
 * @link     http://www.etsisi.upm.es/ ETS de Ingeniería de Sistemas Informáticos
0 ignored issues
show
Coding Style introduced by
The tag in position 2 should be the @subpackage tag
Loading history...
Coding Style introduced by
Tag value for @link tag indented incorrectly; expected 4 spaces but found 5
Loading history...
8
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style Documentation introduced by
Missing @package tag in file comment
Loading history...
Coding Style Documentation introduced by
Missing @subpackage tag in file comment
Loading history...
Coding Style Documentation introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
9
10
namespace MiW\DemoDoctrine\Utility;
11
12
use Dotenv\Dotenv;
13
use Throwable;
14
15
/**
16
 * Trait Utils
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
18
trait Utils
19
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for trait Utils
Loading history...
20
    /**
21
     * Load the environment/configuration variables
22
     * defined in .env file + (.env.docker || .env.local)
23
     *
24
     * @param string $dir   project root directory
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 3 found
Loading history...
25
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
26
    public static function loadEnv(string $dir): void
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
27
    {
28
        /** @noinspection PhpIncludeInspection */
29
        require_once $dir . '/vendor/autoload.php';
30
31
        if (!class_exists(Dotenv::class)) {
32
            fwrite(STDERR, 'ERROR: No se ha cargado la clase Dotenv' . PHP_EOL);
33
            die(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
34
        }
35
36
        try {
37
            // Load environment variables from .env file
38
            if (file_exists($dir . '/.env')) {
39
                $dotenv = Dotenv::createMutable($dir, '.env');
40
                $dotenv->load();
41
            } else {
42
                fwrite(STDERR, 'ERROR: no existe el fichero .env' . PHP_EOL);
43
                die(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
44
            }
45
46
            // Overload (if they exist) with .env.docker or .env.local
47
            if (filter_has_var(INPUT_SERVER, 'DOCKER') && file_exists($dir . '/.env.docker')) {
48
                $dotenv = Dotenv::createMutable($dir, '.env.docker');
49
                $dotenv->load();
50
            } elseif (file_exists($dir . '/.env.local')) {
51
                $dotenv = Dotenv::createMutable($dir, '.env.local');
52
                $dotenv->load();
53
            }
54
        } catch (Throwable $e) {
55
            die(get_class($e) . ': ' . $e->getMessage() . PHP_EOL);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
56
        }
57
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end loadEnv()
Loading history...
58
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
59