Completed
Push — master ( 501416...580ac7 )
by David
01:23
created

SQLite   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 6 1
A createTableIfNotExists() 0 12 1
A insert() 0 17 1
1
<?php
2
3
namespace Lloople\PHPUnitExtensions\Runners\SlowestTests;
4
5
use PDO;
6
7
class SQLite extends MySQL
8
{
9
10
    protected $credentials = [
11
        'database' => 'phpunit_results.db',
12
        'table' => 'default',
13
    ];
14
15
    protected function connect(): void
16
    {
17
        $this->connection = new PDO("sqlite:{$this->credentials['database']}");
18
        
19
        $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
20
    }
21
22
    protected function createTableIfNotExists(): void
23
    {
24
        $this->connection->prepare(
25
            "CREATE TABLE IF NOT EXISTS `{$this->credentials['table']}` (
26
                `time` float DEFAULT NULL,
27
                `name` varchar(255) NOT NULL,
28
                `method` varchar(255) DEFAULT NULL,
29
                `class` varchar(255) DEFAULT NULL,
30
                PRIMARY KEY (`name`)
31
            );"
32
        )->execute();
33
    }
34
35
    protected function insert(string $test, string $time): void
36
    {
37
        [$class, $method] = explode('::', $test);
0 ignored issues
show
Bug introduced by
The variable $class does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $method does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
38
39
        $this->connection
40
            ->prepare(
41
                "INSERT INTO `{$this->credentials['table']}` (time, method, class, name) 
42
                VALUES(:time, :method, :class, :name) 
43
                ON CONFLICT(name) DO UPDATE SET time = :time;"
44
            )
45
            ->execute([
46
                'time' => $time,
47
                'method' => $method,
48
                'class' => $class,
49
                'name' => $test,
50
            ]);
51
    }
52
}
53