Passed
Push — 9.x ( facc1a...80dc3b )
by Andrey
13:27
created

Logger   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 39
rs 10
c 1
b 0
f 0
wmc 11

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 3 1
B logProcess() 0 25 9
A log() 0 5 1
1
<?php
2
3
namespace Helldar\LaravelLangPublisher\Concerns;
4
5
use Helldar\Verbose\Facades\Log;
6
use Helldar\Verbose\Services\Logger as Service;
7
8
trait Logger
9
{
10
    protected function setLogger(): void
11
    {
12
        Service::io($this->output);
13
    }
14
15
    protected function log(...$message): void
16
    {
17
        $value = $this->logProcess($message);
18
19
        Log::write($value);
20
    }
21
22
    protected function logProcess(array $values): string
23
    {
24
        foreach ($values as &$value) {
25
            switch (gettype($value)) {
26
                case 'boolean':
27
                case 'bool':
28
                    $value = $value ? '"true"' : '"false"';
29
                    break;
30
31
                case 'integer':
32
                case 'double':
33
                    $value = '"' . $value . '"';
34
                    break;
35
36
                case 'array':
37
                    $value = implode(', ', $value);
38
                    break;
39
40
                case 'NULL':
41
                    $value = '"null"';
42
                    break;
43
            }
44
        }
45
46
        return implode(' ', $values);
47
    }
48
}
49