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