chore: refactor NodeResolver#2342
Conversation
| } else { | ||
| $resolved = $this->resolve_taxonomy_term(); | ||
| if ( false !== $resolved ) { | ||
| return $resolved; |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| $post_type = $this->wp->query_vars['post_type']; | ||
| } | ||
|
|
||
| return $this->resolve_post_by_slug( $this->wp->query_vars['name'], $post_type ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
|
|
||
| return $this->resolve_post_by_slug( $this->wp->query_vars['name'], $post_type ); | ||
| } elseif ( isset( $this->wp->query_vars['cat'] ) ) { | ||
| return $this->resolve_term_by_id( $this->wp->query_vars['cat'], 'category' ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| } elseif ( isset( $this->wp->query_vars['cat'] ) ) { | ||
| return $this->resolve_term_by_id( $this->wp->query_vars['cat'], 'category' ); | ||
| } elseif ( isset( $this->wp->query_vars['tag'] ) ) { | ||
| return $this->resolve_term_by_slug( $this->wp->query_vars['tag'], 'post_tag' ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
aaa0aa4 to
0b7d5d8
Compare
| } | ||
|
|
||
| // If we're still here, the query wants a post type object. | ||
| return $this->resolve_post_type( $this->wp->query_vars['post_type'] ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| // Search all post types if none is set. | ||
| $post_type = isset( $this->wp->query_vars['post_type'] ) ? $this->wp->query_vars['post_type'] : $this->get_allowed_post_types(); | ||
|
|
||
| return $this->resolve_post_by_slug( $this->wp->query_vars['pagename'], $post_type ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| // } | ||
| // return $post; | ||
| } elseif ( isset( $this->wp->query_vars['author_name'] ) ) { | ||
| return $this->resolve_user_by_slug( $this->wp->query_vars['author_name'] ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| // If the query is asking for a Page nodeType with the uri, try and resolve it. | ||
| if ( isset( $this->wp->query_vars['nodeType'] ) && 'Page' === $this->wp->query_vars['nodeType'] && isset( $this->wp->query_vars['uri'] ) ) { | ||
| $post_type = $this->wp->query_vars['post_type']; | ||
| return $this->resolve_post_by_slug( $this->wp->query_vars['uri'], $post_type ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| } | ||
|
|
||
| $page_on_front = get_option( 'page_on_front', 0 ); | ||
| return $this->resolve_post_by_id( absint( $page_on_front ) ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| if ( ! $term instanceof \WP_Term ) { | ||
| return null; | ||
| } | ||
| return $this->resolve_term_by_id( $term->term_id, 'category' ); |
There was a problem hiding this comment.
Avoid too many return statements within this method.
| * | ||
| * @return string|null The parsed uri. | ||
| */ | ||
| public function parse_request( string $uri, $extra_query_vars = '' ) { |
There was a problem hiding this comment.
Function parse_request has a Cognitive Complexity of 112 (exceeds 5 allowed). Consider refactoring.
271d0c1 to
ad69342
Compare
|
Code Climate has analyzed commit ad69342 and detected 12 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically closed because it has not had recent activity. If you believe this issue is still valid, please open a new issue and mark this as a related issue. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What does this implement/fix? Explain your changes.
Early work on refactoring
NodeResolverto make it easier to work on going forward and address the assortment of reported bugs.In a nutshell:
WP::parse_request()has been moved fromresolve_uri()toparse_request()resolve_uri()now uses variousresolve_{type}()methods to keep the logic dry.Does this close any currently open issues?
…
Any other comments?
@todo) that I need to better understand before marking this ready for review.Where has this been tested?
Operating System: Ubuntu 20.04 (wsl2 + devilbox + php 8.0.15)
WordPress Version: 5.9.3