| Conditions | 11 |
| Paths | 290 |
| Total Lines | 80 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 32 | public function requestInfo($unusedParameter = null) { |
||
| 33 | //We have to make several remote API requests to gather all the necessary info |
||
| 34 | //which can take a while on slow networks. |
||
| 35 | if ( function_exists('set_time_limit') ) { |
||
| 36 | @set_time_limit(60); |
||
|
|
|||
| 37 | } |
||
| 38 | |||
| 39 | $api = $this->api; |
||
| 40 | $api->setLocalDirectory($this->package->getAbsoluteDirectoryPath()); |
||
| 41 | |||
| 42 | $info = new Plugin\PluginInfo(); |
||
| 43 | $info->filename = $this->pluginFile; |
||
| 44 | $info->slug = $this->slug; |
||
| 45 | |||
| 46 | $this->setInfoFromHeader($this->package->getPluginHeader(), $info); |
||
| 47 | $this->setIconsFromLocalAssets($info); |
||
| 48 | $this->setBannersFromLocalAssets($info); |
||
| 49 | |||
| 50 | //Pick a branch or tag. |
||
| 51 | $updateSource = $api->chooseReference($this->branch); |
||
| 52 | if ( $updateSource ) { |
||
| 53 | $ref = $updateSource->name; |
||
| 54 | $info->version = $updateSource->version; |
||
| 55 | $info->last_updated = $updateSource->updated; |
||
| 56 | $info->download_url = $updateSource->downloadUrl; |
||
| 57 | |||
| 58 | if ( !empty($updateSource->changelog) ) { |
||
| 59 | $info->sections['changelog'] = $updateSource->changelog; |
||
| 60 | } |
||
| 61 | if ( isset($updateSource->downloadCount) ) { |
||
| 62 | $info->downloaded = $updateSource->downloadCount; |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | //There's probably a network problem or an authentication error. |
||
| 66 | do_action( |
||
| 67 | 'puc_api_error', |
||
| 68 | new \WP_Error( |
||
| 69 | 'puc-no-update-source', |
||
| 70 | 'Could not retrieve version information from the repository. ' |
||
| 71 | . 'This usually means that the update checker either can\'t connect ' |
||
| 72 | . 'to the repository or it\'s configured incorrectly.' |
||
| 73 | ), |
||
| 74 | null, null, $this->slug |
||
| 75 | ); |
||
| 76 | return null; |
||
| 77 | } |
||
| 78 | |||
| 79 | //Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata |
||
| 80 | //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags. |
||
| 81 | $mainPluginFile = basename($this->pluginFile); |
||
| 82 | $remotePlugin = $api->getRemoteFile($mainPluginFile, $ref); |
||
| 83 | if ( !empty($remotePlugin) ) { |
||
| 84 | $remoteHeader = $this->package->getFileHeader($remotePlugin); |
||
| 85 | $this->setInfoFromHeader($remoteHeader, $info); |
||
| 86 | } |
||
| 87 | |||
| 88 | //Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain |
||
| 89 | //a lot of useful information like the required/tested WP version, changelog, and so on. |
||
| 90 | if ( $this->readmeTxtExistsLocally() ) { |
||
| 91 | $this->setInfoFromRemoteReadme($ref, $info); |
||
| 92 | } |
||
| 93 | |||
| 94 | //The changelog might be in a separate file. |
||
| 95 | if ( empty($info->sections['changelog']) ) { |
||
| 96 | $info->sections['changelog'] = $api->getRemoteChangelog($ref, $this->package->getAbsoluteDirectoryPath()); |
||
| 97 | if ( empty($info->sections['changelog']) ) { |
||
| 98 | $info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker'); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | if ( empty($info->last_updated) ) { |
||
| 103 | //Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date. |
||
| 104 | $latestCommitTime = $api->getLatestCommitTime($ref); |
||
| 105 | if ( $latestCommitTime !== null ) { |
||
| 106 | $info->last_updated = $latestCommitTime; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $info = apply_filters($this->getUniqueName('request_info_result'), $info, null); |
||
| 111 | return $info; |
||
| 112 | } |
||
| 261 |
If you suppress an error, we recommend checking for the error condition explicitly: