| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| 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 |
||
| 25 | public function register_routes() { |
||
| 26 | /** |
||
| 27 | * Filters the maxwidth oEmbed parameter. |
||
| 28 | * |
||
| 29 | * @since 4.4.0 |
||
| 30 | * |
||
| 31 | * @param int $maxwidth Maximum allowed width. Default 600. |
||
| 32 | */ |
||
| 33 | $maxwidth = apply_filters( 'oembed_default_width', 600 ); |
||
| 34 | |||
| 35 | register_rest_route( 'oembed/1.0', '/embed', array( |
||
| 36 | array( |
||
| 37 | 'methods' => WP_REST_Server::READABLE, |
||
| 38 | 'callback' => array( $this, 'get_item' ), |
||
| 39 | 'args' => array( |
||
| 40 | 'url' => array( |
||
| 41 | 'required' => true, |
||
| 42 | 'sanitize_callback' => 'esc_url_raw', |
||
| 43 | ), |
||
| 44 | 'format' => array( |
||
| 45 | 'default' => 'json', |
||
| 46 | 'sanitize_callback' => 'wp_oembed_ensure_format', |
||
| 47 | ), |
||
| 48 | 'maxwidth' => array( |
||
| 49 | 'default' => $maxwidth, |
||
| 50 | 'sanitize_callback' => 'absint', |
||
| 51 | ), |
||
| 52 | ), |
||
| 53 | ), |
||
| 54 | ) ); |
||
| 55 | |||
| 56 | register_rest_route( 'oembed/1.0', '/proxy', array( |
||
| 57 | array( |
||
| 58 | 'methods' => WP_REST_Server::READABLE, |
||
| 59 | 'callback' => array( $this, 'get_proxy_item' ), |
||
| 60 | 'permission_callback' => array( $this, 'get_proxy_item_permissions_check' ), |
||
| 61 | 'args' => array( |
||
| 62 | 'url' => array( |
||
| 63 | 'description' => __( 'The URL of the resource for which to fetch oEmbed data.' ), |
||
| 64 | 'type' => 'string', |
||
| 65 | 'required' => true, |
||
| 66 | 'sanitize_callback' => 'esc_url_raw', |
||
| 67 | ), |
||
| 68 | 'format' => array( |
||
| 69 | 'description' => __( 'The oEmbed format to use.' ), |
||
| 70 | 'type' => 'string', |
||
| 71 | 'default' => 'json', |
||
| 72 | 'enum' => array( |
||
| 73 | 'json', |
||
| 74 | 'xml', |
||
| 75 | ), |
||
| 76 | ), |
||
| 77 | 'maxwidth' => array( |
||
| 78 | 'description' => __( 'The maximum width of the embed frame in pixels.' ), |
||
| 79 | 'type' => 'integer', |
||
| 80 | 'default' => $maxwidth, |
||
| 81 | 'sanitize_callback' => 'absint', |
||
| 82 | ), |
||
| 83 | 'maxheight' => array( |
||
| 84 | 'description' => __( 'The maximum height of the embed frame in pixels.' ), |
||
| 85 | 'type' => 'integer', |
||
| 86 | 'sanitize_callback' => 'absint', |
||
| 87 | ), |
||
| 88 | 'discover' => array( |
||
| 89 | 'description' => __( 'Whether to perform an oEmbed discovery request for non-whitelisted providers.' ), |
||
| 90 | 'type' => 'boolean', |
||
| 91 | 'default' => true, |
||
| 92 | ), |
||
| 93 | ), |
||
| 94 | ), |
||
| 95 | ) ); |
||
| 96 | } |
||
| 97 | |||
| 196 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.