Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
2 / 4 |
|
50.00% |
2 / 4 |
CRAP | n/a |
0 / 0 |
|
| BrianHenryIE\WP_Plugin_Updater\str_underscore_to_dash | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| BrianHenryIE\WP_Plugin_Updater\str_dash_to_underscore | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| BrianHenryIE\WP_Plugin_Updater\str_dash_to_next_capitalised_first_lower | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| BrianHenryIE\WP_Plugin_Updater\bh_wp_is_rest_request | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Some helpful functions for the plugin. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wp-plugin-updater |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WP_Plugin_Updater; |
| 9 | |
| 10 | // PRIVATE – API WILL CHANGE WITHOUT NOTICE. |
| 11 | |
| 12 | if ( ! function_exists( '\BrianHenryIE\WP_Plugin_Updater\str_underscore_to_dash' ) ) { |
| 13 | /** |
| 14 | * Convert a string from snake case to kebab case. |
| 15 | * |
| 16 | * @param string $string |
| 17 | */ |
| 18 | function str_underscore_to_dash( string $string ): string { |
| 19 | return str_replace( '_', '-', $string ); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | if ( ! function_exists( '\BrianHenryIE\WP_Plugin_Updater\str_dash_to_underscore' ) ) { |
| 24 | /** |
| 25 | * Convert a string from kebab case to snake case. |
| 26 | * |
| 27 | * @param string $string |
| 28 | */ |
| 29 | function str_dash_to_underscore( string $string ): string { |
| 30 | return str_replace( '-', '_', $string ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if ( ! function_exists( '\BrianHenryIE\WP_Plugin_Updater\str_dash_to_next_capitalised_first_lower' ) ) { |
| 35 | /** |
| 36 | * Convert a string from kebab case to camel case. |
| 37 | * |
| 38 | * E.g. `bh-wc-zelle-gateway-licence` -> `bhWcZelleGatewayLicence`. |
| 39 | * |
| 40 | * @param string $string |
| 41 | */ |
| 42 | function str_dash_to_next_capitalised_first_lower( string $string ): string { |
| 43 | return lcfirst( str_replace( ' ', '', ucwords( str_replace( '-', ' ', $string ) ) ) ); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if ( ! function_exists( '\BrianHenryIE\WP_Plugin_Updater\bh_wp_is_rest_request' ) ) { |
| 48 | |
| 49 | function bh_wp_is_rest_request(): bool { |
| 50 | return isset( $_GET['rest_route'] ) || str_contains( $_SERVER['REQUEST_URI'], '/wp-json/' ); |
| 51 | } |
| 52 | } |