Conditions | 9 |
Paths | 64 |
Total Lines | 66 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
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 |
||
94 | private function create_test_object( $slug, $supports, $metaboxes ){ |
||
95 | $return = ''; |
||
96 | |||
97 | // Get a random title |
||
98 | $title = TestContent::title(); |
||
99 | |||
100 | // First, insert our post |
||
101 | $post = array( |
||
102 | 'post_name' => sanitize_title( $title ), |
||
103 | 'post_status' => 'publish', |
||
104 | 'post_type' => $slug, |
||
105 | 'ping_status' => 'closed', |
||
106 | 'comment_status' => 'closed', |
||
107 | ); |
||
108 | |||
109 | // Add title if supported |
||
110 | if ( $supports['title'] === true ){ |
||
111 | $post['post_title'] = $title; |
||
112 | } |
||
113 | |||
114 | // Add main content if supported |
||
115 | if ( $supports['editor'] === true ){ |
||
116 | $post['post_content'] = TestContent::paragraphs(); |
||
117 | } |
||
118 | |||
119 | // Insert then post object |
||
120 | $post_id = wp_insert_post( $post ); |
||
121 | |||
122 | // Then, set a test content flag on the new post for later deletion |
||
123 | add_post_meta( $post_id, 'evans_test_content', '__test__', true ); |
||
124 | |||
125 | // Add thumbnail if supported |
||
126 | if ( $supports['thumbnail'] === true || in_array( $slug, array( 'post', 'page' ) ) ){ |
||
127 | update_post_meta( $post_id, '_thumbnail_id', TestContent::image( $post_id ) ); |
||
128 | } |
||
129 | |||
130 | $taxonomies = get_object_taxonomies( $slug ); |
||
131 | |||
132 | // Assign the post to terms |
||
133 | if ( !empty( $taxonomies ) ){ |
||
134 | $return .= $this->assign_terms( $post_id, $taxonomies ); |
||
135 | } |
||
136 | |||
137 | // Spin up metaboxes |
||
138 | if ( !empty( $metaboxes ) ){ |
||
139 | foreach ( $metaboxes as $cmb ) : |
||
140 | $return .= $this->metaboxes->random_metabox_content( $post_id, $cmb ); |
||
141 | endforeach; |
||
142 | } |
||
143 | |||
144 | // Check if we have errors and return them or created message |
||
145 | if ( is_wp_error( $return ) ){ |
||
146 | error_log( $return->get_error_message() ); |
||
147 | return $return; |
||
148 | } else { |
||
149 | return array( |
||
150 | 'type' => 'created', |
||
151 | 'object' => 'post', |
||
152 | 'pid' => $post_id, |
||
153 | 'post_type' => get_post_type( $post_id ), |
||
154 | 'link_edit' => admin_url( '/post.php?post='.$post_id.'&action=edit' ), |
||
155 | 'link_view' => get_permalink( $post_id ), |
||
156 | ); |
||
157 | } |
||
158 | |||
159 | } |
||
160 | |||
241 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..