Conditions | 2 |
Paths | 2 |
Total Lines | 85 |
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 // phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r |
||
74 | public function render_ui() { |
||
75 | ?> |
||
76 | <h1>XML-RPC errors</h1> |
||
77 | <p> |
||
78 | This page helps you to trigger XML-RPC requests with invalid signatures. |
||
79 | </p> |
||
80 | <?php if ( $this->dev_debug_on ) : ?> |
||
81 | <div class="notice notice-success"> |
||
82 | <p>JETPACK_DEV_DEBUG constant is ON. This means every xml-rpc error will be reported. You're good to test.</p> |
||
83 | </div> |
||
84 | <?php else : ?> |
||
85 | <div class="notice notice-warning"> |
||
86 | <p>JETPACK_DEV_DEBUG constant is OFF. This means xml-rpc error will only be reported once evey hour. Set it to true so you can test it.</p> |
||
87 | </div> |
||
88 | <?php endif; ?> |
||
89 | |||
90 | <p> |
||
91 | Now head to <a href="https://jetpack.com/debug/?url=<?php echo esc_url_raw( get_home_url() ); ?>">Jetpack Debugger</a> and trigger some requests! |
||
92 | </p> |
||
93 | <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
||
94 | <input type="hidden" name="action" value="create_error"> |
||
95 | <?php wp_nonce_field( 'create-error' ); ?> |
||
96 | <h3> |
||
97 | Create fake errors |
||
98 | </h3> |
||
99 | <p> |
||
100 | <input type="radio" name="token_type" value="blog" checked /> With the blog token |
||
101 | <input type="radio" name="token_type" value="user" /> With a user token |
||
102 | | |
||
103 | <input type="radio" name="verified" value="yes" checked /> Verified |
||
104 | <input type="radio" name="verified" value="no" /> Not verified |
||
105 | </p> |
||
106 | <p> |
||
107 | <input type="submit" value="Create error" class="button button-primary"> |
||
108 | </p> |
||
109 | </form> |
||
110 | |||
111 | <p> |
||
112 | <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
||
113 | <input type="hidden" name="action" value="clear_all_errors"> |
||
114 | <?php wp_nonce_field( 'clear-all-errors' ); ?> |
||
115 | <input type="submit" value="Clear all errors" class="button button-primary"> |
||
116 | </form> |
||
117 | </p> |
||
118 | |||
119 | <div id="current_xmlrpc_errors"> |
||
120 | |||
121 | |||
122 | <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
||
123 | <input type="hidden" name="action" value="clear_all_xmlrpc_errors"> |
||
124 | <?php wp_nonce_field( 'clear-xmlrpc-errors' ); ?> |
||
125 | <h2> |
||
126 | Current Unverified Errors |
||
127 | <input type="submit" value="Clear all unverified errors" class="button button-primary"> |
||
128 | </h2> |
||
129 | </form> |
||
130 | <p> |
||
131 | Unverified errors are errors that were detected but that we don't know if they are legit and came from WP.com |
||
132 | </p> |
||
133 | <p> |
||
134 | After an error is detected, we send a request to WP.COM and ask it to reach back to us with a nonce to confirm the error is legit. They do this by sending a request to the verify error API endpoint. You can simulate this request clicking on the "Verify error" buttons below. |
||
135 | </p> |
||
136 | <div id="stored-xmlrpc-error"> |
||
137 | <?php $this->print_current_errors(); ?> |
||
138 | </div> |
||
139 | <div id="verified-xmlrpc-error"> |
||
140 | <form action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" method="post"> |
||
141 | <input type="hidden" name="action" value="clear_all_verified_xmlrpc_errors"> |
||
142 | <?php wp_nonce_field( 'clear-verified-xmlrpc-errors' ); ?> |
||
143 | <h2> |
||
144 | Current Verified Errors |
||
145 | <input type="submit" value="Clear all verified errors" class="button button-primary"> |
||
146 | </h2> |
||
147 | </form> |
||
148 | <p> |
||
149 | Verified errors are errors we know are legit and now we will display them to the user or do some self healing, depending on the error. |
||
150 | </p> |
||
151 | <div id="verified_errors_list"> |
||
152 | <?php $this->print_verified_errors(); ?> |
||
153 | </div> |
||
154 | </div> |
||
155 | </div> |
||
156 | |||
157 | <?php |
||
158 | } |
||
159 | |||
298 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: