Passed
Pull Request — master (#18)
by Cesar
03:07 queued 41s
created

Log   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlers() 0 3 1
A getLaravelLogFiles() 0 11 4
A closeHandlers() 0 6 5
1
<?php
2
3
namespace Cesargb\LaravelLog\Helpers;
4
5
use Illuminate\Support\Facades\Log as LogLaravel;
6
use Monolog\Handler\RotatingFileHandler;
7
use Monolog\Handler\StreamHandler;
8
9
class Log
10
{
11
    protected static function getHandlers()
12
    {
13
        return LogLaravel::getHandlers();
14
    }
15
16
    public static function getLaravelLogFiles()
17
    {
18
        $files = [];
19
20
        foreach (self::getHandlers() as $handler) {
21
            if ($handler instanceof StreamHandler && ! $handler instanceof RotatingFileHandler) {
22
                $files[] = $handler->getUrl();
23
            }
24
        }
25
26
        return $files;
27
    }
28
29
    public static function closeHandlers()
30
    {
31
        foreach (self::getHandlers() as $handler) {
32
            if ($handler instanceof StreamHandler && ! $handler instanceof RotatingFileHandler) {
33
                if (method_exists($handler, 'close')) {
34
                    $handler->close();
35
                }
36
            }
37
        }
38
    }
39
}
40