Completed
Push — master ( 7b7ebd...db1323 )
by Sébastien
02:06
created

AbstractMysqlDriver   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 55
ccs 23
cts 23
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A disableInnoDbStats() 0 20 4
A restoreInnoDbStats() 0 8 2
1
<?php
2
3
namespace Soluble\Schema\Source\Mysql;
4
5
use Soluble\Schema\Db\Wrapper\MysqlConnectionAdapter;
6
7
abstract class AbstractMysqlDriver
8
{
9
10
    /**
11
     *
12
     * @param MysqlConnectionAdapter $adapter
13
     * @param strinbg $schema database name
14
     */
15 23
    public function __construct(MysqlConnectionAdapter $adapter, $schema)
16
    {
17 23
        $this->adapter = $adapter;
0 ignored issues
show
Bug introduced by
The property adapter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18 23
        $this->schema = $schema;
0 ignored issues
show
Bug introduced by
The property schema does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19 23
    }
20
21
22
    /**
23
     * Disable innodbstats will increase speed of metadata lookups
24
     *
25
     * @return void
26
     */
27 6
    protected function disableInnoDbStats()
28
    {
29 6
        $sql = "show global variables like 'innodb_stats_on_metadata'";
30
        try {
31 6
            $results = $this->adapter->query($sql);
32 6
            if (count($results) > 0) {
33 6
                $row = $results->offsetGet(0);
34
35 6
                $value = strtoupper($row['Value']);
36
                // if 'on' no need to do anything
37 6
                if ($value != 'OFF') {
38 6
                    $this->mysql_innodbstats_value = $value;
0 ignored issues
show
Bug introduced by
The property mysql_innodbstats_value does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
                    // disabling innodb_stats
40 6
                    $this->adapter->execute("set global innodb_stats_on_metadata='OFF'");
41 6
                }
42 6
            }
43 6
        } catch (\Exception $e) {
44
            // do nothing, silently fallback
45
        }
46 6
    }
47
48
49
    /**
50
     * Restore old innodbstats variable
51
     * @return void
52
     */
53 6
    protected function restoreInnoDbStats()
54
    {
55 6
        $value = $this->mysql_innodbstats_value;
56 6
        if ($value !== null) {
57
            // restoring old variable
58 6
            $this->adapter->execute("set global innodb_stats_on_metadata='$value'");
59 6
        }
60 6
    }
61
}
62