Test Failed
Push — main ( 82933d...ebe982 )
by Rafael
02:28
created

Database::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 23
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
/* Copyright (C) 2024      Rafael San José      <[email protected]>
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 3 of the License, or
8
 * any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
namespace Alxarafe\Base;
20
21
use DebugBar\DebugBarException;
0 ignored issues
show
Bug introduced by
The type DebugBar\DebugBarException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use DoliCore\Tools\Debug;
0 ignored issues
show
Bug introduced by
The type DoliCore\Tools\Debug was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use DebugBar\DataCollector\PDO\PDOCollector;
0 ignored issues
show
Bug introduced by
The type DebugBar\DataCollector\PDO\PDOCollector was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Illuminate\Database\Capsule\Manager as CapsuleManager;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Capsule\Manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
26
/**
27
 * Create a PDO database connection
28
 *
29
 * @package Alxarafe\Base
30
 */
31
class Database extends CapsuleManager
32
{
33
    /**
34
     * Construct the database access
35
     *
36
     * @param $db
37
     *
38
     * @throws DebugBarException
39
     */
40
    public function __construct($db)
41
    {
42
        parent::__construct();
43
44
        $this->addConnection([
45
            'driver' => $db->type,
46
            'host' => $db->host,
47
            'database' => $db->name,
48
            'username' => $db->user,
49
            'password' => $db->pass,
50
            'charset' => $db->charset,
51
            'collation' => $db->collation,
52
            'prefix' => $db->prefix,
53
        ]);
54
55
        $this->setAsGlobal();
56
        $this->bootEloquent();
57
58
        // Obtains Eloquent PDO
59
        $pdo = $this->getConnection()->getPdo();
60
        $debugBar = Debug::getDebugBar();
61
        if ($debugBar) {
62
            $debugBar->addCollector(new PDOCollector($pdo));
63
        }
64
    }
65
}
66