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