| Conditions | 9 |
| Paths | 16 |
| Total Lines | 54 |
| 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 |
||
| 23 | function xoops_module_pre_install_mylinks_base(&$xoopsModule) |
||
| 24 | { |
||
| 25 | global $xoopsDB; |
||
| 26 | $retVal = true; |
||
| 27 | |||
| 28 | $minPHPVersion = $xoopsModule->getInfo('min_php'); |
||
| 29 | $minSQLVersion = $xoopsModule->getInfo('min_sql'); |
||
| 30 | $minXoopsVersion = $xoopsModule->getInfo('min_xoops'); |
||
| 31 | |||
| 32 | /* |
||
| 33 | * Error Messages |
||
| 34 | */ |
||
| 35 | $phpErrMsg = "<span style='color: red; font-weight: bold;'>YOUR PHP VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minPHPVersion} TO USE THIS MODULE</span>"; |
||
| 36 | $mysqlErrMsg = "<span style='color: red; font-weight: bold;'>YOUR MYSQL DATABASE VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minSQLVersion} TO USE THIS MODULE</span>"; |
||
| 37 | $xoopsErrMsg = "<span style='color: red; font-weight: bold;'>YOUR XOOPS VERSION MUST BE UPGRADED TO AT LEAST VERSION {$minXoopsVersion} TO USE THIS MODULE</span>"; |
||
| 38 | |||
| 39 | // Check if PHP version is supported |
||
| 40 | if (version_compare(PHP_VERSION, $minPHPVersion) < 0) { |
||
| 41 | $retVal = false; |
||
| 42 | $xoopsModule->setErrors($phpErrMsg); |
||
| 43 | } else { |
||
| 44 | // Check if MySQL version is supported |
||
| 45 | $minSQLSupported = explode('.', $minSQLVersion); |
||
| 46 | $sql = $xoopsDB->query('SELECT version() AS sqlver'); |
||
| 47 | $result = $xoopsDB->fetchObject($sql); |
||
| 48 | $currSQLVer = $result->sqlver; |
||
| 49 | $sqlVerArray = explode('.', $currSQLVer); |
||
| 50 | $sqlVerArray = array_map('intval', $sqlVerArray); //strip off non-integer revision chars |
||
| 51 | |||
| 52 | if ($sqlVerArray[0] < $minSQLSupported[0]) { |
||
| 53 | $retVal = false; |
||
| 54 | $xoopsModule->setErrors($mysqlErrMsg); |
||
| 55 | } elseif ($sqlVerArray[0] == $minSQLSupported[0]) { |
||
| 56 | if ($sqlVerArray[1] < $minSQLSupported[1]) { |
||
| 57 | $retVal = false; |
||
| 58 | $xoopsModule->setErrors($mysqlErrMsg); |
||
| 59 | } elseif (($sqlVerArray[1] == $minSQLSupported[1]) && ($sqlVerArray[2] < $minSQLSupported[2])) { |
||
| 60 | $retVal = false; |
||
| 61 | $xoopsModule->setErrors($mysqlErrMsg); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($retVal) { |
||
| 66 | // Check if this XOOPS version is supported |
||
| 67 | $curXoopsVersion = substr(XOOPS_VERSION, 6); |
||
| 68 | if (version_compare($curXoopsVersion, $minXoopsVersion, '<')) { |
||
| 69 | $retVal = false; |
||
| 70 | $xoopsModule->setErrors(sprintf($xoopsErrMsg, $minXoopsVersion, $curXoopsVersion)); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return $retVal; |
||
| 76 | } |
||
| 77 | |||
| 100 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.