| Conditions | 14 |
| Paths | 306 |
| Total Lines | 96 |
| Code Lines | 47 |
| 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 |
||
| 20 | public function render_template( $args ) { |
||
| 21 | //do some work before we locate the template |
||
| 22 | global $current_foogallery; |
||
| 23 | global $current_foogallery_arguments; |
||
| 24 | global $current_foogallery_template; |
||
| 25 | |||
| 26 | //set the arguments |
||
| 27 | $current_foogallery_arguments = $args; |
||
| 28 | |||
| 29 | //load our gallery |
||
| 30 | $current_foogallery = $this->find_gallery( $args ); |
||
| 31 | |||
| 32 | if ( false === $current_foogallery ) { |
||
| 33 | //we could not find the gallery! |
||
| 34 | _e( 'The gallery was not found!', 'foogallery' ); |
||
| 35 | return; |
||
| 36 | } |
||
| 37 | |||
| 38 | //check if the gallery is password protected |
||
| 39 | if ( post_password_required( $current_foogallery->_post ) ) { |
||
| 40 | echo get_the_password_form( $current_foogallery->_post ); |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | //find the gallery template we will use to render the gallery |
||
| 45 | $current_foogallery_template = $this->get_arg( $args, 'template', $current_foogallery->gallery_template ); |
||
| 46 | //set a default if we have no gallery template |
||
| 47 | if ( empty( $current_foogallery_template ) ) { |
||
| 48 | $current_foogallery_template = foogallery_get_default( 'gallery_template' ); |
||
| 49 | } |
||
| 50 | |||
| 51 | //override the template if needed |
||
| 52 | if ( $current_foogallery->gallery_template !== $current_foogallery_template ) { |
||
| 53 | $current_foogallery->gallery_template = $current_foogallery_template; |
||
| 54 | } |
||
| 55 | |||
| 56 | //potentially override attachment_ids from arguments |
||
| 57 | $attachment_ids = $this->get_arg( $args, 'attachment_ids', false ); |
||
|
|
|||
| 58 | if ( $attachment_ids ) { |
||
| 59 | $current_foogallery->attachment_ids = explode( ',', $attachment_ids ); |
||
| 60 | } |
||
| 61 | |||
| 62 | //check if we have any attachments |
||
| 63 | if ( ! $current_foogallery->has_attachments() ) { |
||
| 64 | //no attachments! |
||
| 65 | do_action( "foogallery_template_no_attachments-($current_foogallery_template)", $current_foogallery ); |
||
| 66 | } else { |
||
| 67 | |||
| 68 | //create locator instance |
||
| 69 | $loader = $this->create_locator_instance(); |
||
| 70 | |||
| 71 | if ( false !== ( $template_location = $loader->locate_file( "gallery-{$current_foogallery_template}.php" ) ) ) { |
||
| 72 | |||
| 73 | //we have found a template! |
||
| 74 | do_action( 'foogallery_located_template', $current_foogallery ); |
||
| 75 | do_action( "foogallery_located_template-{$current_foogallery_template}", $current_foogallery ); |
||
| 76 | |||
| 77 | //try to include some JS, but allow template to opt-out based on some condition |
||
| 78 | if ( false !== apply_filters( "foogallery_template_load_js-{$current_foogallery_template}", true, $current_foogallery ) ) { |
||
| 79 | if ( false !== ( $js_location = $loader->locate_file( "gallery-{$current_foogallery_template}.js" ) ) ) { |
||
| 80 | $js_deps = apply_filters( "foogallery_template_js_deps-{$current_foogallery_template}", array(), $current_foogallery ); |
||
| 81 | $js_ver = apply_filters( "foogallery_template_js_ver-{$current_foogallery_template}", FOOGALLERY_VERSION, $current_foogallery ); |
||
| 82 | wp_enqueue_script( "foogallery-template-{$current_foogallery_template}", $js_location['url'], $js_deps, $js_ver ); |
||
| 83 | do_action( 'foogallery_template_enqueue_script', $current_foogallery_template, $js_location['url'] ); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | //try to include some CSS, but allow template to opt-out based on some condition |
||
| 88 | if ( false !== apply_filters( "foogallery_template_load_css-{$current_foogallery_template}", true, $current_foogallery ) ) { |
||
| 89 | if ( false !== ( $css_location = $loader->locate_file( "gallery-{$current_foogallery_template}.css" ) ) ) { |
||
| 90 | $css_deps = apply_filters( "foogallery_template_css_deps-{$current_foogallery_template}", array(), $current_foogallery ); |
||
| 91 | $css_ver = apply_filters( "foogallery_template_css_ver-{$current_foogallery_template}", FOOGALLERY_VERSION, $current_foogallery ); |
||
| 92 | foogallery_enqueue_style( "foogallery-template-{$current_foogallery_template}", $css_location['url'], $css_deps, $css_ver ); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | //finally include the actual php template! |
||
| 97 | if ( $template_location ) { |
||
| 98 | $this->load_gallery_template( $current_foogallery, $template_location['path'] ); |
||
| 99 | } |
||
| 100 | |||
| 101 | //cater for lightbox extensions needing to add styles and javascript |
||
| 102 | $lightbox = foogallery_gallery_template_setting( 'lightbox' ); |
||
| 103 | if ( !empty( $lightbox ) ) { |
||
| 104 | do_action( "foogallery_template_lightbox-{$lightbox}", $current_foogallery ); |
||
| 105 | } |
||
| 106 | |||
| 107 | //we have loaded all files, now let extensions do some stuff |
||
| 108 | do_action( "foogallery_loaded_template", $current_foogallery ); |
||
| 109 | do_action( "foogallery_loaded_template-($current_foogallery_template)", $current_foogallery ); |
||
| 110 | } else { |
||
| 111 | //we could not find a template! |
||
| 112 | _e( 'No gallery template found!', 'foogallery' ); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 246 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: