| Conditions | 11 |
| Paths | 13 |
| Total Lines | 54 |
| 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 |
||
| 71 | function autoloader( $class_name ) { |
||
| 72 | global $jetpack_packages_classes; |
||
| 73 | |||
| 74 | if ( isset( $jetpack_packages_classes[ $class_name ] ) ) { |
||
| 75 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
||
| 76 | // TODO ideally we shouldn't skip any of these, see: https://github.com/Automattic/jetpack/pull/12646. |
||
| 77 | $ignore = in_array( |
||
| 78 | $class_name, |
||
| 79 | array( |
||
| 80 | 'Automattic\Jetpack\JITM', |
||
| 81 | 'Automattic\Jetpack\Connection\Manager', |
||
| 82 | 'Automattic\Jetpack\Connection\Manager_Interface', |
||
| 83 | 'Automattic\Jetpack\Connection\XMLRPC_Connector', |
||
| 84 | 'Jetpack_Options', |
||
| 85 | 'Jetpack_Signature', |
||
| 86 | 'Automattic\Jetpack\Sync\Main', |
||
| 87 | 'Automattic\Jetpack\Constants', |
||
| 88 | 'Automattic\Jetpack\Tracking', |
||
| 89 | 'Automattic\Jetpack\Plugin\Tracking', |
||
| 90 | ), |
||
| 91 | true |
||
| 92 | ); |
||
| 93 | if ( ! $ignore && function_exists( 'did_action' ) && ! did_action( 'plugins_loaded' ) ) { |
||
| 94 | _doing_it_wrong( |
||
| 95 | esc_html( $class_name ), |
||
| 96 | sprintf( |
||
| 97 | /* translators: %s Name of a PHP Class */ |
||
| 98 | esc_html__( 'Not all plugins have loaded yet but we requested the class %s', 'jetpack' ), |
||
| 99 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
| 100 | $class_name |
||
| 101 | ), |
||
| 102 | esc_html( $jetpack_packages_classes[ $class_name ]['version'] ) |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | if ( file_exists( $jetpack_packages_classes[ $class_name ]['path'] ) ) { |
||
| 108 | require_once $jetpack_packages_classes[ $class_name ]['path']; |
||
| 109 | |||
| 110 | // Extend autoloaded class with legacy class, if it exists. |
||
| 111 | if ( class_exists( $class_name ) && method_exists( $class_name, 'getLegacyName' ) ) { |
||
| 112 | eval( 'class ' . $class_name::getLegacyName() . ' extends ' . $class_name . '{}' ); |
||
| 113 | |||
| 114 | if ( class_exists( $class_name::getLegacyName() ) ) { |
||
| 115 | echo $class_name::getLegacyName() . "exists!\n<br>"; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | return true; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return false; |
||
| 124 | } |
||
| 125 | |||
| 129 |