| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 67 |
| 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 |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @throws ServiceException |
||
| 179 | */ |
||
| 180 | private function accessDenied() |
||
| 181 | { |
||
| 182 | $this->addTracking(); |
||
| 183 | |||
| 184 | throw new ServiceException( |
||
| 185 | __u('Acceso no permitido'), |
||
| 186 | ServiceException::ERROR, |
||
| 187 | null, |
||
| 188 | -32601 |
||
| 189 | ); |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Sets up user's data in context and performs some user checks |
||
| 194 | * |
||
| 195 | * @throws \SP\Core\Exceptions\SPException |
||
| 196 | */ |
||
| 197 | private function setupUser() |
||
| 198 | { |
||
| 199 | $userLoginResponse = UserService::mapUserLoginResponse($this->dic->get(UserService::class)->getById($this->authTokenData->getUserId())); |
||
| 200 | $userLoginResponse->getIsDisabled() && $this->accessDenied(); |
||
| 201 | |||
| 202 | $this->context->setUserData($userLoginResponse); |
||
| 203 | $this->context->setUserProfile($this->dic->get(UserProfileService::class)->getById($userLoginResponse->getUserProfileId())->getProfile()); |
||
| 204 | } |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Devolver la clave maestra |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | * @throws ServiceException |
||
| 211 | */ |
||
| 212 | private function getMasterPassFromVault() |
||
| 213 | { |
||
| 214 | try { |
||
| 215 | $tokenPass = $this->getParam('tokenPass', true); |
||
| 216 | |||
| 217 | Hash::checkHashKey($tokenPass, $this->authTokenData->getHash()) || $this->accessDenied(); |
||
| 218 | |||
| 219 | /** @var Vault $vault */ |
||
| 220 | $vault = unserialize($this->authTokenData->getVault()); |
||
| 221 | |||
| 222 | if ($vault && ($pass = $vault->getData($tokenPass . $this->getParam('authToken')))) { |
||
| 223 | return $pass; |
||
| 224 | } else { |
||
| 225 | throw new ServiceException( |
||
| 226 | __u('Error interno'), |
||
| 227 | ServiceException::ERROR, |
||
| 228 | __u('Datos inválidos'), |
||
| 229 | -32603 |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | } catch (CryptoException $e) { |
||
| 233 | throw new ServiceException( |
||
| 234 | __u('Error interno'), |
||
| 235 | ServiceException::ERROR, |
||
| 236 | $e->getMessage(), |
||
| 237 | -32603 |
||
| 238 | ); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $param |
||
| 244 | * @param bool $required |
||
| 245 | * @param null $default |
||
| 246 | * |
||
| 247 | * @return int |
||
| 248 | * @throws ServiceException |
||
| 249 | */ |
||
| 250 | public function getParamInt($param, $required = false, $default = null) |
||
| 251 | { |
||
| 252 | return Filter::getInt($this->getParam($param, $required, $default)); |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param string $param |
||
| 257 | * @param bool $required |
||
| 258 | * @param null $default |
||
| 259 | * |
||
| 260 | * @return string |
||
| 261 | * @throws ServiceException |
||
| 262 | */ |
||
| 263 | public function getParamString($param, $required = false, $default = null) |
||
| 264 | { |
||
| 265 | return Filter::getString($this->getParam($param, $required, $default)); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string $param |
||
| 270 | * @param bool $required |
||
| 271 | * @param null $default |
||
| 272 | * |
||
| 355 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.