| Conditions | 11 |
| Paths | 12 |
| Total Lines | 59 |
| 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 |
||
| 51 | public function checkUserCredentials($user, $password) |
||
| 52 | { |
||
| 53 | // devolver error si no está habilitado |
||
| 54 | if (false === $this->enabled) { |
||
| 55 | return self::STATUS_NOT_AVAILABLE; |
||
| 56 | } |
||
| 57 | |||
| 58 | // obtener URL de entrada |
||
| 59 | $str = $this->getUrl($this->url, $this->forceSecurity); |
||
| 60 | if (!$str) { |
||
| 61 | return self::STATUS_NOT_AVAILABLE; |
||
| 62 | } |
||
| 63 | |||
| 64 | $dom = new \DOMDocument(); |
||
| 65 | libxml_use_internal_errors(true); |
||
| 66 | $dom->loadHTML($str); |
||
| 67 | $xpath = new \DOMXPath($dom); |
||
| 68 | $form = $xpath->query('//form')->item(0); |
||
| 69 | $hidden = $xpath->query('//input[@name="N_V_"]')->item(0); |
||
| 70 | |||
| 71 | if (!$form || !$hidden) { |
||
| 72 | return self::STATUS_NOT_AVAILABLE; |
||
| 73 | } |
||
| 74 | |||
| 75 | // enviar datos del formulario |
||
| 76 | $postUrl = $form->getAttribute('action'); |
||
| 77 | $hiddenValue = $hidden->getAttribute('value'); |
||
| 78 | |||
| 79 | $fields = array( |
||
| 80 | 'USUARIO' => urlencode($user), |
||
| 81 | 'CLAVE' => urlencode($password), |
||
| 82 | 'N_V_' => urlencode($hiddenValue) |
||
| 83 | ); |
||
| 84 | |||
| 85 | $str = $this->postToUrl($fields, $postUrl, $this->url, $this->forceSecurity); |
||
| 86 | |||
| 87 | if (!$str) { |
||
| 88 | return self::STATUS_NOT_AVAILABLE; |
||
| 89 | } |
||
| 90 | |||
| 91 | $dom = new \DOMDocument(); |
||
| 92 | libxml_use_internal_errors(true); |
||
| 93 | $dom->loadHTML($str); |
||
| 94 | $xpath = new \DOMXPath($dom); |
||
| 95 | $nav = $xpath->query('//nav'); |
||
| 96 | $error = $xpath->query('//p[@class="text-danger"]'); |
||
| 97 | $message = $error->length > 0 ? $error->item(0)->firstChild->nodeValue : ''; |
||
| 98 | |||
| 99 | if ($nav->length === 1 && $error->length === 0) { |
||
| 100 | $result = self::STATUS_USER_AUTHENTICATED; |
||
| 101 | } elseif (false !== strpos($message, 'Usuario bloqueado')) { |
||
| 102 | $result = self::STATUS_USER_BLOCKED; |
||
| 103 | } elseif (false !== strpos($message, 'Usuario incorrecto')) { |
||
| 104 | $result = self::STATUS_WRONG_USER_OR_PASSWORD; |
||
| 105 | } else { |
||
| 106 | $result = self::STATUS_NOT_AVAILABLE; |
||
| 107 | } |
||
| 108 | return $result; |
||
| 109 | } |
||
| 110 | |||
| 166 |