Passed
Push — main ( 23165f...4af278 )
by Miaad
01:25
created

logger   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 15 4
A write() 0 4 3
1
<?php
2
3
namespace BPT;
4
5
class logger {
6
    private static int $log_size;
7
8
    private static $handler;
9
10
11
    public static function init (int $log_size = 10) {
12
        self::$log_size = $log_size;
13
        if (file_exists('BPT.log') && !(filesize('BPT.log') > self::$log_size * 1024 * 1024)) {
14
            $mode = 'a';
15
            $write = false;
16
        }
17
        else {
18
            $mode = 'w';
19
            $write = true;
20
        }
21
22
        self::$handler = fopen('BPT.log', $mode);
23
24
        if ($write) {
25
            fwrite(self::$handler,"♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nTnx for using our library\nSome information about us :\nAuthor : @Im_Miaad\nHelper : @A_LiReza_ME\nChannel : @BPT_CH\nOur Website : https://bptlib.ir\n\nIf you have any problem with our library\nContact to our supports\n♥♥♥♥♥♥♥♥♥♥♥♥♥♥ BPT Library  ♥♥♥♥♥♥♥♥♥♥♥♥♥♥\nINFO : BPT Library LOG STARTED ...\nwarning : this file automatically deleted when its size reached log_size setting, do not delete it manually\n\n");
26
        }
27
    }
28
29
    public static function write($data, $type = '') {
30
        if (!is_null(self::$handler)) {
31
            $text = date('Y/m/d H:i:s') . ( $type === '' ? " : $data\n\n" : " : ⤵\n$type : $data\n\n" );
32
            fwrite(self::$handler, $text);
33
        }
34
    }
35
}