From fe58e4f4220d6685b91bf516374e33936e1075e3 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 14 Jan 2018 17:47:26 +0100 Subject: database: updated checks for selectOne --- includes/model/User_model.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'includes/model/User_model.php') diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 5a31e7b8..a439b199 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -347,12 +347,12 @@ function User_validate_jabber($jabber) */ function User_validate_planned_arrival_date($planned_arrival_date) { - if ($planned_arrival_date == null) { + if (is_null($planned_arrival_date)) { // null is not okay return new ValidationResult(false, time()); } $event_config = EventConfig(); - if ($event_config == null) { + if (empty($event_config)) { // Nothing to validate against return new ValidationResult(true, $planned_arrival_date); } @@ -376,7 +376,7 @@ function User_validate_planned_arrival_date($planned_arrival_date) */ function User_validate_planned_departure_date($planned_arrival_date, $planned_departure_date) { - if ($planned_departure_date == null) { + if (is_null($planned_departure_date)) { // null is okay return new ValidationResult(true, null); } @@ -385,7 +385,7 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de return new ValidationResult(false, $planned_arrival_date); } $event_config = EventConfig(); - if ($event_config == null) { + if (empty($event_config )) { // Nothing to validate against return new ValidationResult(true, $planned_departure_date); } @@ -404,7 +404,7 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de * Returns user by id. * * @param int $user_id UID - * @return array|null + * @return array */ function User($user_id) { @@ -415,7 +415,7 @@ function User($user_id) * Returns User by api_key. * * @param string $api_key User api key - * @return array|null Matching user, null if not found + * @return array Matching user, empty if not found */ function User_by_api_key($api_key) { @@ -426,7 +426,7 @@ function User_by_api_key($api_key) * Returns User by email. * * @param string $email - * @return array|null Matching user, null on error + * @return array Matching user, empty on error */ function User_by_email($email) { @@ -437,7 +437,7 @@ function User_by_email($email) * Returns User by password token. * * @param string $token - * @return array|null Matching user, null when not found + * @return array Matching user, empty when not found */ function User_by_password_recovery_token($token) { -- cgit v1.2.3-54-g00ecf From 5227fe6a94bd8b510aa49b40bfb36fad73ae4afb Mon Sep 17 00:00:00 2001 From: Bot Date: Sun, 14 Jan 2018 18:09:34 +0100 Subject: Formatting --- includes/controller/user_worklog_controller.php | 42 +++++++++----- includes/model/UserWorkLog_model.php | 74 +++++++++++++++---------- includes/model/User_model.php | 16 +++--- includes/view/UserWorkLog_view.php | 30 ++++++---- includes/view/User_view.php | 58 +++++++++++++------ public/index.php | 2 +- 6 files changed, 143 insertions(+), 79 deletions(-) (limited to 'includes/model/User_model.php') diff --git a/includes/controller/user_worklog_controller.php b/includes/controller/user_worklog_controller.php index 1c3281ac..a7218071 100644 --- a/includes/controller/user_worklog_controller.php +++ b/includes/controller/user_worklog_controller.php @@ -2,6 +2,8 @@ /** * Delete a work log entry. + * + * @return array */ function user_worklog_delete_controller() { @@ -29,6 +31,8 @@ function user_worklog_delete_controller() /** * Edit work log for user. + * + * @return array */ function user_worklog_edit_controller() { @@ -59,9 +63,10 @@ function user_worklog_edit_controller() } /** + * Handle form * - * @param UserWorkLog $userWorkLog - * @return [bool $valid, UserWorkLog $userWorkLog] + * @param array $userWorkLog + * @return array [bool $valid, UserWorkLog $userWorkLog] */ function user_worklog_from_request($userWorkLog) { @@ -69,14 +74,17 @@ function user_worklog_from_request($userWorkLog) $valid = true; - $userWorkLog['work_timestamp'] = parse_date('Y-m-d H:i', $request->input('work_timestamp') . ' 00:00'); + $userWorkLog['work_timestamp'] = parse_date( + 'Y-m-d H:i', + $request->input('work_timestamp') . ' 00:00' + ); if (is_null($userWorkLog['work_timestamp'])) { $valid = false; error(_('Please enter work date.')); } $userWorkLog['work_hours'] = $request->input('work_hours'); - if (! preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) { + if (!preg_match("/[0-9]+(\.[0-9]+)?/", $userWorkLog['work_hours'])) { $valid = false; error(_('Please enter work hours in format ##[.##].')); } @@ -95,6 +103,8 @@ function user_worklog_from_request($userWorkLog) /** * Add work log entry to user. + * + * @return array */ function user_worklog_add_controller() { @@ -128,12 +138,14 @@ function user_worklog_add_controller() /** * Link to work log entry add for given user. * - * @param User $user + * @param array $user + * + * @return string */ function user_worklog_add_link($user) { return page_link_to('user_worklog', [ - 'action' => 'add', + 'action' => 'add', 'user_id' => $user['UID'] ]); } @@ -141,12 +153,13 @@ function user_worklog_add_link($user) /** * Link to work log entry edit. * - * @param UserWorkLog $userWorkLog + * @param array $userWorkLog + * @return string */ function user_worklog_edit_link($userWorkLog) { return page_link_to('user_worklog', [ - 'action' => 'edit', + 'action' => 'edit', 'user_worklog_id' => $userWorkLog['id'] ]); } @@ -154,31 +167,34 @@ function user_worklog_edit_link($userWorkLog) /** * Link to work log entry delete. * - * @param UserWorkLog $userWorkLog + * @param array $userWorkLog * @param array[] $parameters + * @return string */ function user_worklog_delete_link($userWorkLog, $parameters = []) { return page_link_to('user_worklog', array_merge([ - 'action' => 'delete', + 'action' => 'delete', 'user_worklog_id' => $userWorkLog['id'] ], $parameters)); } /** * Work log entry actions + * + * @return array */ -function user_worklogs_controller() +function user_worklog_controller() { global $user, $privileges; - if (! in_array('admin_user_worklog', $privileges)) { + if (!in_array('admin_user_worklog', $privileges)) { redirect(user_link($user)); } $request = request(); $action = $request->input('action'); - if (! $request->has('action')) { + if (!$request->has('action')) { redirect(user_link($user)); } diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index 36442943..df0ec8f6 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -1,10 +1,12 @@ $user['UID'], + 'user_id' => $user['UID'], 'work_timestamp' => $work_date, - 'work_hours' => 0, - 'comment' => '' + 'work_hours' => 0, + 'comment' => '' ]; } - -?> \ No newline at end of file diff --git a/includes/model/User_model.php b/includes/model/User_model.php index a439b199..70a03736 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -20,12 +20,14 @@ function User_delete($user_id) /** * Returns the tshirt score (number of hours counted for tshirt). * Accounts only ended shifts. - * + * * @param array[] $user + * @return int */ -function User_tshirt_score($user) { +function User_tshirt_score($user) +{ $shift_sum_formula = config('shift_sum_formula'); - + $result_shifts = DB::selectOne(' SELECT ROUND((' . $shift_sum_formula . ') / 3600, 2) AS `tshirt_score` FROM `User` LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` @@ -33,7 +35,7 @@ function User_tshirt_score($user) { WHERE `User`.`UID` = ? AND `Shifts`.`end` < ? GROUP BY `User`.`UID` - ',[ + ', [ $user['UID'], time() ]); @@ -43,11 +45,11 @@ function User_tshirt_score($user) { LEFT JOIN `UserWorkLog` ON `User`.`UID` = `UserWorkLog`.`user_id` WHERE `User`.`UID` = ? AND `UserWorkLog`.`work_timestamp` < ? - ',[ + ', [ $user['UID'], time() ]); - + return $result_shifts['tshirt_score'] + $result_worklog['tshirt_score']; } @@ -385,7 +387,7 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de return new ValidationResult(false, $planned_arrival_date); } $event_config = EventConfig(); - if (empty($event_config )) { + if (empty($event_config)) { // Nothing to validate against return new ValidationResult(true, $planned_departure_date); } diff --git a/includes/view/UserWorkLog_view.php b/includes/view/UserWorkLog_view.php index 79c049b3..772d4aee 100644 --- a/includes/view/UserWorkLog_view.php +++ b/includes/view/UserWorkLog_view.php @@ -2,13 +2,18 @@ /** * Delete work log entry. - * @param User $user_source - * @param UserWorkLog $userWorkLog + * + * @param array $user_source + * @param array $userWorkLog + * @return string */ function UserWorkLog_delete_view($user_source, $userWorkLog) { return page_with_title(UserWorkLog_delete_title(), [ - info(sprintf(_('Do you want to delete the worklog entry for %s?'), User_Nick_render($user_source)), true), + info(sprintf( + _('Do you want to delete the worklog entry for %s?'), + User_Nick_render($user_source) + ), true), buttons([ button(user_link($user_source), glyph('remove') . _('cancel')), button(user_worklog_delete_link($userWorkLog, [ @@ -28,9 +33,10 @@ function UserWorkLog_delete_title() /** * Render edit table. - * - * @param User $user_source - * @param UserWorkLog $userWorkLog + * + * @param array $user_source + * @param array $userWorkLog + * @return string */ function UserWorkLog_edit_form($user_source, $userWorkLog) { @@ -46,8 +52,9 @@ function UserWorkLog_edit_form($user_source, $userWorkLog) /** * Form for edit a user work log entry. * - * @param User $user_source - * @param UserWorkLog $userWorkLog + * @param array $user_source + * @param array $userWorkLog + * @return string */ function UserWorkLog_edit_view($user_source, $userWorkLog) { @@ -63,8 +70,9 @@ function UserWorkLog_edit_view($user_source, $userWorkLog) /** * Form for adding a user work log entry. * - * @param User $user_source - * @param UserWorkLog $userWorkLog + * @param array $user_source + * @param array $userWorkLog + * @return string */ function UserWorkLog_add_view($user_source, $userWorkLog) { @@ -92,5 +100,3 @@ function UserWorkLog_add_title() { return _('Add work log entry'); } - -?> \ No newline at end of file diff --git a/includes/view/User_view.php b/includes/view/User_view.php index cc468bd2..8eee610a 100644 --- a/includes/view/User_view.php +++ b/includes/view/User_view.php @@ -406,10 +406,21 @@ function User_view_myshift($shift, $user_source, $its_me) * @param array[] $shifts * @param array $user_source * @param bool $its_me + * @param int $tshirt_score + * @param bool $tshirt_admin + * @param array[] $user_worklogs + * @param $admin_user_worklog_privilege * @return array */ -function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege) -{ +function User_view_myshifts( + $shifts, + $user_source, + $its_me, + $tshirt_score, + $tshirt_admin, + $user_worklogs, + $admin_user_worklog_privilege +) { $myshifts_table = []; $timesum = 0; foreach ($shifts as $shift) { @@ -420,8 +431,8 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi } } - if($its_me || $admin_user_worklog_privilege) { - foreach($user_worklogs as $worklog) { + if ($its_me || $admin_user_worklog_privilege) { + foreach ($user_worklogs as $worklog) { $myshifts_table[$worklog['work_timestamp']] = User_view_worklog($worklog, $admin_user_worklog_privilege); $timesum += $worklog['work_hours'] * 3600; } @@ -453,12 +464,15 @@ function User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshi /** * Renders table entry for user work log - * @param UserWorkLog $worklog - * @param bool $admin_user_worklog_privilege + * + * @param array $worklog + * @param bool $admin_user_worklog_privilege + * @return array */ -function User_view_worklog($worklog, $admin_user_worklog_privilege) { +function User_view_worklog($worklog, $admin_user_worklog_privilege) +{ $actions = ''; - if($admin_user_worklog_privilege) { + if ($admin_user_worklog_privilege) { $actions = table_buttons([ button( user_worklog_edit_link($worklog), @@ -479,11 +493,11 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) { 'room' => '', 'shift_info' => _('Work log entry'), 'comment' => $worklog['comment'] . '
' - . sprintf( - _('Added by %s at %s'), - User_Nick_render(User($worklog['created_user_id'])), - date('Y-m-d H:i', $worklog['created_timestamp']) - ), + . sprintf( + _('Added by %s at %s'), + User_Nick_render(User($worklog['created_user_id'])), + date('Y-m-d H:i', $worklog['created_timestamp']) + ), 'actions' => $actions ]; } @@ -500,6 +514,8 @@ function User_view_worklog($worklog, $admin_user_worklog_privilege) { * @param bool $its_me * @param int $tshirt_score * @param bool $tshirt_admin + * @param bool $admin_user_worklog_privilege + * @param array[] $user_worklogs * @return string */ function User_view( @@ -517,9 +533,17 @@ function User_view( ) { $user_name = htmlspecialchars($user_source['Vorname']) . ' ' . htmlspecialchars($user_source['Name']); $myshifts_table = ''; - if($its_me || $admin_user_privilege) { - $my_shifts = User_view_myshifts($shifts, $user_source, $its_me, $tshirt_score, $tshirt_admin, $user_worklogs, $admin_user_worklog_privilege); - if(count($my_shifts) > 0) { + if ($its_me || $admin_user_privilege) { + $my_shifts = User_view_myshifts( + $shifts, + $user_source, + $its_me, + $tshirt_score, + $tshirt_admin, + $user_worklogs, + $admin_user_worklog_privilege + ); + if (count($my_shifts) > 0) { $myshifts_table = table([ 'date' => _('Day & time'), 'duration' => _('Duration'), @@ -528,7 +552,7 @@ function User_view( 'comment' => _('Comment'), 'actions' => _('Action') ], $my_shifts); - } elseif($user_source['force_active']) { + } elseif ($user_source['force_active']) { $myshifts_table = success(_('You have done enough to get a t-shirt.'), true); } } diff --git a/public/index.php b/public/index.php index adf22e71..db4c4294 100644 --- a/public/index.php +++ b/public/index.php @@ -132,7 +132,7 @@ if ( $content = user_shifts(); break; case 'user_worklog': - list($title, $content) = user_worklogs_controller(); + list($title, $content) = user_worklog_controller(); break; case 'user_messages': $title = messages_title(); -- cgit v1.2.3-54-g00ecf From 0d154365a23678c138cadad31f746aa27ac3f96a Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 14 Jan 2018 23:07:34 +0100 Subject: models: return null on empty result --- includes/model/AngelType_model.php | 6 ++++-- includes/model/EventConfig_model.php | 6 ++++-- includes/model/Message_model.php | 6 ++++-- includes/model/Room_model.php | 6 ++++-- includes/model/ShiftEntry_model.php | 6 ++++-- includes/model/ShiftTypes_model.php | 6 ++++-- includes/model/Shifts_model.php | 2 +- includes/model/UserAngelTypes_model.php | 12 ++++++++---- includes/model/UserDriverLicenses_model.php | 6 ++++-- includes/model/UserWorkLog_model.php | 6 ++++-- includes/model/User_model.php | 24 ++++++++++++++++-------- 11 files changed, 57 insertions(+), 29 deletions(-) (limited to 'includes/model/User_model.php') diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 642d3d70..2dff7019 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -225,12 +225,14 @@ function AngelType_ids() * Returns angelType by id. * * @param int $angeltype_id angelType ID - * @return array + * @return array|null */ function AngelType($angeltype_id) { - return DB::selectOne( + $angelType = DB::selectOne( 'SELECT * FROM `AngelTypes` WHERE `id`=?', [$angeltype_id] ); + + return empty($angelType) ? null : $angelType; } diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php index 6d782ec4..766a5849 100644 --- a/includes/model/EventConfig_model.php +++ b/includes/model/EventConfig_model.php @@ -5,11 +5,13 @@ use Engelsystem\Database\DB; /** * Get event config. * - * @return array + * @return array|null */ function EventConfig() { - return DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1'); + $config = DB::selectOne('SELECT * FROM `EventConfig` LIMIT 1'); + + return empty($config) ? null : $config; } /** diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php index 9bd7d6ef..3f66f74a 100644 --- a/includes/model/Message_model.php +++ b/includes/model/Message_model.php @@ -16,11 +16,13 @@ function Message_ids() * Returns message by id. * * @param int $message_id message ID - * @return array + * @return array|null */ function Message($message_id) { - return DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); + $message = DB::selectOne('SELECT * FROM `Messages` WHERE `id`=? LIMIT 1', [$message_id]); + + return empty($message) ? null : $message; } /** diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php index 36a375aa..b29f68fe 100644 --- a/includes/model/Room_model.php +++ b/includes/model/Room_model.php @@ -148,14 +148,16 @@ function Room_update($room_id, $name, $from_frab, $map_url, $description) * Returns room by id. * * @param int $room_id RID - * @return array + * @return array|null */ function Room($room_id) { - return DB::selectOne(' + $room = DB::selectOne(' SELECT * FROM `Room` WHERE `RID` = ?', [ $room_id ]); + + return empty($room) ? null : $room; } diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php index 02eace1e..ebf600f3 100644 --- a/includes/model/ShiftEntry_model.php +++ b/includes/model/ShiftEntry_model.php @@ -134,11 +134,13 @@ function ShiftEntry_update($shift_entry) * Get a shift entry. * * @param int $shift_entry_id - * @return array + * @return array|null */ function ShiftEntry($shift_entry_id) { - return DB::selectOne('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]); + $shiftEntry = DB::selectOne('SELECT * FROM `ShiftEntry` WHERE `id` = ?', [$shift_entry_id]); + + return empty($shiftEntry) ? null : $shiftEntry; } /** diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php index 0e8ef3a4..599810be 100644 --- a/includes/model/ShiftTypes_model.php +++ b/includes/model/ShiftTypes_model.php @@ -66,11 +66,13 @@ function ShiftType_create($name, $angeltype_id, $description) * Get a shift type by id. * * @param int $shifttype_id - * @return array + * @return array|null */ function ShiftType($shifttype_id) { - return DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); + $shiftType = DB::selectOne('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]); + + return empty($shiftType) ? null : $shiftType; } /** diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 5719a8e1..94513ff3 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -552,7 +552,7 @@ function Shift_update($shift) * Update a shift by its external id. * * @param array $shift - * @return bool|null + * @return int * @throws Exception */ function Shift_update_by_psid($shift) diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php index c744cdd7..b1005095 100644 --- a/includes/model/UserAngelTypes_model.php +++ b/includes/model/UserAngelTypes_model.php @@ -193,15 +193,17 @@ function UserAngelType_create($user, $angeltype) * Get an UserAngelType by its id. * * @param int $user_angeltype_id - * @return array + * @return array|null */ function UserAngelType($user_angeltype_id) { - return DB::selectOne(' + $angelType = DB::selectOne(' SELECT * FROM `UserAngelTypes` WHERE `id`=? LIMIT 1', [$user_angeltype_id]); + + return empty($angelType) ? null : $angelType; } /** @@ -209,11 +211,11 @@ function UserAngelType($user_angeltype_id) * * @param array $user * @param array $angeltype - * @return array + * @return array|null */ function UserAngelType_by_User_and_AngelType($user, $angeltype) { - return DB::selectOne(' + $angelType = DB::selectOne(' SELECT * FROM `UserAngelTypes` WHERE `user_id`=? @@ -225,6 +227,8 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) $angeltype['id'] ] ); + + return empty($angelType) ? null : $angelType; } /** diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php index a1476f95..2c251d66 100644 --- a/includes/model/UserDriverLicenses_model.php +++ b/includes/model/UserDriverLicenses_model.php @@ -41,14 +41,16 @@ function UserDriverLicense_valid($user_driver_license) * Get a users driver license information * * @param int $user_id The users id - * @return array + * @return array|null */ function UserDriverLicense($user_id) { - return DB::selectOne(' + $driverLicense = DB::selectOne(' SELECT * FROM `UserDriverLicenses` WHERE `user_id`=?', [$user_id]); + + return empty($driverLicense) ? null : $driverLicense; } /** diff --git a/includes/model/UserWorkLog_model.php b/includes/model/UserWorkLog_model.php index df0ec8f6..ff39ba8f 100644 --- a/includes/model/UserWorkLog_model.php +++ b/includes/model/UserWorkLog_model.php @@ -6,13 +6,15 @@ use Engelsystem\Database\Db; * Load a single work log entry. * * @param int $user_worklog_id - * @return array + * @return array|null */ function UserWorkLog($user_worklog_id) { - return Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [ + $workLog = Db::selectOne("SELECT * FROM `UserWorkLog` WHERE `id`=?", [ $user_worklog_id ]); + + return empty($workLog) ? null : $workLog; } /** diff --git a/includes/model/User_model.php b/includes/model/User_model.php index 70a03736..d2498462 100644 --- a/includes/model/User_model.php +++ b/includes/model/User_model.php @@ -406,44 +406,52 @@ function User_validate_planned_departure_date($planned_arrival_date, $planned_de * Returns user by id. * * @param int $user_id UID - * @return array + * @return array|null */ function User($user_id) { - return DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `UID`=? LIMIT 1', [$user_id]); + + return empty($user) ? null : $user; } /** * Returns User by api_key. * * @param string $api_key User api key - * @return array Matching user, empty if not found + * @return array|null Matching user, null if not found */ function User_by_api_key($api_key) { - return DB::selectOne('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `api_key`=? LIMIT 1', [$api_key]); + + return empty($user) ? null : $user; } /** * Returns User by email. * * @param string $email - * @return array Matching user, empty on error + * @return array|null Matching user, null when not found */ function User_by_email($email) { - return DB::selectOne('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `email`=? LIMIT 1', [$email]); + + return empty($user) ? null : $user; } /** * Returns User by password token. * * @param string $token - * @return array Matching user, empty when not found + * @return array|null Matching user, null when not found */ function User_by_password_recovery_token($token) { - return DB::selectOne('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]); + $user = DB::selectOne('SELECT * FROM `User` WHERE `password_recovery_token`=? LIMIT 1', [$token]); + + return empty($user) ? null : $user; } /** -- cgit v1.2.3-54-g00ecf