Passed
Push — main ( 83c63f...43105b )
by mohsen
10:48 queued 07:59
created

FileDriver::clean()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace MohsenAbrishami\Stethoscope\LogRecord\Drivers;
4
5
use Illuminate\Support\Facades\Storage;
6
use MohsenAbrishami\Stethoscope\LogRecord\Contracts\LogRecordInterface;
7
use MohsenAbrishami\Stethoscope\Traits\MessageCreatorTrait;
8
9
class FileDriver implements LogRecordInterface
10
{
11
    use MessageCreatorTrait;
12
13
    public $storage;
14
15
    public function __construct()
16
    {
17
        $this->storage = Storage::disk(config('stethoscope.log_file_storage.driver'));
18
    }
19
20
    public function record($resourceLogs)
21
    {
22
        $file = config('stethoscope.log_file_storage.path') . now()->format('Y-m-d');
23
24
        $log = '';
25
26
        foreach ($resourceLogs as $resource => $report) {
27
            $method = $resource . 'Message';
28
29
            if (method_exists($this, $method)) {
30
                $log .= $this->$method($report) . "\n";
31
            }
32
        }
33
34
        if ($log != '') {
35
            $log = $this->timeMessage() . "\n" . $log;
36
37
            if ($this->storage->exists($file))
38
                $log = $this->storage->get($file) . "\n \n" . $log;
39
40
            $this->storage->put($file, $log);
41
        }
42
    }
43
44
    public function clean()
45
    {
46
        $this->storage->deleteDirectory(config('stethoscope.log_file_storage.path'));
47
    }
48
}
49