Completed
Push — master ( 0765b0...b884d5 )
by Anton
9s
created

_functions.php ➔ errorLog()   C

Complexity

Conditions 20
Paths 61

Size

Total Lines 51
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 20
eloc 40
c 4
b 0
f 0
nc 61
nop 4
dl 0
loc 51
rs 5.5746

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Simple functions of Application
4
 * be careful with this way
5
 * @author  Anton Shevchuk
6
 * @created 25.07.13 13:34
7
 */
8
9
/**
10
 * @namespace
11
 */
12
namespace Application;
13
14
/**
15
 * Write message to log file
16
 *
17
 * @param integer $type
18
 * @param string  $message
19
 * @param string  $file
20
 * @param integer $line
21
 * @return bool
22
 */
23
function errorLog($type, $message, $file = null, $line = null)
24
{
25
    if (getenv('BLUZ_LOG') && is_dir(PATH_DATA .'/logs') && is_writable(PATH_DATA .'/logs')) {
26
        switch ($type) {
27
            case E_PARSE:
28
            case E_ERROR:
29
            case E_CORE_ERROR:
30
            case E_COMPILE_ERROR:
31
            case E_USER_ERROR:
32
                $error = 'error';
33
                break;
34
            case E_WARNING:
35
            case E_USER_WARNING:
36
            case E_COMPILE_WARNING:
37
            case E_RECOVERABLE_ERROR:
38
                $error = 'warning';
39
                break;
40
            case E_NOTICE:
41
            case E_USER_NOTICE:
42
                $error = 'notice';
43
                break;
44
            case E_STRICT:
45
                $error = 'strict';
46
                break;
47
            case E_DEPRECATED:
48
            case E_USER_DEPRECATED:
49
                $error = 'deprecated';
50
                break;
51
            default:
52
                $error = 'undefined';
53
                break;
54
        }
55
56
        // TODO: need default log format
57
        // [Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /var/www/...
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
        $message = "[".date("Y-m-d H:i:s")."] [$error] "
59
            . ($file?:$file) .':'. ($line?:$line)
60
            . "\n\t\t\t"
61
            . trim($message)
62
            . "\n"
63
        ;
64
65
        file_put_contents(
66
            PATH_DATA .'/logs/'.(date('Y-m-d')).'.log',
67
            $message,
68
            FILE_APPEND | LOCK_EX
69
        );
70
    }
71
72
    return false;
73
}
74