Completed
Push — master ( 04d2dd...b6c901 )
by Marcin
01:57
created

Formatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLine() 0 6 1
A time() 0 4 2
1
<?php
2
3
namespace Mnabialek\LaravelSqlLogger;
4
5
use Carbon\Carbon;
6
use Mnabialek\LaravelSqlLogger\Objects\SqlQuery;
7
8
class Formatter
9
{
10
    /**
11
     * @var Config
12
     */
13
    private $config;
14
15
    /**
16
     * Formatter constructor.
17
     *
18
     * @param Config $config
19
     */
20
    public function __construct(Config $config)
21
    {
22
        $this->config = $config;
23
    }
24
25
    /**
26
     * Get formatted line.
27
     *
28
     * @param SqlQuery $query
29
     *
30
     * @return string
31
     */
32
    public function getLine(SqlQuery $query)
33
    {
34
        return '/* Query ' . $query->number() . ' - ' . Carbon::now()->toDateTimeString() . ' [' .
35
            $this->time($query->time()) . ']' . " */\n" . $query->get() . ";\n/*" .
36
            str_repeat('=', 50) . "*/\n";
37
    }
38
39
    /**
40
     * Format time.
41
     *
42
     * @param float $time
43
     *
44
     * @return string
45
     */
46
    protected function time($time)
47
    {
48
        return $this->config->useSeconds() ? ($time / 1000.0) . 's' : $time . 'ms';
49
    }
50
}
51