| Conditions | 10 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 88 | public function log( $level, $message ) { |
||
| 89 | |||
| 90 | // Bail out if WordLift log level isn't defined, and WP debug is disabled. |
||
| 91 | if ( ! defined( 'WL_LOG_LEVEL' ) && $level < self::INFO |
||
| 92 | && ( ! defined( 'WP_DEBUG' ) || false === WP_DEBUG ) ) { |
||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | // Bail out if the log message is below the minimum log level. |
||
| 97 | if ( defined( 'WL_LOG_LEVEL' ) && $level < intval( WL_LOG_LEVEL ) ) { |
||
| 98 | return; |
||
| 99 | } |
||
| 100 | |||
| 101 | // Bail out if there's a filter and we don't match it. |
||
| 102 | if ( defined( 'WL_LOG_FILTER' ) && 1 !== preg_match( "/(^|,)$this->class_name($|,)/", WL_LOG_FILTER ) ) { |
||
| 103 | return; |
||
| 104 | } |
||
| 105 | |||
| 106 | // Finally log the message. |
||
| 107 | error_log( sprintf( self::MESSAGE_TEMPLATE, self::$levels[ $level ], $this->class_name, is_array( $message ) ? implode( ', ', $message ) : $message ) ); |
||
| 108 | |||
| 109 | } |
||
| 110 | |||
| 142 |