Conditions | 11 |
Paths | 32 |
Total Lines | 66 |
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 |
||
52 | function load_assets( $attributes ) { |
||
53 | |||
54 | Jetpack_Gutenberg::load_assets_as_required( FEATURE_NAME ); |
||
55 | |||
56 | $classes = array(); |
||
57 | $class_name = get_attribute( $attributes, 'className' ); |
||
58 | $style = get_attribute( $attributes, 'style' ); |
||
59 | |||
60 | if ( 'wide' === $style && jetpack_is_mobile() ) { |
||
61 | $attributes = array_merge( $attributes, array( 'style' => 'standard' ) ); |
||
62 | $classes[] = 'is-style-mobile'; |
||
63 | } |
||
64 | |||
65 | // Handles case of deprecated version using theme instead of block styles. |
||
66 | if ( ! $class_name || strpos( $class_name, 'is-style-' ) === false ) { |
||
67 | $classes[] = sprintf( 'is-style-%s', $style ); |
||
68 | } |
||
69 | |||
70 | if ( array_key_exists( 'rid', $attributes ) && is_array( $attributes['rid'] ) && count( $attributes['rid'] ) > 1 ) { |
||
71 | $classes[] = 'is-multi'; |
||
72 | } |
||
73 | if ( array_key_exists( 'negativeMargin', $attributes ) && $attributes['negativeMargin'] ) { |
||
74 | $classes[] = 'has-no-margin'; |
||
75 | } |
||
76 | $classes = Blocks::classes( FEATURE_NAME, $attributes, $classes ); |
||
77 | $content = '<div class="' . esc_attr( $classes ) . '">'; |
||
78 | |||
79 | $script_url = build_embed_url( $attributes ); |
||
80 | |||
81 | if ( Blocks::is_amp_request() ) { |
||
82 | // Extract params from URL since it had jetpack_opentable_block_url filters applied. |
||
83 | $url_query = \wp_parse_url( $script_url, PHP_URL_QUERY ) . '&overlay=false&disablega=false'; |
||
|
|||
84 | |||
85 | $src = "https://www.opentable.com/widget/reservation/canvas?$url_query"; |
||
86 | |||
87 | $params = array(); |
||
88 | wp_parse_str( $url_query, $params ); |
||
89 | |||
90 | // Note an iframe is similarly constructed in the block edit function. |
||
91 | $content .= sprintf( |
||
92 | '<amp-iframe src="%s" layout="fill" sandbox="allow-scripts allow-forms allow-same-origin allow-popups">%s</amp-iframe>', |
||
93 | esc_url( $src ), |
||
94 | sprintf( |
||
95 | '<a placeholder href="%s">%s</a>', |
||
96 | esc_url( |
||
97 | add_query_arg( |
||
98 | array( |
||
99 | 'rid' => $params['rid'], |
||
100 | ), |
||
101 | 'https://www.opentable.com/restref/client/' |
||
102 | ) |
||
103 | ), |
||
104 | esc_html__( 'Make a reservation', 'jetpack' ) |
||
105 | ) |
||
106 | ); |
||
107 | } else { |
||
108 | // The OpenTable script uses multiple `rid` paramters, |
||
109 | // so we can't use WordPress to output it, as WordPress attempts to validate it and removes them. |
||
110 | // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
||
111 | $content .= '<script src="' . esc_url( $script_url ) . '"></script>'; |
||
112 | } |
||
113 | |||
114 | $content .= '</div>'; |
||
115 | |||
116 | return $content; |
||
117 | } |
||
118 | |||
239 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.