| Conditions | 6 |
| Paths | 13 |
| Total Lines | 51 |
| 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 |
||
| 32 | function jetpack_eventbrite_block_load_assets( $attr ) { |
||
| 33 | if ( empty( $attr['url'] ) ) { |
||
| 34 | return ''; |
||
| 35 | } |
||
| 36 | |||
| 37 | $matches = array(); |
||
| 38 | preg_match( '/(\d+)$/', $attr['url'], $matches ); |
||
| 39 | $event_id = isset( $matches[1] ) && $matches[1] ? $matches[1] : null; |
||
| 40 | |||
| 41 | if ( ! $event_id ) { |
||
|
|
|||
| 42 | return ''; |
||
| 43 | } |
||
| 44 | |||
| 45 | wp_enqueue_script( 'eventbrite-widget', 'https://www.eventbrite.com/static/widgets/eb_widgets.js', array(), JETPACK__VERSION, true ); |
||
| 46 | |||
| 47 | // Show the embedded version. |
||
| 48 | if ( empty( $attr['useModal'] ) ) { |
||
| 49 | wp_add_inline_script( |
||
| 50 | 'eventbrite-widget', |
||
| 51 | "window.EBWidgets.createWidget({ |
||
| 52 | widgetType: 'checkout', |
||
| 53 | event_id: ${event_id}, |
||
| 54 | iframeContainerId: 'eventbrite-widget-container-${event_id}', |
||
| 55 | });" |
||
| 56 | ); |
||
| 57 | |||
| 58 | return <<<EOT |
||
| 59 | <div id="eventbrite-widget-container-${event_id}"></div> |
||
| 60 | <noscript> |
||
| 61 | <a href="https://www.eventbrite.com/e/${event_id}" rel="noopener noreferrer" target="_blank">Buy Tickets on Eventbrite</a> |
||
| 62 | </noscript> |
||
| 63 | EOT; |
||
| 64 | } |
||
| 65 | |||
| 66 | // Show the modal version. |
||
| 67 | wp_add_inline_script( |
||
| 68 | 'eventbrite-widget', |
||
| 69 | "window.EBWidgets.createWidget({ |
||
| 70 | widgetType: 'checkout', |
||
| 71 | event_id: ${event_id}, |
||
| 72 | modal: true, |
||
| 73 | modalTriggerElementId: 'eventbrite-widget-modal-trigger-${event_id}', |
||
| 74 | });" |
||
| 75 | ); |
||
| 76 | |||
| 77 | return <<<EOT |
||
| 78 | <noscript><a href="https://www.eventbrite.com.au/e/${event_id}" rel="noopener noreferrer" target="_blank"></noscript> |
||
| 79 | <button id="eventbrite-widget-modal-trigger-${event_id}" type="button">Buy Tickets</button> |
||
| 80 | <noscript></a>Buy Tickets on Eventbrite</noscript> |
||
| 81 | EOT; |
||
| 82 | } |
||
| 83 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: