| Conditions | 11 |
| Paths | 12 |
| Total Lines | 79 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 declare(strict_types=1); |
||
| 108 | public static function checkVerModule($helper, $source = 'github', $default = 'master') |
||
| 109 | { |
||
| 110 | $moduleDirName = \basename(\dirname(\dirname(__DIR__))); |
||
| 111 | |||
| 112 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName); |
||
| 113 | |||
| 114 | $update = ''; |
||
| 115 | |||
| 116 | $repository = 'XoopsModules25x/' . $moduleDirName; |
||
| 117 | |||
| 118 | // $repository = 'XoopsModules25x/publisher'; //for testing only |
||
| 119 | |||
| 120 | $ret = ''; |
||
| 121 | |||
| 122 | $infoReleasesUrl = "https://api.github.com/repos/$repository/releases"; |
||
| 123 | |||
| 124 | if ('github' === $source) { |
||
| 125 | if (\function_exists('curl_init') && false !== ($curlHandle = \curl_init())) { |
||
| 126 | \curl_setopt($curlHandle, \CURLOPT_URL, $infoReleasesUrl); |
||
| 127 | |||
| 128 | \curl_setopt($curlHandle, \CURLOPT_RETURNTRANSFER, true); |
||
| 129 | |||
| 130 | \curl_setopt($curlHandle, \CURLOPT_SSL_VERIFYPEER, true); //TODO: how to avoid an error when 'Peer's Certificate issuer is not recognized' |
||
| 131 | |||
| 132 | \curl_setopt($curlHandle, \CURLOPT_HTTPHEADER, ["User-Agent:Publisher\r\n"]); |
||
| 133 | |||
| 134 | $curlReturn = \curl_exec($curlHandle); |
||
| 135 | |||
| 136 | if (false === $curlReturn) { |
||
| 137 | \trigger_error(\curl_error($curlHandle)); |
||
| 138 | } elseif (false !== \mb_strpos($curlReturn, 'Not Found')) { |
||
| 139 | \trigger_error('Repository Not Found: ' . $infoReleasesUrl); |
||
| 140 | } else { |
||
| 141 | $file = \json_decode($curlReturn, false); |
||
| 142 | |||
| 143 | $latestVersionLink = \sprintf("https://github.com/$repository/archive/%s.zip", $file ? \reset($file)->tag_name : $default); |
||
| 144 | |||
| 145 | $latestVersion = $file[0]->tag_name; |
||
| 146 | |||
| 147 | $prerelease = $file[0]->prerelease; |
||
| 148 | |||
| 149 | if ('master' !== $latestVersionLink) { |
||
| 150 | $update = \constant('CO_' . $moduleDirNameUpper . '_' . 'NEW_VERSION') . $latestVersion; |
||
| 151 | } |
||
| 152 | |||
| 153 | //"PHP-standardized" version |
||
| 154 | |||
| 155 | $latestVersion = \mb_strtolower($latestVersion); |
||
| 156 | |||
| 157 | if (false !== \mb_strpos($latestVersion, 'final')) { |
||
| 158 | $latestVersion = \str_replace('_', '', \mb_strtolower($latestVersion)); |
||
| 159 | |||
| 160 | $latestVersion = \str_replace('final', '', \mb_strtolower($latestVersion)); |
||
| 161 | } |
||
| 162 | |||
| 163 | $moduleVersion = $helper->getModule()->getInfo('version') . '_' . $helper->getModule()->getInfo('module_status'); |
||
| 164 | |||
| 165 | //"PHP-standardized" version |
||
| 166 | |||
| 167 | $moduleVersion = \str_replace(' ', '', \mb_strtolower($moduleVersion)); |
||
| 168 | |||
| 169 | // $moduleVersion = '1.0'; //for testing only |
||
| 170 | |||
| 171 | // $moduleDirName = 'publisher'; //for testing only |
||
| 172 | |||
| 173 | if (!$prerelease && \version_compare($moduleVersion, $latestVersion, '<')) { |
||
| 174 | $ret = []; |
||
| 175 | |||
| 176 | $ret[] = $update; |
||
| 177 | |||
| 178 | $ret[] = $latestVersionLink; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | \curl_close($curlHandle); |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $ret; |
||
| 187 | } |
||
| 189 |