Conditions | 1 |
Paths | 1 |
Total Lines | 2 |
Code Lines | 0 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Metric | Value |
---|---|
cc | 1 |
eloc | 0 |
c | 1 |
b | 0 |
f | 0 |
nc | 1 |
nop | 0 |
dl | 0 |
loc | 2 |
rs | 10 |
1 | <?php |
||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||
2 | |||||
3 | /** |
||||
4 | * src/Utility/DoctrineConnector.php |
||||
0 ignored issues
–
show
|
|||||
5 | * |
||||
6 | * @license https://opensource.org/licenses/MIT MIT License |
||||
0 ignored issues
–
show
|
|||||
7 | * @link http://www.etsisi.upm.es/ ETS de Ingeniería de Sistemas Informáticos |
||||
0 ignored issues
–
show
|
|||||
8 | */ |
||||
0 ignored issues
–
show
|
|||||
9 | |||||
10 | namespace MiW\DemoDoctrine\Utility; |
||||
11 | |||||
12 | use Doctrine\ORM\EntityManager; |
||||
13 | use Doctrine\ORM\EntityManagerInterface; |
||||
14 | use Doctrine\ORM\Tools\Setup; |
||||
15 | use Throwable; |
||||
16 | |||||
17 | /** |
||||
18 | * Class DoctrineConnector |
||||
19 | */ |
||||
0 ignored issues
–
show
|
|||||
20 | final class DoctrineConnector |
||||
21 | { |
||||
0 ignored issues
–
show
|
|||||
22 | private static ?EntityManager $instance = null; |
||||
0 ignored issues
–
show
|
|||||
23 | |||||
24 | /** |
||||
25 | * Generate the Entity Manager |
||||
26 | * |
||||
27 | * @return EntityManagerInterface |
||||
28 | */ |
||||
29 | public static function getEntityManager(): EntityManagerInterface |
||||
0 ignored issues
–
show
|
|||||
30 | { |
||||
0 ignored issues
–
show
|
|||||
31 | if (null !== self::$instance) { |
||||
0 ignored issues
–
show
|
|||||
32 | return self::$instance; |
||||
33 | } |
||||
34 | |||||
35 | if ( |
||||
0 ignored issues
–
show
|
|||||
36 | !isset( |
||||
0 ignored issues
–
show
|
|||||
37 | $_ENV['DATABASE_NAME'], |
||||
0 ignored issues
–
show
|
|||||
38 | $_ENV['DATABASE_USER'], |
||||
0 ignored issues
–
show
|
|||||
39 | $_ENV['DATABASE_PASSWD'], |
||||
0 ignored issues
–
show
|
|||||
40 | $_ENV['ENTITY_DIR'] |
||||
0 ignored issues
–
show
|
|||||
41 | ) |
||||
0 ignored issues
–
show
|
|||||
42 | ) { |
||||
43 | fwrite(STDERR, 'Faltan variables de entorno por definir' . PHP_EOL); |
||||
0 ignored issues
–
show
|
|||||
44 | exit(1); |
||||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return Doctrine\ORM\EntityManagerInterface . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||||
45 | } |
||||
46 | |||||
47 | // Cargar configuración de la conexión |
||||
0 ignored issues
–
show
|
|||||
48 | $dbParams = [ |
||||
0 ignored issues
–
show
|
|||||
49 | 'host' => $_ENV['DATABASE_HOST'] ?? '127.0.0.1', |
||||
0 ignored issues
–
show
|
|||||
50 | 'port' => $_ENV['DATABASE_PORT'] ?? 3306, |
||||
0 ignored issues
–
show
|
|||||
51 | 'dbname' => $_ENV['DATABASE_NAME'], |
||||
0 ignored issues
–
show
|
|||||
52 | 'user' => $_ENV['DATABASE_USER'], |
||||
0 ignored issues
–
show
|
|||||
53 | 'password' => $_ENV['DATABASE_PASSWD'], |
||||
0 ignored issues
–
show
|
|||||
54 | 'driver' => $_ENV['DATABASE_DRIVER'] ?? 'pdo_mysql', |
||||
0 ignored issues
–
show
|
|||||
55 | 'charset' => $_ENV['DATABASE_CHARSET'] ?? 'UTF8', |
||||
0 ignored issues
–
show
|
|||||
56 | ]; |
||||
0 ignored issues
–
show
|
|||||
57 | |||||
58 | $entityDir = dirname(__DIR__, 2) . '/' . $_ENV['ENTITY_DIR']; |
||||
0 ignored issues
–
show
|
|||||
59 | $debug = $_ENV['DEBUG'] ?? false; |
||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 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. ![]() |
|||||
60 | $config = Setup::createAnnotationMetadataConfiguration( |
||||
0 ignored issues
–
show
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. ![]() |
|||||
61 | [ $entityDir ], // paths to mapped entities |
||||
0 ignored issues
–
show
|
|||||
62 | $debug, // developper mode |
||||
0 ignored issues
–
show
|
|||||
63 | ini_get('sys_temp_dir'), // Proxy dir |
||||
0 ignored issues
–
show
|
|||||
64 | null, // Cache implementation |
||||
0 ignored issues
–
show
|
|||||
65 | false // use Simple Annotation Reader |
||||
0 ignored issues
–
show
|
|||||
66 | ); |
||||
67 | $config->setAutoGenerateProxyClasses(true); |
||||
0 ignored issues
–
show
|
|||||
68 | if ($debug) { |
||||
69 | $config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); |
||||
0 ignored issues
–
show
The class
Doctrine\DBAL\Logging\EchoSQLLogger has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
70 | } |
||||
71 | |||||
72 | try { |
||||
73 | $entityManager = EntityManager::create($dbParams, $config); |
||||
74 | } catch (Throwable $e) { |
||||
75 | $msg = sprintf('ERROR (%d): %s', $e->getCode(), $e->getMessage()); |
||||
76 | fwrite(STDERR, $msg . PHP_EOL); |
||||
0 ignored issues
–
show
|
|||||
77 | exit(1); |
||||
0 ignored issues
–
show
|
|||||
78 | } |
||||
79 | |||||
80 | return $entityManager; |
||||
81 | } |
||||
0 ignored issues
–
show
|
|||||
82 | |||||
83 | protected function __construct() |
||||
0 ignored issues
–
show
|
|||||
84 | { |
||||
0 ignored issues
–
show
|
|||||
85 | } |
||||
0 ignored issues
–
show
|
|||||
86 | |||||
87 | private function __clone() |
||||
0 ignored issues
–
show
|
|||||
88 | { |
||||
0 ignored issues
–
show
|
|||||
89 | } |
||||
0 ignored issues
–
show
|
|||||
90 | |||||
91 | // private function __wakeup() |
||||
0 ignored issues
–
show
|
|||||
92 | // { |
||||
0 ignored issues
–
show
|
|||||
93 | // } |
||||
0 ignored issues
–
show
|
|||||
94 | } |
||||
0 ignored issues
–
show
|
|||||
95 |