MysqlConnectionSpeed   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A name() 4 4 1
A run() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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