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 18.09.2015 11:36 |
||
| 5 | */ |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Class PlayerToAccountTranslate |
||
| 9 | */ |
||
| 10 | class PlayerToAccountTranslate { |
||
| 11 | /** |
||
| 12 | * БД из которой читать данные |
||
| 13 | * |
||
| 14 | * @var db_mysql $db |
||
| 15 | */ |
||
| 16 | protected static $db = null; |
||
| 17 | protected static $is_init = false; |
||
| 18 | |||
| 19 | protected static function init() { |
||
| 20 | if(!empty(static::$db)) { |
||
| 21 | return; |
||
| 22 | } |
||
| 23 | static::$db = classSupernova::$db; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Регистрирует игрока на указанный аккаунт указанного провайдера |
||
| 28 | * |
||
| 29 | * @param $provider_id_safe |
||
| 30 | * @param $provider_account_id_safe |
||
| 31 | * @param $user_id_safe |
||
| 32 | * |
||
| 33 | * @return array|resource |
||
| 34 | */ |
||
| 35 | // OK v4.7 |
||
| 36 | public static function db_translate_register_user($provider_id_unsafe, $provider_account_id_unsafe, $user_id_unsafe) { |
||
| 37 | static::init(); |
||
| 38 | |||
| 39 | $provider_id_safe = static::$db->db_escape($provider_id_unsafe); |
||
| 40 | $provider_account_id_safe = static::$db->db_escape($provider_account_id_unsafe); |
||
| 41 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||
| 42 | |||
| 43 | return static::$db->doInsert( |
||
| 44 | "INSERT INTO `{{account_translate}}` (`provider_id`, `provider_account_id`, `user_id`) VALUES |
||
| 45 | ({$provider_id_safe}, {$provider_account_id_safe}, {$user_id_safe});" |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Возвращает из `account_translate` список пользователей, которые прилинкованы к списку аккаунтов на указанном провайдере |
||
| 51 | * |
||
| 52 | * @param int $provider_id_unsafe Идентификатор провайдера авторизации |
||
| 53 | * @param int|int[] $account_list |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | public static function db_translate_get_users_from_account_list($provider_id_unsafe, $account_list) { |
||
| 58 | static::init(); |
||
| 59 | |||
| 60 | $account_translation = array(); |
||
| 61 | |||
| 62 | $provider_id_safe = intval($provider_id_unsafe); |
||
| 63 | !is_array($account_list) ? $account_list = array($account_list) : false; |
||
| 64 | |||
| 65 | foreach($account_list as $provider_account_id_unsafe) { |
||
| 66 | $provider_account_id_safe = intval($provider_account_id_unsafe); |
||
| 67 | |||
| 68 | // TODO - Здесь могут отсутствовать аккаунты - проверять провайдером |
||
| 69 | $query = static::$db->doSelect( |
||
| 70 | "SELECT `user_id` |
||
| 71 | FROM {{account_translate}} |
||
| 72 | WHERE `provider_id` = {$provider_id_safe} AND `provider_account_id` = {$provider_account_id_safe} |
||
| 73 | FOR UPDATE" |
||
| 74 | ); |
||
| 75 | while($row = static::$db->db_fetch($query)) { |
||
|
0 ignored issues
–
show
|
|||
| 76 | $account_translation[$row['user_id']][$provider_id_unsafe][$provider_account_id_unsafe] = true; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | return $account_translation; |
||
| 81 | } |
||
| 82 | |||
| 83 | public static function db_translate_get_account_by_user_id($user_id_unsafe, $provider_id_unsafe = 0) { |
||
| 84 | static::init(); |
||
| 85 | |||
| 86 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||
| 87 | $provider_id_safe = static::$db->db_escape($provider_id_unsafe); |
||
| 88 | |||
| 89 | $account_translation = array(); |
||
| 90 | |||
| 91 | $query = static::$db->doSelect( |
||
| 92 | "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " . |
||
| 93 | ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') . |
||
| 94 | "ORDER BY `timestamp` FOR UPDATE"); |
||
| 95 | while($row = static::$db->db_fetch($query)) { |
||
|
0 ignored issues
–
show
It seems like
$query defined by static::$db->doSelect("S...timestamp` FOR UPDATE') on line 91 can also be of type boolean; however, db_mysql::db_fetch() does only seem to accept object<mysqli_result>, maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. Loading history...
|
|||
| 96 | $account_translation[$row['user_id']][$row['provider_id']][$row['provider_account_id']] = $row; |
||
| 97 | } |
||
| 98 | |||
| 99 | return $account_translation; |
||
| 100 | } |
||
| 101 | |||
| 102 | public static function db_translate_unregister_user($user_id_unsafe) { |
||
| 103 | static::init(); |
||
| 104 | |||
| 105 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||
| 106 | return static::$db->doDelete("DELETE FROM `{{account_translate}}` WHERE `user_id` = {$user_id_safe});"); |
||
| 107 | } |
||
| 108 | |||
| 109 | } |
||
| 110 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.