Passed
Branch master (b73fcd)
by Thomas
02:06
created

Logger   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 12
c 1
b 0
f 0
dl 0
loc 38
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Zoho\OAuth\Utility;
4
5
use function constant;
6
use function defined;
7
8
class Logger
9
{
10
    public const LOG_FILENAME = 'zoho_oauth.log';
11
12
    public static function warn($msg): void
13
    {
14
        self::writeToFile("WARNING: $msg");
15
    }
16
17
    public static function writeToFile($msg): void
18
    {
19
        $path = defined('LOGGER_PATH') ? constant('LOGGER_PATH') : __DIR__ . '/../../../../';
20
        $filePointer = fopen($path . self::LOG_FILENAME, 'ab');
21
        if (!$filePointer) {
22
            return;
23
        }
24
        fwrite($filePointer, sprintf("%s %s\n", date('Y-m-d H:i:s'), $msg));
25
        fclose($filePointer);
26
    }
27
28
    public static function info($msg): void
29
    {
30
        self::writeToFile("INFO: $msg");
31
    }
32
33
    public static function severe($msg): void
34
    {
35
        self::writeToFile("SEVERE: $msg");
36
    }
37
38
    public static function err($msg): void
39
    {
40
        self::writeToFile("ERROR: $msg");
41
    }
42
43
    public static function debug($msg): void
44
    {
45
        self::writeToFile("DEBUG: $msg");
46
    }
47
}