MysqlConnectionSpeed::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JildertMiedema\SystemMonitor\Measurements;
6
7
use Illuminate\Database\Capsule\Manager;
8
use JildertMiedema\SystemMonitor\System\MeasurementStore;
9
10 View Code Duplication
final class MysqlConnectionSpeed implements Measurement
11
{
12
    /**
13
     * @var Manager
14
     */
15
    private $manager;
16
17
    public function __construct(Manager $manager)
18
    {
19
        $this->manager = $manager;
20
    }
21
22
    /**
23
     * The name of the.
24
     *
25
     * @return string
26
     */
27
    public function name(): string
28
    {
29
        return 'mysql.speed';
30
    }
31
32
    /**
33
     * Runs the measurement.
34
     *
35
     * @param MeasurementStore $store
36
     * @param array            $data
37
     */
38
    public function run(MeasurementStore $store, array $data)
39
    {
40
        $connection = array_get($data, 'connection');
41
        $key = array_get($data, 'key');
42
43
        $database = $this->manager->getConnection($connection);
44
45
        $timerStart = microtime(true);
46
        $database->select('SELECT 1');
47
        $timerEnd = microtime(true);
48
        $time = round(($timerEnd - $timerStart) * 1000, 4);
49
50
        $store->storeTimer($key, $time . '|ms');
51
    }
52
}
53