| Conditions | 19 |
| Paths | 136 |
| Total Lines | 70 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 153 | public function determineMailsToSend() { |
||
| 154 | $this->mailQueue = []; |
||
| 155 | // check for IDP_EXISTS_BUT_NO_DATABASE |
||
| 156 | if (!in_array(AbstractTest::INFRA_NONEXISTENTREALM, $this->possibleFailureReasons) && $this->additionalFindings[AbstractTest::INFRA_NONEXISTENTREALM]['DATABASE_STATUS']['ID2'] < 0) { |
||
| 157 | $this->mailQueue[] = Logopath::IDP_EXISTS_BUT_NO_DATABASE; |
||
| 158 | } |
||
| 159 | |||
| 160 | // after collecting all the conditions, find the target entities in all |
||
| 161 | // the mails, and check if they resolve to a known mail address. If they |
||
| 162 | // do not, this triggers more mails about missing contact info. |
||
| 163 | |||
| 164 | $abstractRecipients = []; |
||
| 165 | foreach ($this->mailQueue as $mail) { |
||
| 166 | $abstractRecipients = array_unique(array_merge($this->mailStack[$mail]['to'], $this->mailStack[$mail]['cc'], $this->mailStack[$mail]['bcc'], $this->mailStack[$mail]['reply-to'])); |
||
| 167 | } |
||
| 168 | // who are those guys? Here is significant legwork in terms of DB lookup |
||
| 169 | $this->concreteRecipients = []; |
||
| 170 | foreach ($abstractRecipients as $oneRecipient) { |
||
| 171 | switch ($oneRecipient) { |
||
| 172 | case Logopath::EDUROAM_OT: |
||
| 173 | $this->concreteRecipients[Logopath::EDUROAM_OT] = ["[email protected]"]; |
||
| 174 | break; |
||
| 175 | case Logopath::ENDUSER: |
||
| 176 | // will be filled when sending, from $this->userEmail |
||
| 177 | // hence the +1 below |
||
| 178 | break; |
||
| 179 | case Logopath::IDP_PUBLIC: // intentional fall-through, we populate both in one go |
||
| 180 | case Logopath::IDP_PRIVATE: |
||
| 181 | // CAT contacts, if existing |
||
| 182 | if ($this->additionalFindings['INFRA_NONEXISTENT_REALM']['DATABASE_STATUS']['ID1'] > 0) { |
||
| 183 | $profile = \core\ProfileFactory::instantiate($this->additionalFindings['INFRA_NONEXISTENT_REALM']['DATABASE_STATUS']['ID1']); |
||
| 184 | |||
| 185 | foreach ($profile->getAttributes("support:email") as $oneMailAddress) { |
||
| 186 | // CAT contacts are always public |
||
| 187 | $this->concreteRecipients[Logopath::IDP_PUBLIC][] = $oneMailAddress; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | // DB contacts, if existing |
||
| 191 | if ($this->additionalFindings['INFRA_NONEXISTENT_REALM']['DATABASE_STATUS']['ID2'] > 0) { |
||
| 192 | $cat = new \core\CAT(); |
||
| 193 | $info = $cat->getExternalDBEntityDetails($this->additionalFindings['INFRA_NONEXISTENT_REALM']['DATABASE_STATUS']['ID2']); |
||
| 194 | foreach ($info['admins'] as $infoElement) { |
||
| 195 | if (isset($infoElement['email'])) { |
||
| 196 | // until DB Spec 2.0 is out and used, consider all DB contacts as private |
||
| 197 | $this->concreteRecipients[Logopath::IDP_PRIVATE][] = $infoElement['email']; |
||
| 198 | } |
||
| 199 | } |
||
| 200 | } |
||
| 201 | break; |
||
| 202 | case Logopath::NRO_IDP: // same code for both, fall through |
||
| 203 | case Logopath::NRO_SP: |
||
| 204 | $target = ($oneRecipient == Logopath::NRO_IDP ? $this->additionalFindings['INFRA_NRO_IdP'] : $this->additionalFindings['INFRA_NRO_SP']); |
||
| 205 | $fed = new \core\Federation($target); |
||
| 206 | $adminList = $fed->listFederationAdmins(); |
||
|
|
|||
| 207 | // TODO: we only have those who are signed up for CAT currently, and by their ePTID. |
||
| 208 | // in touch with OT to get all, so that we can get a list of emails |
||
| 209 | break; |
||
| 210 | case Logopath::SP: |
||
| 211 | // TODO: needs a DB view on SPs in eduroam DB, in touch with OT |
||
| 212 | break; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | // now see if we lack pertinent recipient info, and add corresponding |
||
| 216 | // mails to the list |
||
| 217 | if (count($abstractRecipients) != count($this->concreteRecipients) + 1) { |
||
| 218 | // there is a discrepancy, do something ... |
||
| 219 | // we need to add a mail to the next higher hierarchy level as escalation |
||
| 220 | // but may also have to remove the lower one because we don't know the guy. |
||
| 221 | } |
||
| 222 | } |
||
| 223 | |||
| 281 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.