| Conditions | 12 |
| Paths | 17 |
| Total Lines | 48 |
| Code Lines | 38 |
| 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 |
||
| 98 | private function processUserRequestAction(array $data): PBXApiResult |
||
| 99 | { |
||
| 100 | $mikoPBXConfig = new MikoPBXConfig(); |
||
| 101 | $res = new PBXApiResult(); |
||
| 102 | if (strlen($data['licKey']) === 28 |
||
| 103 | && Text::startsWith($data['licKey'], 'MIKO-') |
||
| 104 | ) { |
||
| 105 | $oldLicKey = $mikoPBXConfig->getGeneralSettings('PBXLicense'); |
||
| 106 | if ($oldLicKey !== $data['licKey']) { |
||
| 107 | $licenseInfo = $this->license->getLicenseInfo($data['licKey']); |
||
| 108 | if ($licenseInfo instanceof SimpleXMLElement) { |
||
|
|
|||
| 109 | $mikoPBXConfig->setGeneralSettings('PBXLicense', $data['licKey']); |
||
| 110 | $this->license->changeLicenseKey($data['licKey']); |
||
| 111 | $this->license->addTrial('11'); // MikoPBX forever license |
||
| 112 | $res->success = true; |
||
| 113 | } elseif ( ! empty($licenseInfo) && strpos($licenseInfo, '2026') !== false) { |
||
| 114 | $res->success = false; |
||
| 115 | $res->messages[] = $this->translation->_('lic_FailedCheckLicense2026'); |
||
| 116 | } elseif ( ! empty($licenseInfo)) { |
||
| 117 | $res->messages[] = $licenseInfo; |
||
| 118 | $res->success = false; |
||
| 119 | } else { |
||
| 120 | $res->messages[] = $this->translation->_('lic_FailedCheckLicense'); |
||
| 121 | $res->success = false; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | if ( ! empty($data['coupon'])) { |
||
| 125 | $result = $this->license->activateCoupon($data['coupon']); |
||
| 126 | if ($result === true) { |
||
| 127 | $res->messages[] = $this->translation->_('lic_SuccessfulCouponActivated'); |
||
| 128 | $res->success = true; |
||
| 129 | } else { |
||
| 130 | $res->messages[] = $this->license->translateLicenseErrorMessage($result); |
||
| 131 | $res->success = false; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } else { // Only add trial for license key |
||
| 135 | $newLicenseKey = $this->license->getTrialLicense($data); |
||
| 136 | if (strlen($newLicenseKey) === 28 && Text::startsWith($newLicenseKey, 'MIKO-')) { |
||
| 137 | $mikoPBXConfig->setGeneralSettings('PBXLicense', $data['licKey']); |
||
| 138 | $this->license->changeLicenseKey($data['licKey']); |
||
| 139 | } else { |
||
| 140 | // No internet connection, or wrong data sent to license server, or something else |
||
| 141 | $res->messages[] = $this->license->translateLicenseErrorMessage($newLicenseKey); |
||
| 142 | $res->success = false; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | return $res; |
||
| 146 | } |
||
| 227 | } |