errorLog()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 16
ccs 0
cts 10
cp 0
crap 20
rs 9.9
1
<?php
2
3
/**
4
 * Simple functions of Application
5
 * be careful with this way
6
 */
7
8
namespace Application;
9
10
/**
11
 * Write Exception to log file
12
 *
13
 * @param \Throwable $exception
14
 *
15
 * @return void
16
 */
17
function errorLog(\Throwable $exception)
18
{
19
    if (getenv('BLUZ_LOG') && is_dir(PATH_DATA . '/logs') && is_writable(PATH_DATA . '/logs')) {
20
        // [Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /var/www/...
21
        $message = '[' . date('r') . '] [' . get_class($exception) . '] '
22
            . '[' . $_SERVER['REQUEST_URI'] . ']'
23
            . $exception->getFile() . ':' . $exception->getLine()
24
            . ': '
25
            . trim($exception->getMessage())
26
            . "\n";
27
28
        // write log
29
        file_put_contents(
30
            PATH_DATA . '/logs/' . date('Y-m-d') . '.log',
31
            $message,
32
            FILE_APPEND | LOCK_EX
33
        );
34
    }
35
}
36