Passed
Push — main ( 6dd21f...0366e5 )
by Thierry
19:47 queued 10:52
created

Driver::afterConnectConfig()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 10
nop 0
dl 0
loc 17
rs 9.5555
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\MySql;
4
5
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...
6
use Lagdo\DbAdmin\Driver\Driver as AbstractDriver;
7
use Lagdo\DbAdmin\Driver\Exception\AuthException;
8
9
class Driver extends AbstractDriver
10
{
11
    /**
12
     * The constructor
13
     *
14
     * @param Utils $utils
15
     * @param array $options
16
     */
17
    public function __construct(Utils $utils, array $options)
18
    {
19
        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

19
        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

19
        parent::/** @scrutinizer ignore-call */ 
20
                __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...
20
21
        $this->server = new Db\Server($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MyS...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

21
        $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...
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\MySql\Driver. Did you mean util?
Loading history...
22
        $this->database = new Db\Database($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MyS...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

22
        $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...
23
        $this->table = new Db\Table($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MySql\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

23
        $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...
24
        $this->query = new Db\Query($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MySql\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

24
        $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...
25
        $this->grammar = new Db\Grammar($this, $this->utils);
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MyS...\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

25
        $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...
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function name()
32
    {
33
        return "MySQL";
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    protected function beforeConnectConfig()
40
    {
41
        // Init config
42
        $this->config->jush = 'sql';
43
        $this->config->drivers = ["MySQLi", "PDO_MySQL"];
44
        $this->config->setTypes([
45
            'Numbers' => ["tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10,
46
                "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21],
47
            'Date and time' => ["date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4],
48
            'Strings' => ["char" => 255, "varchar" => 65535, "tinytext" => 255,
49
                "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295],
50
            'Lists' => ["enum" => 65535, "set" => 64],
51
            'Binary' => ["bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255,
52
                "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295],
53
            'Geometry' => ["geometry" => 0, "point" => 0, "linestring" => 0, "polygon" => 0,
54
                "multipoint" => 0, "multilinestring" => 0, "multipolygon" => 0, "geometrycollection" => 0],
55
        ]);
56
        $this->config->unsigned = ["unsigned", "zerofill", "unsigned zerofill"];
57
        $this->config->operators = ["=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%",
58
            "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP",
59
            "NOT IN", "IS NOT NULL", "SQL"];
60
        $this->config->functions = ["char_length", "date", "from_unixtime", "lower",
61
            "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper"];
62
        $this->config->grouping = ["avg", "count", "count distinct", "group_concat", "max", "min", "sum"];
63
        $this->config->editFunctions = [[
64
            "char" => "md5/sha1/password/encrypt/uuid",
65
            "binary" => "md5/sha1",
66
            "date|time" => "now",
67
        ],[
68
            $this->numberRegex() => "+/-",
69
            "date" => "+ interval/- interval",
70
            "time" => "addtime/subtime",
71
            "char|text" => "concat",
72
        ]];
73
        /**
74
         * Features not available
75
         *
76
         * @var array
77
         */
78
        $this->config->features = ['database', 'table', 'columns', 'sql', 'indexes', 'descidx',
79
            'comment', 'processlist', 'variables', 'drop_col', 'kill', 'dump', 'fkeys_sql'];
80
    }
81
82
    /**
83
     * @inheritDoc
84
     */
85
    protected function afterConnectConfig()
86
    {
87
        if ($this->minVersion(5)) {
88
            $this->config->features[] = 'routine';
89
            $this->config->features[] = 'trigger';
90
            $this->config->features[] = 'view';
91
            if ($this->minVersion(5.1)) {
92
                $this->config->features[] = 'event';
93
                $this->config->features[] = 'partitioning';
94
            }
95
            if ($this->minVersion(8)) {
96
                $this->config->features[] = 'descidx';
97
            }
98
        }
99
        if ($this->minVersion('5.7.8', 10.2)) {
100
            $this->config->structuredTypes[$this->utils->trans->lang('Strings')][] = "json";
0 ignored issues
show
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\MySql\Driver. Did you mean util?
Loading history...
101
            $this->config->types["json"] = 4294967295;
102
        }
103
    }
104
105
    /**
106
     * @inheritDoc
107
     * @throws AuthException
108
     */
109
    protected function createConnection()
110
    {
111
        if (!$this->options('prefer_pdo', false) && extension_loaded("mysqli")) {
112
            $connection = new Db\MySqli\Connection($this, $this->utils, 'MySQLi');
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MyS...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

112
            $connection = /** @scrutinizer ignore-call */ new Db\MySqli\Connection($this, $this->utils, 'MySQLi');

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...
Bug introduced by
'MySQLi' of type string is incompatible with the type Lagdo\DbAdmin\Driver\TranslatorInterface expected by parameter $trans of Lagdo\DbAdmin\Driver\MyS...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

112
            $connection = new Db\MySqli\Connection($this, $this->utils, /** @scrutinizer ignore-type */ 'MySQLi');
Loading history...
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\MySql\Driver. Did you mean util?
Loading history...
113
            return $this->connection = $connection;
114
        }
115
        if (extension_loaded("pdo_mysql")) {
116
            $connection = new Db\Pdo\Connection($this, $this->utils, 'PDO_MySQL');
0 ignored issues
show
Bug introduced by
The call to Lagdo\DbAdmin\Driver\MyS...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

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

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...
Bug introduced by
'PDO_MySQL' of type string is incompatible with the type Lagdo\DbAdmin\Driver\TranslatorInterface expected by parameter $trans of Lagdo\DbAdmin\Driver\MyS...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

116
            $connection = new Db\Pdo\Connection($this, $this->utils, /** @scrutinizer ignore-type */ 'PDO_MySQL');
Loading history...
117
            return $this->connection = $connection;
118
        }
119
        throw new AuthException($this->utils->trans->lang('No package installed to connect to a MySQL server.'));
120
    }
121
122
    /**
123
     * @inheritDoc
124
     */
125
    public function error()
126
    {
127
        $error = preg_replace('~^You have an error.*syntax to use~U', 'Syntax error', parent::error());
128
        // windows-1250 - most common Windows encoding
129
        // if (function_exists('iconv') && !$this->utils->str->isUtf8($error) &&
130
        //     strlen($s = iconv("windows-1250", "utf-8", $error)) > strlen($error)) {
131
        //     $error = $s;
132
        // }
133
        return $this->utils->str->html($error);
0 ignored issues
show
Bug introduced by
The property utils does not exist on Lagdo\DbAdmin\Driver\MySql\Driver. Did you mean util?
Loading history...
134
    }
135
}
136