| Conditions | 11 |
| Paths | 12 |
| Total Lines | 49 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 100 | public static function checkVerModule($helper, $source = 'github', $default = 'master') |
||
| 101 | { |
||
| 102 | $moduleDirName = basename(dirname(dirname(__DIR__))); |
||
| 103 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
| 104 | $update = ''; |
||
| 105 | $repository = 'XoopsModules25x/' . $moduleDirName; |
||
| 106 | // $repository = 'XoopsModules25x/publisher'; //for testing only |
||
| 107 | $ret = ''; |
||
| 108 | $infoReleasesUrl = "https://api.github.com/repos/$repository/releases"; |
||
| 109 | if ('github' === $source) { |
||
| 110 | if (function_exists('curl_init') && false !== ($curlHandle = curl_init())) { |
||
| 111 | curl_setopt($curlHandle, CURLOPT_URL, $infoReleasesUrl); |
||
| 112 | curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); |
||
| 113 | curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); |
||
| 114 | curl_setopt($curlHandle, CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]); |
||
| 115 | $curlReturn = curl_exec($curlHandle); |
||
| 116 | if (false === $curlReturn) { |
||
| 117 | trigger_error(curl_error($curlHandle)); |
||
| 118 | } elseif (false !== strpos($curlReturn, 'Not Found')) { |
||
| 119 | trigger_error('Repository Not Found: ' . $infoReleasesUrl); |
||
| 120 | } else { |
||
| 121 | $file = json_decode($curlReturn, false); |
||
| 122 | $latestVersionLink = sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->tag_name : $default); |
||
| 123 | $latestVersion = $file[0]->tag_name; |
||
| 124 | $prerelease = $file[0]->prerelease; |
||
| 125 | if ('master' !== $latestVersionLink) { |
||
| 126 | $update = constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion; |
||
| 127 | } |
||
| 128 | //"PHP-standardized" version |
||
| 129 | $latestVersion = mb_strtolower($latestVersion); |
||
| 130 | if (false !== mb_strpos($latestVersion, 'final')) { |
||
| 131 | $latestVersion = str_replace('_', '', mb_strtolower($latestVersion)); |
||
| 132 | $latestVersion = str_replace('final', '', mb_strtolower($latestVersion)); |
||
| 133 | } |
||
| 134 | $moduleVersion = ($helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status')); |
||
| 135 | //"PHP-standardized" version |
||
| 136 | $moduleVersion = str_replace(' ', '', mb_strtolower($moduleVersion)); |
||
| 137 | // $moduleVersion = '1.0'; //for testing only |
||
| 138 | // $moduleDirName = 'publisher'; //for testing only |
||
| 139 | if (!$prerelease && version_compare($moduleVersion, $latestVersion, '<')) { |
||
| 140 | $ret = []; |
||
| 141 | $ret[] = $update; |
||
| 142 | $ret[] = $latestVersionLink; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | curl_close($curlHandle); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | return $ret; |
||
| 149 | } |
||
| 151 |