Passed
Push — main ( 0ad8f5...e78d26 )
by Thierry
28:37 queued 19:50
created

Driver::beforeConnectConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 24
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\Sqlite;
4
5
use Lagdo\DbAdmin\Driver\Exception\AuthException;
6
use Lagdo\DbAdmin\Driver\Utils\Utils;
0 ignored issues
show
Bug introduced by
The type Lagdo\DbAdmin\Driver\Utils\Utils 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...
7
use Lagdo\DbAdmin\Driver\Driver as AbstractDriver;
8
9
use function class_exists;
10
use function extension_loaded;
11
12
class Driver extends AbstractDriver
13
{
14
    /**
15
     * The constructor
16
     *
17
     * @param Utils $utils
18
     * @param array $options
19
     */
20
    public function __construct(Utils $utils, array $options)
21
    {
22
        parent::__construct($utils, $options);
0 ignored issues
show
Bug introduced by
$options of type array is incompatible with the type Lagdo\DbAdmin\Driver\TranslatorInterface expected by parameter $trans of Lagdo\DbAdmin\Driver\Driver::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        parent::__construct($utils, /** @scrutinizer ignore-type */ $options);
Loading history...
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Driver::__construct() has too few arguments starting with options. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        parent::/** @scrutinizer ignore-call */ 
23
                __construct($utils, $options);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
23
24
        $this->server = new Db\Server($this, $this->utils);
0 ignored issues
show
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\Sqlite\Driver. Did you mean util?
Loading history...
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...b\Server::__construct() has too few arguments starting with trans. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $this->server = /** @scrutinizer ignore-call */ new Db\Server($this, $this->utils);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
        $this->database = new Db\Database($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...Database::__construct() has too few arguments starting with trans. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        $this->database = /** @scrutinizer ignore-call */ new Db\Database($this, $this->utils);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
26
        $this->table = new Db\Table($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...Db\Table::__construct() has too few arguments starting with trans. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $this->table = /** @scrutinizer ignore-call */ new Db\Table($this, $this->utils);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
27
        $this->query = new Db\Query($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...Db\Query::__construct() has too few arguments starting with trans. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $this->query = /** @scrutinizer ignore-call */ new Db\Query($this, $this->utils);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
        $this->grammar = new Db\Grammar($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...\Grammar::__construct() has too few arguments starting with trans. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->grammar = /** @scrutinizer ignore-call */ new Db\Grammar($this, $this->utils);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function name()
35
    {
36
        return "SQLite 3";
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    protected function beforeConnectConfig()
43
    {
44
        // Init config
45
        $this->config->jush = 'sqlite';
46
        $this->config->drivers = ["SQLite3", "PDO_SQLite"];
47
        $this->config->setTypes([ //! arrays
48
            'Numbers' => ["integer" => 0, "real" => 0, "numeric" => 0],
49
            'Strings' => ["text" => 0],
50
            'Binary' => ["blob" => 0],
51
        ]);
52
        // $this->config->unsigned = [];
53
        $this->config->operators = ["=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%",
54
            "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"]; // REGEXP can be user defined function;
55
        $this->config->functions = ["hex", "length", "lower", "round", "unixepoch", "upper"];
56
        $this->config->grouping = ["avg", "count", "count distinct", "group_concat", "max", "min", "sum"];
57
        $this->config->editFunctions = [[
58
            // "text" => "date('now')/time('now')/datetime('now')",
59
        ],[
60
            "integer|real|numeric" => "+/-",
61
            // "text" => "date/time/datetime",
62
            "text" => "||",
63
        ]];
64
        $this->config->features = ['columns', 'database', 'drop_col', 'dump', 'indexes', 'descidx',
65
            'move_col', 'sql', 'status', 'table', 'trigger', 'variables', 'view', 'view_trigger'];
66
    }
67
68
    /**
69
     * @inheritDoc
70
     */
71
    protected function afterConnectConfig()
72
    {}
73
74
    /**
75
     * @inheritDoc
76
     * @throws AuthException
77
     */
78
    protected function createConnection()
79
    {
80
        if (!$this->options('prefer_pdo', false) && class_exists("SQLite3")) {
81
            $connection = new Db\Sqlite\Connection($this, $this->utils, 'SQLite3');
0 ignored issues
show
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\Sqlite\Driver. Did you mean util?
Loading history...
Bug introduced by
'SQLite3' of type string is incompatible with the type Lagdo\DbAdmin\Driver\TranslatorInterface expected by parameter $trans of Lagdo\DbAdmin\Driver\Sql...nnection::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

81
            $connection = new Db\Sqlite\Connection($this, $this->utils, /** @scrutinizer ignore-type */ 'SQLite3');
Loading history...
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...nnection::__construct() has too few arguments starting with extension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
            $connection = /** @scrutinizer ignore-call */ new Db\Sqlite\Connection($this, $this->utils, 'SQLite3');

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
82
            return $this->connection = $connection;
83
        }
84
        if (extension_loaded("pdo_sqlite")) {
85
            $connection = new Db\Pdo\Connection($this, $this->utils, 'PDO_SQLite');
0 ignored issues
show
Bug introduced by
'PDO_SQLite' of type string is incompatible with the type Lagdo\DbAdmin\Driver\TranslatorInterface expected by parameter $trans of Lagdo\DbAdmin\Driver\Sql...nnection::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
            $connection = new Db\Pdo\Connection($this, $this->utils, /** @scrutinizer ignore-type */ 'PDO_SQLite');
Loading history...
Bug introduced by
The call to Lagdo\DbAdmin\Driver\Sql...nnection::__construct() has too few arguments starting with extension. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
            $connection = /** @scrutinizer ignore-call */ new Db\Pdo\Connection($this, $this->utils, 'PDO_SQLite');

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
86
            return $this->connection = $connection;
87
        }
88
        throw new AuthException($this->utils->trans->lang('No package installed to open a Sqlite database.'));
89
    }
90
}
91