| Conditions | 10 |
| Paths | 21 |
| Total Lines | 42 |
| 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 |
||
| 28 | 'import_start' => 'jetpack_import_start', |
||
| 29 | 'import_done' => 'jetpack_import_done', |
||
| 30 | 'import_end' => 'jetpack_import_done', |
||
| 31 | ); |
||
| 32 | |||
| 33 | public static function init() { |
||
| 34 | // Only handle import actions for sites that have agreed to TOS |
||
| 35 | if ( Jetpack::jetpack_tos_agreed() ) { |
||
| 36 | add_action( 'import_start', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
||
| 37 | add_action( 'import_done', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
||
| 38 | add_action( 'import_end', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | public static function log_import_progress( $importer ) { |
||
| 43 | // prefer self-reported importer-names |
||
| 44 | if ( ! $importer ) { |
||
| 45 | // fall back to inferring by calling class name |
||
| 46 | $importer = Jetpack_Sync_Functions::get_calling_importer_class(); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Give known importers a "friendly" name |
||
| 50 | if ( isset( self::$known_importers[ $importer ] ) ) { |
||
| 51 | $importer = self::$known_importers[ $importer ]; |
||
| 52 | } |
||
| 53 | $action = current_filter(); |
||
| 54 | // map action to event name |
||
| 55 | $event_name = self::$action_event_name_map[ $action ]; |
||
| 56 | |||
| 57 | $current_user = wp_get_current_user(); |
||
| 58 | |||
| 59 | // Record event to Tracks |
||
| 60 | jetpack_tracks_record_event( $current_user, $event_name, array( |
||
| 61 | 'importer' => $importer, |
||
| 62 | ) ); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | add_action( 'init', array( 'Jetpack_Import_Stats', 'init' ) ); |
||
| 67 |