Conditions | 7 |
Paths | 13 |
Total Lines | 57 |
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 |
||
56 | public function sync_import_action( $importer ) { |
||
57 | $import_action = current_filter(); |
||
58 | // Map action to event name. |
||
59 | $sync_action = self::$import_sync_action_map[ $import_action ]; |
||
60 | |||
61 | // Only sync each action once per import. |
||
62 | if ( array_key_exists( $sync_action, $this->synced_actions ) && $this->synced_actions[ $sync_action ] ) { |
||
63 | return; |
||
64 | } |
||
65 | |||
66 | // Mark this action as synced. |
||
67 | $this->synced_actions[ $sync_action ] = true; |
||
68 | |||
69 | // Prefer self-reported $importer value. |
||
70 | if ( ! $importer ) { |
||
71 | // Fall back to inferring by calling class name. |
||
72 | $importer = self::get_calling_importer_class(); |
||
73 | } |
||
74 | |||
75 | // Get $importer from known_importers. |
||
76 | $known_importers = \Jetpack_Sync_Settings::get_setting( 'known_importers' ); |
||
77 | if ( isset( $known_importers[ $importer ] ) ) { |
||
78 | $importer = $known_importers[ $importer ]; |
||
79 | } |
||
80 | |||
81 | $importer_name = $this->get_importer_name( $importer ); |
||
82 | |||
83 | switch ( $sync_action ) { |
||
84 | case 'jetpack_sync_import_start': |
||
85 | /** |
||
86 | * Used for syncing the start of an import |
||
87 | * |
||
88 | * @since 7.3.0 |
||
89 | * |
||
90 | * @module sync |
||
91 | * |
||
92 | * @param string $importer Either a string reported by the importer, the class name of the importer, or 'unknown'. |
||
93 | * @param string $importer_name The name reported by the importer, or 'Unknown Importer'. |
||
94 | */ |
||
95 | do_action( 'jetpack_sync_import_start', $importer, $importer_name ); |
||
96 | break; |
||
97 | |||
98 | case 'jetpack_sync_import_end': |
||
99 | /** |
||
100 | * Used for syncing the end of an import |
||
101 | * |
||
102 | * @since 7.3.0 |
||
103 | * |
||
104 | * @module sync |
||
105 | * |
||
106 | * @param string $importer Either a string reported by the importer, the class name of the importer, or 'unknown'. |
||
107 | * @param string $importer_name The name reported by the importer, or 'Unknown Importer'. |
||
108 | */ |
||
109 | do_action( 'jetpack_sync_import_end', $importer, $importer_name ); |
||
110 | break; |
||
111 | } |
||
112 | } |
||
113 | |||
171 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.