Passed
Pull Request — main (#57)
by mohsen
02:54
created

FileDriver::record()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 12
c 0
b 0
f 0
nc 9
nop 1
dl 0
loc 23
rs 9.5555
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
use Illuminate\Support\Str;
9
10
class FileDriver implements LogRecordInterface
11
{
12
    use MessageCreatorTrait;
13
14
    public function record($resourceReports)
15
    {
16
        $file = config('stethoscope.log_file_storage.path') . now()->format('Y-m-d');
17
18
        $this->storage = Storage::disk(config('stethoscope.log_file_storage.driver'));
0 ignored issues
show
Bug Best Practice introduced by
The property storage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
20
        $log = '';
21
22
        foreach ($resourceReports as $resource => $resourceReport) {            
23
            $method = $resource . 'Message';
24
25
            if (method_exists($this, $method)) {
26
                $log .= $this->$method($resourceReport) . "\n";
27
            }
28
        }
29
30
        if ($log != '') {
31
            $log = $this->timeMessage() . "\n" . $log;
32
33
            if ($this->storage->exists($file))
34
                $log = $this->storage->get($file) . "\n \n" . $log;
35
36
            $this->storage->put($file, $log);
37
        }
38
    }
39
}
40