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