| Conditions | 18 |
| Paths | 32 |
| Total Lines | 46 |
| Code Lines | 23 |
| 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 |
||
| 37 | public function process_notices() { |
||
|
|
|||
| 38 | |||
| 39 | $notices = $this->get_notices(); |
||
| 40 | |||
| 41 | if ( ! empty( $notices ) && is_array( $notices ) ) { |
||
| 42 | |||
| 43 | foreach ( $notices as $group ) { |
||
| 44 | foreach ( $group as $notice ) { |
||
| 45 | |||
| 46 | if ( $notice instanceof Notice ) { |
||
| 47 | |||
| 48 | if ( $notice->visible === false ) { |
||
| 49 | continue; |
||
| 50 | } |
||
| 51 | |||
| 52 | if ( ! empty( $notice->capability ) ) { |
||
| 53 | if ( ! current_user_can( $notice->capability ) ) { |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | if ( ! empty( $notice->screen ) && is_array( $notice->screen ) && function_exists( 'get_current_screen' ) ) { |
||
| 59 | $screen = get_current_screen(); |
||
| 60 | if ( isset( $screen->id ) ) { |
||
| 61 | if ( ! in_array( $screen->id, $notice->screen ) ) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if ( ! empty( $notice->post ) && is_array( $notice->post ) ) { |
||
| 68 | if ( isset( $_GET['post'] ) ) { |
||
| 69 | if ( ! in_array( intval( $_GET['post'] ), $notice->post ) ) { |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | } else { |
||
| 73 | continue; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->add_notice( $notice ); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 201 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: