Issues (169)

src/Utility/Utils.php (66 issues)

1
<?php
0 ignored issues
show
There must be no blank lines before the file comment
Loading history...
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Filename "Utils.php" doesn't match the expected filename "utils.php"
Loading history...
Class found in ".php" file; use ".inc" extension instead
Loading history...
2
3
/**
4
 * src/Utility/Utils.php
0 ignored issues
show
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
The tag in position 1 should be the @package tag
Loading history...
7
 * @link    https://miw.etsisi.upm.es/ ETS de Ingeniería de Sistemas Informáticos
0 ignored issues
show
The tag in position 2 should be the @subpackage tag
Loading history...
8
 */
0 ignored issues
show
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...
Missing @category tag in file comment
Loading history...
9
10
namespace MiW\DemoDoctrine\Utility;
11
12
use Doctrine\ORM\{ EntityManager, Tools\SchemaTool };
13
use Dotenv\Dotenv;
14
use Throwable;
15
16
/**
17
 * Class Utils
18
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @author tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
19
class Utils
20
{
0 ignored issues
show
Opening brace should be on the same line as the declaration for class Utils
Loading history...
21
    /**
22
     * Load the environment/configuration variables
23
     * defined in .env file + (.env.docker || .env.local)
24
     *
25
     * @param string $dir   project root directory
0 ignored issues
show
Expected 1 spaces after parameter name; 3 found
Loading history...
Parameter comment must start with a capital letter
Loading history...
Parameter comment must end with a full stop
Loading history...
26
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
27
    public static function loadEnv(string $dir): void
0 ignored issues
show
Expected 2 blank lines before function; 0 found
Loading history...
28
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
29
        require_once $dir . '/vendor/autoload.php';
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
File is being conditionally included; use "include_once" instead
Loading history...
30
31
        if (!class_exists(Dotenv::class)) {
0 ignored issues
show
Expected 1 space(s) after NOT operator; 0 found
Loading history...
32
            fwrite(STDERR, 'ERROR: No se ha cargado la clase Dotenv' . PHP_EOL);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
33
            exit(1);
0 ignored issues
show
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
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
38
            if (file_exists($dir . '/.env')) {
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
39
                $dotenv = Dotenv::createMutable($dir, '.env');
40
                $dotenv->load();
41
            } else {
42
                fwrite(STDERR, 'ERROR: no existe el fichero .env' . PHP_EOL);
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
43
                exit(1);
0 ignored issues
show
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
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
47
            if (isset($_SERVER['DOCKER']) && file_exists($dir . '/.env.docker')) {
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
48
                $dotenv = Dotenv::createMutable($dir, '.env.docker');
49
                $dotenv->load();
50
            } elseif (file_exists($dir . '/.env.local')) {
0 ignored issues
show
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
Concat operator must not be surrounded by spaces
Loading history...
51
                $dotenv = Dotenv::createMutable($dir, '.env.local');
52
                $dotenv->load();
53
            }
54
55
            // Requiring Variables to be set
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
56
            $dotenv->required([ 'DATABASE_NAME', 'DATABASE_USER', 'DATABASE_PASSWD', 'SERVER_VERSION' ]);
0 ignored issues
show
Short array syntax is not allowed
Loading history...
57
            $dotenv->required([ 'ENTITY_DIR' ]);
0 ignored issues
show
Short array syntax is not allowed
Loading history...
58
        } catch (Throwable $e) {
59
            fwrite(
60
                STDERR,
61
                'EXCEPCIÓN: ' . $e->getCode() . ' - ' . $e->getMessage()
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
62
            );
63
            exit(1);
0 ignored issues
show
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...
64
        }
0 ignored issues
show
End comment for long condition not found; expected "//end try"
Loading history...
65
    }
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end loadEnv()
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
66
67
    /**
68
     * Drop & Update database schema
69
     *
70
     * @return void
71
     */
72
    public static function updateSchema(): void
73
    {
0 ignored issues
show
Opening brace should be on the same line as the declaration
Loading history...
74
        try {
75
            /** @var EntityManager $e_manager */
0 ignored issues
show
Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
Loading history...
Block comments must be started with /*
Loading history...
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
76
            $e_manager = DoctrineConnector::getEntityManager();
0 ignored issues
show
Variable "e_manager" is not in valid camel caps format
Loading history...
77
            $e_manager->clear();
0 ignored issues
show
Variable "e_manager" is not in valid camel caps format
Loading history...
78
            $metadata = $e_manager->getMetadataFactory()->getAllMetadata();
0 ignored issues
show
Variable "e_manager" is not in valid camel caps format
Loading history...
79
            $sch_tool = new SchemaTool($e_manager);
0 ignored issues
show
Variable "sch_tool" is not in valid camel caps format
Loading history...
Variable "e_manager" is not in valid camel caps format
Loading history...
80
            $sch_tool->dropDatabase();
0 ignored issues
show
Variable "sch_tool" is not in valid camel caps format
Loading history...
81
            $sch_tool->updateSchema($metadata);
0 ignored issues
show
Variable "sch_tool" is not in valid camel caps format
Loading history...
82
        } catch (Throwable $e) {
83
            fwrite(
84
                STDERR,
85
                'EXCEPCIÓN: ' . $e->getCode() . ' - ' . $e->getMessage()
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
86
            );
87
            exit(1);
0 ignored issues
show
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...
88
        }
89
    }
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected //end updateSchema()
Loading history...
90
}
0 ignored issues
show
Expected //end class
Loading history...
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...
91