Complex classes like Writing_On_GitHub_Import often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Writing_On_GitHub_Import, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Writing_On_GitHub_Import { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Application container. |
||
| 15 | * |
||
| 16 | * @var Writing_On_GitHub |
||
| 17 | */ |
||
| 18 | protected $app; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Initializes a new import manager. |
||
| 22 | * |
||
| 23 | * @param Writing_On_GitHub $app Application container. |
||
| 24 | */ |
||
| 25 | public function __construct( Writing_On_GitHub $app ) { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Imports a payload. |
||
| 31 | * @param Writing_On_GitHub_Payload $payload |
||
| 32 | * |
||
| 33 | * @return string|WP_Error |
||
| 34 | */ |
||
| 35 | public function payload( Writing_On_GitHub_Payload $payload ) { |
||
| 54 | |||
| 55 | /** |
||
| 56 | * import blob by files |
||
| 57 | * @param Writing_On_GitHub_File_Info[] $files |
||
| 58 | * @param boolean $force |
||
| 59 | * |
||
| 60 | * @return true|WP_Error |
||
|
|
|||
| 61 | */ |
||
| 62 | protected function import_files( $files, $force = false ) { |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Imports the latest commit on the master branch. |
||
| 101 | * |
||
| 102 | * @param boolean $force |
||
| 103 | * @return string|WP_Error |
||
| 104 | */ |
||
| 105 | public function master( $force = false ) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Checks whether the provided blob should be imported. |
||
| 127 | * |
||
| 128 | * @param Writing_On_GitHub_File_Info $file |
||
| 129 | * |
||
| 130 | * @return bool |
||
| 131 | */ |
||
| 132 | protected function importable_file( Writing_On_GitHub_File_Info $file ) { |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Checks whether the provided blob should be imported. |
||
| 148 | * |
||
| 149 | * @param Writing_On_GitHub_Blob $blob Blob to validate. |
||
| 150 | * |
||
| 151 | * @return bool |
||
| 152 | */ |
||
| 153 | protected function importable_post( Writing_On_GitHub_Blob $blob ) { |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Delete post |
||
| 175 | * @param Writing_On_GitHub_Blob $blob |
||
| 176 | * @return WP_Error|bool |
||
| 177 | */ |
||
| 178 | protected function delete_post( Writing_On_GitHub_Blob $blob ) { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Imports a post into wordpress |
||
| 193 | * @param Writing_On_GitHub_Blob $blob |
||
| 194 | * @param boolean $force |
||
| 195 | * @return WP_Error|bool |
||
| 196 | */ |
||
| 197 | protected function import_post( Writing_On_GitHub_Blob $blob, $force = false ) { |
||
| 225 | |||
| 226 | /** |
||
| 227 | * import raw file |
||
| 228 | * @param Writing_On_GitHub_Blob $blob |
||
| 229 | * @return bool |
||
| 230 | */ |
||
| 231 | protected function importable_raw_file( Writing_On_GitHub_Blob $blob ) { |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Imports a raw file content into file system. |
||
| 246 | * @param Writing_On_GitHub_Blob $blob |
||
| 247 | * @param bool $is_remove |
||
| 248 | */ |
||
| 249 | protected function import_raw_file( Writing_On_GitHub_Blob $blob, $is_remove ) { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Imports a single blob content into matching post. |
||
| 269 | * |
||
| 270 | * @param Writing_On_GitHub_Blob $blob Blob to transform into a Post. |
||
| 271 | * @param boolean $force |
||
| 272 | * |
||
| 273 | * @return Writing_On_GitHub_Post|false |
||
| 274 | */ |
||
| 275 | protected function blob_to_post( Writing_On_GitHub_Blob $blob, $force = false ) { |
||
| 330 | } |
||
| 331 |
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.