Conditions | 17 |
Paths | 17 |
Total Lines | 89 |
Code Lines | 54 |
Lines | 0 |
Ratio | 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 |
||
90 | public static function get_page() { |
||
91 | $page = null; |
||
92 | |||
93 | /** |
||
94 | * See: https://codex.wordpress.org/Conditional_Tags |
||
95 | */ |
||
96 | |||
97 | switch ( true ) { |
||
98 | case ( is_404() ): |
||
99 | $page = 'error'; |
||
100 | break; |
||
101 | |||
102 | case ( is_search() ): |
||
103 | $page = 'search'; |
||
104 | break; |
||
105 | |||
106 | /** |
||
107 | * Case is_home() return true when on the posts list page, |
||
108 | * This is usually the page that shows the latest 10 posts. |
||
109 | */ |
||
110 | case ( is_home() ): |
||
111 | $page = 'home'; |
||
112 | break; |
||
113 | |||
114 | /** |
||
115 | * Case is_front_page() returns true if the user is on the page or page of posts that is set to the front page |
||
116 | * on Settings->Reading->Front page displays |
||
117 | */ |
||
118 | case ( is_front_page() ): |
||
119 | $page = 'front_page'; |
||
120 | break; |
||
121 | |||
122 | case ( is_post_type_archive() ): |
||
123 | $page = 'post-type-archive'; |
||
124 | break; |
||
125 | |||
126 | case ( is_page_template() ): |
||
127 | $page = 'custom'; |
||
128 | break; |
||
129 | |||
130 | case ( is_single() ): |
||
131 | $page = 'single'; |
||
132 | break; |
||
133 | |||
134 | case ( is_page() ): |
||
135 | $page = 'page'; |
||
136 | break; |
||
137 | |||
138 | case ( is_attachment() ): |
||
139 | $page = 'attachment'; |
||
140 | break; |
||
141 | |||
142 | case ( is_comments_popup() ): |
||
143 | $page = 'comments-popup'; |
||
144 | break; |
||
145 | |||
146 | case ( is_tax() ): |
||
147 | $page = 'taxonomy'; |
||
148 | break; |
||
149 | |||
150 | case ( is_tag() ): |
||
151 | $page = 'tag'; |
||
152 | break; |
||
153 | |||
154 | case ( is_date() ): |
||
155 | $page = 'date'; |
||
156 | break; |
||
157 | |||
158 | case ( is_category() ): |
||
159 | $page = 'category'; |
||
160 | break; |
||
161 | |||
162 | case ( is_author() ): |
||
163 | $page = 'author'; |
||
164 | break; |
||
165 | |||
166 | case ( is_archive() ): |
||
167 | $page = 'archive'; |
||
168 | break; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Filter: override for page selection |
||
173 | */ |
||
174 | $page = self::filter( 'page-' . $page, $page ); |
||
175 | $page = self::filter( 'page', $page ); |
||
176 | |||
177 | return $page; |
||
178 | } |
||
179 | } |
||
180 |