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