Conditions | 13 |
Paths | 154 |
Total Lines | 91 |
Code Lines | 45 |
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 | //potentially override attachment_ids from arguments |
||
52 | $attachment_ids = $this->get_arg( $args, 'attachment_ids', false ); |
||
|
|||
53 | if ( $attachment_ids ) { |
||
54 | $current_foogallery->attachment_ids = explode( ',', $attachment_ids ); |
||
55 | } |
||
56 | |||
57 | //check if we have any attachments |
||
58 | if ( ! $current_foogallery->has_attachments() ) { |
||
59 | //no attachments! |
||
60 | do_action( "foogallery_template_no_attachments-($current_foogallery_template)", $current_foogallery ); |
||
61 | } else { |
||
62 | |||
63 | //create locator instance |
||
64 | $loader = $this->create_locator_instance(); |
||
65 | |||
66 | if ( false !== ( $template_location = $loader->locate_file( "gallery-{$current_foogallery_template}.php" ) ) ) { |
||
67 | |||
68 | //we have found a template! |
||
69 | do_action( 'foogallery_located_template', $current_foogallery ); |
||
70 | do_action( "foogallery_located_template-{$current_foogallery_template}", $current_foogallery ); |
||
71 | |||
72 | //try to include some JS, but allow template to opt-out based on some condition |
||
73 | if ( false !== apply_filters( "foogallery_template_load_js-{$current_foogallery_template}", true, $current_foogallery ) ) { |
||
74 | if ( false !== ( $js_location = $loader->locate_file( "gallery-{$current_foogallery_template}.js" ) ) ) { |
||
75 | $js_deps = apply_filters( "foogallery_template_js_deps-{$current_foogallery_template}", array(), $current_foogallery ); |
||
76 | $js_ver = apply_filters( "foogallery_template_js_ver-{$current_foogallery_template}", FOOGALLERY_VERSION, $current_foogallery ); |
||
77 | wp_enqueue_script( "foogallery-template-{$current_foogallery_template}", $js_location['url'], $js_deps, $js_ver ); |
||
78 | do_action( 'foogallery_template_enqueue_script', $current_foogallery_template, $js_location['url'] ); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | //try to include some CSS, but allow template to opt-out based on some condition |
||
83 | if ( false !== apply_filters( "foogallery_template_load_css-{$current_foogallery_template}", true, $current_foogallery ) ) { |
||
84 | if ( false !== ( $css_location = $loader->locate_file( "gallery-{$current_foogallery_template}.css" ) ) ) { |
||
85 | $css_deps = apply_filters( "foogallery_template_css_deps-{$current_foogallery_template}", array(), $current_foogallery ); |
||
86 | $css_ver = apply_filters( "foogallery_template_css_ver-{$current_foogallery_template}", FOOGALLERY_VERSION, $current_foogallery ); |
||
87 | foogallery_enqueue_style( "foogallery-template-{$current_foogallery_template}", $css_location['url'], $css_deps, $css_ver ); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | //finally include the actual php template! |
||
92 | if ( $template_location ) { |
||
93 | $this->load_gallery_template( $current_foogallery, $template_location['path'] ); |
||
94 | } |
||
95 | |||
96 | //cater for lightbox extensions needing to add styles and javascript |
||
97 | $lightbox = foogallery_gallery_template_setting( 'lightbox' ); |
||
98 | if ( !empty( $lightbox ) ) { |
||
99 | do_action( "foogallery_template_lightbox-{$lightbox}", $current_foogallery ); |
||
100 | } |
||
101 | |||
102 | //we have loaded all files, now let extensions do some stuff |
||
103 | do_action( "foogallery_loaded_template", $current_foogallery ); |
||
104 | do_action( "foogallery_loaded_template-($current_foogallery_template)", $current_foogallery ); |
||
105 | } else { |
||
106 | //we could not find a template! |
||
107 | _e( 'No gallery template found!', 'foogallery' ); |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
241 |
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: