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