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

AbstractMysqlDriver::disableInnoDbStats()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
ccs 13
cts 13
cp 1
rs 9.2
cc 4
eloc 11
nc 8
nop 0
crap 4
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