Passed
Pull Request — master (#18)
by Cesar
02:33
created

Log::closeHandlers()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 4
c 3
b 0
f 0
nc 4
nop 0
dl 0
loc 6
rs 9.6111
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