| Conditions | 7 |
| Paths | 9 |
| Total Lines | 60 |
| Code Lines | 48 |
| 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 |
||
| 94 | public function __construct($invitationId) { |
||
| 95 | parent::__construct(); |
||
| 96 | $this->invitationTokenString = $invitationId; |
||
| 97 | $databaseHandle = DBConnection::handle("INST"); |
||
| 98 | /* |
||
| 99 | * Finds invitation by its token attribute and loads all certificates generated using the token. |
||
| 100 | * Certificate details will always be empty, since code still needs to be adapted to return multiple certificates information. |
||
| 101 | */ |
||
| 102 | $invColumnNames = "`id`, `profile_id`, `silverbullet_user_id`, `token`, `quantity`, `expiry`"; |
||
| 103 | $invitationsResult = $databaseHandle->exec("SELECT $invColumnNames FROM `silverbullet_invitation` WHERE `token`=? ORDER BY `expiry` DESC", "s", $this->invitationTokenString); |
||
| 104 | if ($invitationsResult->num_rows == 0) { |
||
| 105 | $this->loggerInstance->debug(2, "Token $this->invitationTokenString not found in database or database query error!\n"); |
||
| 106 | $this->invitationTokenStatus = SilverbulletInvitation::SB_TOKENSTATUS_INVALID; |
||
| 107 | $this->associatedCertificates = []; |
||
| 108 | $this->identifier = 0; |
||
| 109 | $this->profile = 0; |
||
| 110 | $this->userId = 0; |
||
| 111 | $this->expiry = "2000-01-01 00:00:00"; |
||
|
|
|||
| 112 | $this->activationsTotal = 0; |
||
| 113 | $this->activationsRemaining = 0; |
||
| 114 | } else { |
||
| 115 | // if not returned, we found the token in the DB |
||
| 116 | // -> instantiate the class |
||
| 117 | // SELECT -> resource, no boolean |
||
| 118 | $invitationRow = mysqli_fetch_object(/** @scrutinizer ignore-type */ $invitationsResult); |
||
| 119 | $this->identifier = $invitationRow->id; |
||
| 120 | $this->profile = $invitationRow->profile_id; |
||
| 121 | $this->userId = $invitationRow->silverbullet_user_id; |
||
| 122 | $this->expiry = $invitationRow->expiry; |
||
| 123 | $this->activationsTotal = $invitationRow->quantity; |
||
| 124 | $certColumnNames = "`id`, `profile_id`, `silverbullet_user_id`, `silverbullet_invitation_id`, `serial_number`, `cn`, `issued`, `expiry`, `device`, `revocation_status`, `revocation_time`, `OCSP`, `OCSP_timestamp`"; |
||
| 125 | $certificatesResult = $databaseHandle->exec("SELECT $certColumnNames FROM `silverbullet_certificate` WHERE `silverbullet_invitation_id` = ? ORDER BY `revocation_status`, `expiry` DESC", "i", $this->identifier); |
||
| 126 | $certificatesNumber = ($certificatesResult ? $certificatesResult->num_rows : 0); |
||
| 127 | $this->loggerInstance->debug(5, "At token validation level, " . $certificatesNumber . " certificates exist.\n"); |
||
| 128 | $this->associatedCertificates = \core\ProfileSilverbullet::enumerateCertDetails(/** @scrutinizer ignore-type */ $certificatesResult); |
||
| 129 | $this->activationsRemaining = $this->activationsTotal - $certificatesNumber; |
||
| 130 | switch ($certificatesNumber) { |
||
| 131 | case 0: |
||
| 132 | // find out if it has expired |
||
| 133 | $now = new \DateTime(); |
||
| 134 | $expiryObject = new \DateTime($this->invitationTokenExpiry); |
||
| 135 | $delta = $now->diff($expiryObject); |
||
| 136 | if ($delta->invert == 1) { |
||
| 137 | $this->invitationTokenStatus = SilverbulletInvitation::SB_TOKENSTATUS_EXPIRED; |
||
| 138 | $this->activationsRemaining = 0; |
||
| 139 | break; |
||
| 140 | } |
||
| 141 | $this->invitationTokenStatus = SilverbulletInvitation::SB_TOKENSTATUS_VALID; |
||
| 142 | break; |
||
| 143 | case $invitationRow->quantity: |
||
| 144 | $this->invitationTokenStatus = SilverbulletInvitation::SB_TOKENSTATUS_REDEEMED; |
||
| 145 | break; |
||
| 146 | default: |
||
| 147 | assert($certificatesNumber > 0); // no negatives allowed |
||
| 148 | assert($certificatesNumber < $invitationRow->quantity || $invitationRow->quantity == 0); // not more than max quantity allowed (unless quantity is zero) |
||
| 149 | $this->invitationTokenStatus = SilverbulletInvitation::SB_TOKENSTATUS_PARTIALLY_REDEEMED; |
||
| 150 | } |
||
| 151 | } |
||
| 152 | $this->loggerInstance->debug(5, "Done creating invitation token state from DB.\n"); |
||
| 153 | } |
||
| 154 | |||
| 244 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.