| Conditions | 20 |
| Paths | 61 |
| Total Lines | 51 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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/... |
||
|
|
|||
| 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 |
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.