supernova-ws /
SuperNova
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Created by Gorlum 17.09.2015 14:11 |
||
| 5 | */ |
||
| 6 | class Confirmation { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * @var db_mysql |
||
| 10 | */ |
||
| 11 | protected $db = null; |
||
| 12 | |||
| 13 | public function __construct($db) { |
||
| 14 | $this->db = $db; |
||
| 15 | } |
||
| 16 | |||
| 17 | // TODO - НЕ ОБЯЗАТЕЛЬНО ОТПРАВЛЯТЬ ЧЕРЕЗ ЕМЕЙЛ! ЕСЛИ ЭТО ФЕЙСБУЧЕК ИЛИ ВКШЕЧКА - МОЖНО ЧЕРЕЗ ЛС ПИСАТЬ!! |
||
| 18 | // TODO - OK 4.6 |
||
| 19 | public function db_confirmation_get_latest_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
||
| 20 | $email_safe = $this->db->db_escape($email_unsafe); |
||
| 21 | |||
| 22 | return $this->db->doSelectFetch( |
||
| 23 | "SELECT * FROM {{confirmations}} WHERE |
||
| 24 | `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}' ORDER BY create_time DESC LIMIT 1;" |
||
| 25 | ); |
||
| 26 | } |
||
| 27 | // TODO - OK 4.6 |
||
| 28 | public function db_confirmation_delete_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
||
| 29 | $email_safe = $this->db->db_escape($email_unsafe); |
||
| 30 | |||
| 31 | return $this->db->doDelete("DELETE FROM {{confirmations}} WHERE `type` = {$confirmation_type_safe} AND `email` = '{$email_safe}'"); |
||
| 32 | } |
||
| 33 | // TODO - OK 4.6 |
||
| 34 | View Code Duplication | public function db_confirmation_get_unique_code_by_type_and_email($confirmation_type_safe, $email_unsafe) { |
|
|
0 ignored issues
–
show
|
|||
| 35 | $email_safe = $this->db->db_escape($email_unsafe); |
||
| 36 | |||
| 37 | do { |
||
| 38 | // Ну, если у нас > 999.999 подтверждений - тут нас ждут проблемы... |
||
| 39 | $confirm_code_safe = $this->db->db_escape($confirm_code_unsafe = $this->make_password_reset_code()); |
||
| 40 | // $query = static::$db->doquery("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' AND `type` = {$confirmation_type_safe} FOR UPDATE", true); |
||
| 41 | // Тип не нужен для проверки - код подтверждения должен быть уникален от слова "совсем" |
||
| 42 | $query = $this->db->doSelectFetch("SELECT `id` FROM {{confirmations}} WHERE `code` = '{$confirm_code_safe}' FOR UPDATE"); |
||
| 43 | } while($query); |
||
|
0 ignored issues
–
show
The expression
$query of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 44 | |||
| 45 | $this->db->doReplace( |
||
| 46 | "REPLACE INTO {{confirmations}} |
||
| 47 | SET `type` = {$confirmation_type_safe}, `code` = '{$confirm_code_safe}', `email` = '{$email_safe}';"); |
||
| 48 | |||
| 49 | return $confirm_code_unsafe; |
||
| 50 | } |
||
| 51 | // TODO - OK 4.6 |
||
| 52 | public function db_confirmation_get_by_type_and_code($confirmation_type_safe, $confirmation_code_unsafe) { |
||
| 53 | $confirmation_code_safe = $this->db->db_escape($confirmation_code_unsafe); |
||
| 54 | |||
| 55 | return $this->db->doSelectFetch( |
||
| 56 | "SELECT * |
||
| 57 | FROM {{confirmations}} |
||
| 58 | WHERE |
||
| 59 | `type` = {$confirmation_type_safe} |
||
| 60 | AND |
||
| 61 | `code` = '{$confirmation_code_safe}' |
||
| 62 | ORDER BY create_time |
||
| 63 | DESC LIMIT 1 |
||
| 64 | FOR UPDATE" |
||
| 65 | ); |
||
| 66 | } |
||
| 67 | |||
| 68 | protected function make_password_reset_code() { |
||
| 69 | return sys_random_string(LOGIN_PASSWORD_RESET_CONFIRMATION_LENGTH, SN_SYS_SEC_CHARS_CONFIRMATION); |
||
| 70 | } |
||
| 71 | |||
| 72 | } |
||
| 73 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.