| Conditions | 6 |
| Paths | 7 |
| Total Lines | 52 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 82 | private function handleForgotPassword($aErr) { |
||
| 83 | if (!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) { |
||
| 84 | $aErr[] = 'emailinvalid'; |
||
| 85 | } else { |
||
| 86 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 87 | $querybuilder |
||
| 88 | ->select('*') |
||
| 89 | ->from('customer') |
||
| 90 | ->where('cust_email = ?') |
||
| 91 | ->setParameter(0, filter_var(trim(\HaaseIT\Toolbox\Tools::getFormfield('email')), FILTER_SANITIZE_EMAIL)) |
||
| 92 | ; |
||
| 93 | $stmt = $querybuilder->execute(); |
||
| 94 | |||
| 95 | if ($stmt->rowCount() != 1) { |
||
| 96 | $aErr[] = 'emailunknown'; |
||
| 97 | } else { |
||
| 98 | $aResult = $stmt->fetch(); |
||
| 99 | $iTimestamp = time(); |
||
| 100 | if ($iTimestamp - strtotime('1 Hour', 0) < $aResult['cust_pwresettimestamp']) { // 1 hour delay between requests |
||
| 101 | $aErr[] = 'pwresetstilllocked'; |
||
| 102 | } else { |
||
| 103 | $sResetCode = md5($aResult['cust_email'].mt_rand().$iTimestamp); |
||
| 104 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 105 | $querybuilder |
||
| 106 | ->update('customer') |
||
| 107 | ->set('cust_pwresetcode', '?') |
||
| 108 | ->set('cust_pwresettimestamp', '?') |
||
| 109 | ->where('cust_id = ?') |
||
| 110 | ->setParameter(0, $sResetCode) |
||
| 111 | ->setParameter(1, $iTimestamp) |
||
| 112 | ->setParameter(2, $aResult['cust_id']) |
||
| 113 | ; |
||
| 114 | $querybuilder->execute(); |
||
| 115 | |||
| 116 | $serverservername = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL); |
||
| 117 | $serverhttps = filter_input(INPUT_SERVER, 'HTTPS'); |
||
| 118 | $sTargetAddress = $aResult['cust_email']; |
||
| 119 | $sSubject = $this->textcats->T('forgotpw_mail_subject'); |
||
| 120 | $sMessage = $this->textcats->T('forgotpw_mail_text1'); |
||
| 121 | $sMessage .= '<br><br>' .'<a href="http'.($serverhttps === 'on' ? 's' : '').'://'; |
||
| 122 | $sMessage .= $serverservername.'/_misc/rp.html?key='.$sResetCode.'&email='.$sTargetAddress.'">'; |
||
| 123 | $sMessage .= 'http'.($serverhttps === 'on' ? 's' : '').'://'; |
||
| 124 | $sMessage .= $serverservername.'/_misc/rp.html?key='.$sResetCode.'&email='.$sTargetAddress.'</a>'; |
||
| 125 | $sMessage .= '<br><br>'.$this->textcats->T('forgotpw_mail_text2'); |
||
| 126 | |||
| 127 | \HaaseIT\HCSF\Helper::mailWrapper($sTargetAddress, $sSubject, $sMessage); |
||
|
|
|||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | return $aErr; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.