diff --git a/application/controllers/Booking.php b/application/controllers/Booking.php index ceeb6418..72398059 100755 --- a/application/controllers/Booking.php +++ b/application/controllers/Booking.php @@ -131,7 +131,6 @@ class Booking extends EA_Controller { $display_login_button = setting('display_login_button'); $display_delete_personal_information = setting('display_delete_personal_information'); $book_advance_timeout = setting('book_advance_timeout'); - $future_booking_limit = setting('future_booking_limit'); $theme = request('theme', setting('theme', 'default')); if (empty($theme) || ! file_exists(__DIR__ . '/../../assets/css/themes/' . $theme . '.min.css')) @@ -286,7 +285,7 @@ class Booking extends EA_Controller { * * @param string $appointment_hash */ - public function reschedule($appointment_hash) + public function reschedule(string $appointment_hash) { html_vars(['appointment_hash' => $appointment_hash]); @@ -311,7 +310,7 @@ class Booking extends EA_Controller { if (empty($provider_id)) { - json_response([]); + json_response(); return; } @@ -397,7 +396,7 @@ class Booking extends EA_Controller { // Check if the provider is available for the requested date. $available_hours = $this->availability->get_available_hours($date, $service, $provider); - if (count($available_hours) > $max_hours_count && (empty($hour) || in_array($hour, $available_hours, FALSE))) + if (count($available_hours) > $max_hours_count && (empty($hour) || in_array($hour, $available_hours))) { $provider_id = $provider['id']; @@ -567,7 +566,7 @@ class Booking extends EA_Controller { 'time_format' => setting('time_format') ]; - $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); + $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings); $this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); @@ -596,7 +595,7 @@ class Booking extends EA_Controller { * Use this method just before the customer confirms the appointment registration. If the selected date was reserved * in the meanwhile, the customer must be prompted to select another time. * - * @return int Returns the ID of the provider that is available for the appointment. + * @return int|null Returns the ID of the provider that is available for the appointment. * * @throws Exception */ diff --git a/application/controllers/Booking_confirmation.php b/application/controllers/Booking_confirmation.php index 4ca87e7e..64300f11 100755 --- a/application/controllers/Booking_confirmation.php +++ b/application/controllers/Booking_confirmation.php @@ -36,6 +36,8 @@ class Booking_confirmation extends EA_Controller { /** * Display the appointment registration success page. + * + * @throws Exception */ public function of() { diff --git a/application/controllers/Calendar.php b/application/controllers/Calendar.php index b1bdd84f..cee3c718 100644 --- a/application/controllers/Calendar.php +++ b/application/controllers/Calendar.php @@ -227,7 +227,7 @@ class Calendar extends EA_Controller { ? can('add', PRIV_APPOINTMENTS) : can('edit', PRIV_APPOINTMENTS); - if ($required_permissions == FALSE) + if ( ! $required_permissions) { throw new RuntimeException('You do not have the required permissions for this task.'); } @@ -279,7 +279,7 @@ class Calendar extends EA_Controller { 'time_format' => setting('time_format') ]; - $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); + $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings); $this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); @@ -411,7 +411,7 @@ class Calendar extends EA_Controller { $this->unavailabilities_model->delete($unavailability_id); - $this->synchronization->sync_appointment_deleted($unavailability, $provider); + $this->synchronization->sync_unavailability_deleted($unavailability, $provider); $this->webhooks_client->trigger(WEBHOOK_UNAVAILABILITY_DELETE, $unavailability); diff --git a/application/controllers/Google.php b/application/controllers/Google.php index c75af08f..7ec2c305 100644 --- a/application/controllers/Google.php +++ b/application/controllers/Google.php @@ -39,8 +39,6 @@ class Google extends EA_Controller { * This method will completely sync the appointments of a provider with his Google Calendar account. The sync period * needs to be relatively small, because a lot of API calls might be necessary and this will lead to consuming the * Google limit for the Calendar API usage. - * - * @param string $provider_id Provider record to be synced. */ public static function sync(string $provider_id = NULL) { @@ -166,7 +164,7 @@ class Google extends EA_Controller { } } - catch (Throwable $e) + catch (Throwable) { // Appointment not found on Google Calendar, delete from Easy!Appointments. $CI->appointments_model->delete($appointment['id']); @@ -285,7 +283,10 @@ class Google extends EA_Controller { * * IMPORTANT: Because it is necessary to authorize the application using the web server flow (see official * documentation of OAuth), every Easy!Appointments installation should use its own calendar api key. So in every - * api console account, the "http://path-to-Easy!Appointments/google/oauth_callback" should be included in an allowed redirect URL. + * api console account, the "http://path-to-Easy!Appointments/google/oauth_callback" should be included in an + * allowed redirect URL. + * + * @throws Exception */ public function oauth_callback() { @@ -431,7 +432,7 @@ class Google extends EA_Controller { $this->providers_model->set_setting($provider_id, 'google_sync', FALSE); - $this->providers_model->set_setting($provider_id, 'google_token', NULL); + $this->providers_model->set_setting($provider_id, 'google_token'); $this->appointments_model->clear_google_sync_ids($provider_id); diff --git a/application/controllers/Installation.php b/application/controllers/Installation.php index 2231f409..f274e3b0 100644 --- a/application/controllers/Installation.php +++ b/application/controllers/Installation.php @@ -42,7 +42,7 @@ class Installation extends EA_Controller { { if (is_app_installed()) { - redirect(''); + redirect(); return; } diff --git a/application/controllers/api/v1/Appointments_api_v1.php b/application/controllers/api/v1/Appointments_api_v1.php index 056b7143..1490fbe7 100644 --- a/application/controllers/api/v1/Appointments_api_v1.php +++ b/application/controllers/api/v1/Appointments_api_v1.php @@ -334,7 +334,7 @@ class Appointments_api_v1 extends EA_Controller { 'time_format' => setting('time_format') ]; - $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); + $this->synchronization->sync_appointment_saved($appointment, $service, $provider, $customer, $settings); $this->notifications->notify_appointment_saved($appointment, $service, $provider, $customer, $settings, $manage_mode); } diff --git a/application/core/EA_Model.php b/application/core/EA_Model.php index 0cebcff4..a877b5fc 100644 --- a/application/core/EA_Model.php +++ b/application/core/EA_Model.php @@ -43,7 +43,7 @@ class EA_Model extends CI_Model { /** * @var array */ - protected $casts = []; + protected array $casts = []; /** * EA_Model constructor. diff --git a/application/helpers/asset_helper.php b/application/helpers/asset_helper.php index b75ea094..8599b56f 100644 --- a/application/helpers/asset_helper.php +++ b/application/helpers/asset_helper.php @@ -22,18 +22,18 @@ * * @return string Returns the final asset URL. */ -function asset_url($uri = '', $protocol = NULL) +function asset_url(string $uri = '', string $protocol = NULL): string { $debug = config('debug'); $cache_busting_token = ! $debug ? '?' . config('cache_busting_token') : ''; - if (strpos(basename($uri), '.js') !== FALSE && strpos(basename($uri), '.min.js') === FALSE && ! $debug) + if (str_contains(basename($uri), '.js') && ! str_contains(basename($uri), '.min.js') && ! $debug) { $uri = str_replace('.js', '.min.js', $uri); } - if (strpos(basename($uri), '.css') !== FALSE && strpos(basename($uri), '.min.css') === FALSE && ! $debug) + if (str_contains(basename($uri), '.css') && ! str_contains(basename($uri), '.min.css') && ! $debug) { $uri = str_replace('.css', '.min.css', $uri); } diff --git a/application/helpers/config_helper.php b/application/helpers/config_helper.php index 2f86c6f5..81414fbc 100644 --- a/application/helpers/config_helper.php +++ b/application/helpers/config_helper.php @@ -25,13 +25,13 @@ * config(['version' => '1.0.0']); * * @param array|string $key Configuration key. - * @param mixed $default Default value in case the requested config has no value. + * @param mixed|null $default Default value in case the requested config has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value. * * @throws InvalidArgumentException */ -function config($key, $default = NULL) +function config(array|string $key, mixed $default = NULL): mixed { /** @var EA_Controller $CI */ $CI = &get_instance(); @@ -71,14 +71,14 @@ if ( ! function_exists('script_vars')) * * script_vars(['version' => '1.0.0']); * - * @param array|string $key Configuration key. - * @param mixed $default Default value in case the requested config has no value. + * @param array|string|null $key Configuration key. + * @param mixed|null $default Default value in case the requested config has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value. * * @throws InvalidArgumentException */ - function script_vars($key = NULL, $default = NULL) + function script_vars(array|string $key = NULL, mixed $default = NULL): mixed { $script_vars = config('script_vars', []); @@ -120,14 +120,14 @@ if ( ! function_exists('html_vars')) * * html_vars(['title' => 'Test Title']); * - * @param array|string $key Variable key. - * @param mixed $default Default value in case the requested variable has no value. + * @param array|string|null $key Variable key. + * @param mixed|null $default Default value in case the requested variable has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value. * * @throws InvalidArgumentException */ - function html_vars($key = NULL, $default = NULL) + function html_vars(array|string $key = NULL, mixed $default = NULL): mixed { $html_vars = config('html_vars', []); @@ -169,14 +169,14 @@ if ( ! function_exists('vars')) * * vars(['version' => '1.0.0']); * - * @param array|string $key Configuration key. - * @param mixed $default Default value in case the requested config has no value. + * @param array|string|null $key Configuration key. + * @param mixed|null $default Default value in case the requested config has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new configuration value. * * @throws InvalidArgumentException */ - function vars($key = NULL, $default = NULL) + function vars(array|string $key = NULL, mixed $default = NULL): mixed { return html_vars($key) ?? script_vars($key) ?? $default; } diff --git a/application/helpers/debug_helper.php b/application/helpers/debug_helper.php index 62fdf1f5..4f1d248b 100644 --- a/application/helpers/debug_helper.php +++ b/application/helpers/debug_helper.php @@ -1,4 +1,6 @@ - [ @@ -99,7 +99,7 @@ if ( ! function_exists('section')) * * @param string $name */ - function section(string $name) + function section(string $name): void { $layout = config('layout'); @@ -148,7 +148,7 @@ if ( ! function_exists('end_section')) * * @param string $name */ - function end_section(string $name) + function end_section(string $name): void { $layout = config('layout'); @@ -170,7 +170,7 @@ if ( ! function_exists('slot')) * * @param string $name */ - function slot(string $name) + function slot(string $name): void { $layout = config('layout'); diff --git a/application/helpers/installation_helper.php b/application/helpers/installation_helper.php index c65d56c9..535593a8 100644 --- a/application/helpers/installation_helper.php +++ b/application/helpers/installation_helper.php @@ -21,7 +21,7 @@ * * @return bool Returns whether E!A is installed or not. */ -function is_app_installed() +function is_app_installed(): bool { $CI =& get_instance(); diff --git a/application/helpers/rate_limit_helper.php b/application/helpers/rate_limit_helper.php index 3d932aab..271b58ae 100644 --- a/application/helpers/rate_limit_helper.php +++ b/application/helpers/rate_limit_helper.php @@ -26,8 +26,9 @@ if ( ! function_exists('rate_limit')) * @param int $max_requests Number of allowed requests, defaults to 100. * @param int $duration In seconds, defaults to 2 minutes. */ - function rate_limit(string $ip, int $max_requests = 100, int $duration = 120) + function rate_limit(string $ip, int $max_requests = 100, int $duration = 120): void { + /** @var EA_Controller $CI */ $CI =& get_instance(); $rate_limiting = $CI->config->item('rate_limiting'); diff --git a/application/helpers/routes_helper.php b/application/helpers/routes_helper.php index d131bbfe..3554e9f5 100644 --- a/application/helpers/routes_helper.php +++ b/application/helpers/routes_helper.php @@ -18,9 +18,9 @@ if ( ! function_exists('route_api_resource')) * * @param array $route Route config. * @param string $resource Resource name. - * @param string|null $prefix URL prefix (e.g. api/v1/). + * @param string $prefix URL prefix (e.g. api/v1/). */ - function route_api_resource(array &$route, string $resource, string $prefix = '') + function route_api_resource(array &$route, string $resource, string $prefix = ''): void { $route[$prefix . $resource]['post'] = 'api/v1/' . $resource . '_api_v1/store'; $route[$prefix . $resource . '/(:num)']['put'] = 'api/v1/' . $resource . '_api_v1/update/$1'; diff --git a/application/helpers/session_helper.php b/application/helpers/session_helper.php index f22e67a4..0af7cf79 100644 --- a/application/helpers/session_helper.php +++ b/application/helpers/session_helper.php @@ -26,14 +26,14 @@ if ( ! function_exists('session')) * * session(['logged_in' => FALSE]); * - * @param array|string $key Session item key. - * @param mixed $default Default value in case the requested session item has no value. + * @param array|string|null $key Session item key. + * @param mixed|null $default Default value in case the requested session item has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new session value. * * @throws InvalidArgumentException */ - function session($key = NULL, $default = NULL) + function session(array|string $key = NULL, mixed $default = NULL): mixed { /** @var EA_Controller $CI */ $CI = &get_instance(); diff --git a/application/helpers/setting_helper.php b/application/helpers/setting_helper.php index c1b428d1..e1332bdd 100644 --- a/application/helpers/setting_helper.php +++ b/application/helpers/setting_helper.php @@ -26,14 +26,14 @@ if ( ! function_exists('setting')) * * setting(['company_name' => 'ACME Inc']); * - * @param array|string $key Setting key. - * @param mixed $default Default value in case the requested setting has no value. + * @param array|string|null $key Setting key. + * @param mixed|null $default Default value in case the requested setting has no value. * * @return mixed|NULL Returns the requested value or NULL if you assign a new setting value. * * @throws InvalidArgumentException */ - function setting($key = NULL, $default = NULL) + function setting(array|string $key = NULL, mixed $default = NULL): mixed { /** @var EA_Controller $CI */ $CI = &get_instance(); diff --git a/application/libraries/Accounts.php b/application/libraries/Accounts.php index f2c3e679..706604d7 100644 --- a/application/libraries/Accounts.php +++ b/application/libraries/Accounts.php @@ -21,9 +21,9 @@ */ class Accounts { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Accounts constructor. @@ -45,6 +45,7 @@ class Accounts { * @param string $password Password (non-hashed). * * @return array|null Returns an associative array with the PHP session data or NULL on failure. + * @throws Exception */ public function check_login(string $username, string $password): ?array { @@ -112,9 +113,9 @@ class Accounts { * @param string $username Username. * @param string $email Email. * - * @return string|bool Returns the new password on success or FALSE on failure. + * @return string Returns the new password on success or FALSE on failure. * - * @throws RuntimeException + * @throws Exception */ public function regenerate_password(string $username, string $email): string { diff --git a/application/libraries/Api.php b/application/libraries/Api.php index cc9484f4..eaf2fff6 100644 --- a/application/libraries/Api.php +++ b/application/libraries/Api.php @@ -1,4 +1,6 @@ -CI->load->model($model); @@ -60,7 +62,7 @@ class Api { /** * Authorize the API request (Basic Auth or Bearer Token supported). */ - public function auth() + public function auth(): void { try { @@ -84,7 +86,7 @@ class Api { throw new RuntimeException('The provided credentials do not match any admin user!', 401, 'Unauthorized'); } } - catch (Throwable $e) + catch (Throwable) { $this->request_authentication(); } @@ -93,7 +95,7 @@ class Api { /** * Returns the bearer token value. * - * @return string + * @return string|null */ protected function get_bearer_token(): ?string { @@ -153,7 +155,7 @@ class Api { /** * Sets request authentication headers. */ - public function request_authentication() + #[NoReturn] public function request_authentication(): void { header('WWW-Authenticate: Basic realm="Easy!Appointments"'); header('HTTP/1.0 401 Unauthorized'); diff --git a/application/libraries/Availability.php b/application/libraries/Availability.php index 2fd9b557..0372e380 100644 --- a/application/libraries/Availability.php +++ b/application/libraries/Availability.php @@ -21,9 +21,9 @@ */ class Availability { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Availability constructor. @@ -126,7 +126,7 @@ class Availability { $date_working_plan = $working_plan[$working_day] ?? NULL; - // Search if the $date is an custom availability period added outside the normal working plan. + // Search if the $date is a custom availability period added outside the normal working plan. if (isset($working_plan_exceptions[$date])) { $date_working_plan = $working_plan_exceptions[$date]; @@ -145,7 +145,7 @@ class Availability { $day_end = new DateTime($date_working_plan['end']); // Split the working plan to available time periods that do not contain the breaks in them. - foreach ($date_working_plan['breaks'] as $index => $break) + foreach ($date_working_plan['breaks'] as $break) { $break_start = new DateTime($break['start']); $break_end = new DateTime($break['end']); @@ -373,7 +373,7 @@ class Availability { $date_working_plan = $working_plan[$working_day] ?? NULL; - // Search if the $date is an custom availability period added outside the normal working plan. + // Search if the $date is a custom availability period added outside the normal working plan. if (isset($working_plan_exceptions[$date])) { $date_working_plan = $working_plan_exceptions[$date]; @@ -505,7 +505,6 @@ class Availability { { // break contains period $period['start'] = $break_end; - continue; } } } @@ -620,7 +619,7 @@ class Availability { * @param array $available_hours * @param array $provider * - * @return array|mixed + * @return array * * @throws Exception */ diff --git a/application/libraries/Email_messages.php b/application/libraries/Email_messages.php index af4d5376..a8e4dbee 100644 --- a/application/libraries/Email_messages.php +++ b/application/libraries/Email_messages.php @@ -20,9 +20,9 @@ */ class Email_messages { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Email_messages constructor. diff --git a/application/libraries/Google_sync.php b/application/libraries/Google_sync.php index d0046773..0b66bc9c 100644 --- a/application/libraries/Google_sync.php +++ b/application/libraries/Google_sync.php @@ -22,19 +22,19 @@ use Google\Service\Calendar\Events; */ class Google_sync { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * @var Google_Client */ - protected $client; + protected Google_Client $client; /** * @var Google_Service_Calendar */ - protected $service; + protected Google_Service_Calendar $service; /** * Google_sync constructor. @@ -57,7 +57,7 @@ class Google_sync { /** * Initialize the client, so that existing execution errors are not passed from one provider to another. */ - public function initialize_clients() + public function initialize_clients(): void { $http = new GuzzleHttp\Client([ 'verify' => FALSE @@ -126,7 +126,7 @@ class Google_sync { * @param string $refresh_token The provider's refresh token. This value is stored in the database and used every * time we need to make actions to his Google Calendar account. */ - public function refresh_token(string $refresh_token) + public function refresh_token(string $refresh_token): void { $this->initialize_clients(); @@ -247,7 +247,7 @@ class Google_sync { * @param array $provider Provider data. * @param string $google_event_id The Google Calendar event ID to be removed. */ - public function delete_appointment(array $provider, string $google_event_id) + public function delete_appointment(array $provider, string $google_event_id): void { $this->service->events->delete($provider['settings']['google_calendar'], $google_event_id); } @@ -318,7 +318,7 @@ class Google_sync { * @param array $provider Provider data. * @param string $google_event_id Google Calendar event ID to be removed. */ - public function delete_unavailability(array $provider, string $google_event_id) + public function delete_unavailability(array $provider, string $google_event_id): void { $this->service->events->delete($provider['settings']['google_calendar'], $google_event_id); } diff --git a/application/libraries/Ics_file.php b/application/libraries/Ics_file.php index 25789d22..fb900446 100644 --- a/application/libraries/Ics_file.php +++ b/application/libraries/Ics_file.php @@ -33,9 +33,9 @@ use Jsvrcek\ICS\Utility\Formatter; */ class Ics_file { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Availability constructor. diff --git a/application/libraries/Instance.php b/application/libraries/Instance.php index 05d24767..c19db101 100644 --- a/application/libraries/Instance.php +++ b/application/libraries/Instance.php @@ -22,9 +22,9 @@ require_once __DIR__ . '/../core/EA_Migration.php'; */ class Instance { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Installation constructor. @@ -47,7 +47,7 @@ class Instance { * * @param string $type Provide "fresh" to revert previous migrations and start from the beginning or "up"/"down" to step. */ - public function migrate(string $type = '') + public function migrate(string $type = ''): void { $current_version = $this->CI->migration->current_version(); @@ -166,7 +166,7 @@ class Instance { * * @throws Exception */ - public function backup(string $path = NULL) + public function backup(string $path = NULL): void { $path = $path ?? APPPATH . '/../storage/backups'; diff --git a/application/libraries/Notifications.php b/application/libraries/Notifications.php index 3ad55974..7fd294a8 100644 --- a/application/libraries/Notifications.php +++ b/application/libraries/Notifications.php @@ -20,9 +20,9 @@ */ class Notifications { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Notifications constructor. diff --git a/application/libraries/Permissions.php b/application/libraries/Permissions.php index ddf8368d..2dd12bab 100644 --- a/application/libraries/Permissions.php +++ b/application/libraries/Permissions.php @@ -21,9 +21,9 @@ */ class Permissions { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Permissions constructor. @@ -65,12 +65,12 @@ class Permissions { return TRUE; } - if ($role_slug === DB_SLUG_PROVIDER && $limit_customer_access) + if ($role_slug === DB_SLUG_PROVIDER) { return $this->CI->appointments_model->query()->where(['id_users_provider' => $user_id, 'id_users_customer' => $customer_id])->get()->num_rows() > 0; } - if ($role_slug === DB_SLUG_SECRETARY && $limit_customer_access) + if ($role_slug === DB_SLUG_SECRETARY) { $secretary = $this->CI->secretaries_model->find($user_id); diff --git a/application/libraries/Synchronization.php b/application/libraries/Synchronization.php index a99ac860..b1f460a0 100644 --- a/application/libraries/Synchronization.php +++ b/application/libraries/Synchronization.php @@ -20,9 +20,9 @@ */ class Synchronization { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Synchronization constructor. @@ -45,9 +45,8 @@ class Synchronization { * @param array $provider Provider record. * @param array $customer Customer record. * @param array $settings Required settings for the notification content. - * @param bool|false $manage_mode True if the appointment is being edited. */ - public function sync_appointment_saved(array $appointment, array $service, array $provider, array $customer, array $settings, bool $manage_mode = FALSE) + public function sync_appointment_saved(array $appointment, array $service, array $provider, array $customer, array $settings): void { try { @@ -103,7 +102,7 @@ class Synchronization { * @param array $appointment Appointment record. * @param array $provider Provider record. */ - public function sync_appointment_deleted(array $appointment, array $provider) + public function sync_appointment_deleted(array $appointment, array $provider): void { try { @@ -137,7 +136,7 @@ class Synchronization { * @param array $unavailability Unavailability record. * @param array $provider Provider record. */ - public function sync_unavailability_saved(array $unavailability, array $provider) + public function sync_unavailability_saved(array $unavailability, array $provider): void { try { @@ -181,7 +180,7 @@ class Synchronization { * @param array $unavailability Unavailability record. * @param array $provider Provider record. */ - public function sync_unavailability_deleted(array $unavailability, array $provider) + public function sync_unavailability_deleted(array $unavailability, array $provider): void { try { @@ -213,9 +212,9 @@ class Synchronization { * * @throws Exception */ - public function remove_appointment_on_provider_change($appointment_id) + public function remove_appointment_on_provider_change($appointment_id): void { - $existing_appointment = $this->CI->appointments_model->get_row($appointment_id); + $existing_appointment = $this->CI->appointments_model->find($appointment_id); $existing_google_id = $existing_appointment['id_google_calendar']; @@ -223,7 +222,7 @@ class Synchronization { if ( ! empty($existing_google_id) && (int)$existing_provider_id !== (int)$existing_appointment['id_users_provider']) { - $existing_provider = $this->CI->providers_model->get_row($existing_provider_id); + $existing_provider = $this->CI->providers_model->find($existing_provider_id); if ($existing_provider['settings']['google_sync']) { diff --git a/application/libraries/Timezones.php b/application/libraries/Timezones.php index 58f9ef03..d041a53c 100644 --- a/application/libraries/Timezones.php +++ b/application/libraries/Timezones.php @@ -20,19 +20,19 @@ */ class Timezones { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * @var string */ - protected $default = 'UTC'; + protected string $default = 'UTC'; /** * @var array */ - protected $timezones = [ + protected array $timezones = [ 'UTC' => [ 'UTC' => 'UTC' ], @@ -517,31 +517,17 @@ class Timezones { * * @return array */ - public function to_grouped_array() + public function to_grouped_array(): array { return $this->timezones; } - /** - * Returns the session timezone or the default timezone as a fallback. - * - * @return string - */ - public function get_session_timezone(): string - { - $default_timezone = $this->get_default_timezone(); - - $timezone = session('timezone'); - - return $timezone ?? $default_timezone; - } - /** * Get the default timezone value of the current system. * * @return string */ - public function get_default_timezone() + public function get_default_timezone(): string { return 'UTC'; } @@ -557,7 +543,7 @@ class Timezones { * * @throws Exception */ - public function convert($value, $from_timezone, $to_timezone) + public function convert(string $value, string $from_timezone, string $to_timezone): string { if ( ! $to_timezone || $from_timezone === $to_timezone) { @@ -582,11 +568,11 @@ class Timezones { * * @return string|null */ - public function get_timezone_name($value) + public function get_timezone_name(string $value): ?string { $timezones = $this->to_array(); - return isset($timezones[$value]) ? $timezones[$value] : NULL; + return $timezones[$value] ?? NULL; } /** @@ -594,7 +580,7 @@ class Timezones { * * @return array */ - public function to_array() + public function to_array(): array { return array_merge(...array_values($this->timezones)); } diff --git a/application/libraries/Webhooks_client.php b/application/libraries/Webhooks_client.php index b6a0cc0d..8d4ad19c 100644 --- a/application/libraries/Webhooks_client.php +++ b/application/libraries/Webhooks_client.php @@ -22,9 +22,9 @@ use GuzzleHttp\Client; */ class Webhooks_client { /** - * @var EA_Controller + * @var EA_Controller|CI_Controller */ - protected $CI; + protected EA_Controller|CI_Controller $CI; /** * Webhook client constructor. @@ -56,7 +56,7 @@ class Webhooks_client { foreach ($webhooks as $webhook) { - if (strpos($webhook['actions'], $action) !== FALSE) + if (str_contains($webhook['actions'], $action)) { $this->call($webhook, $action, $payload); } @@ -70,7 +70,7 @@ class Webhooks_client { * @param string $action * @param array $payload */ - private function call(array $webhook, string $action, array $payload) + private function call(array $webhook, string $action, array $payload): void { try { diff --git a/application/models/Admins_model.php b/application/models/Admins_model.php index 8d2813fa..2086ec24 100644 --- a/application/models/Admins_model.php +++ b/application/models/Admins_model.php @@ -22,7 +22,7 @@ class Admins_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'id_roles' => 'integer', ]; @@ -30,7 +30,7 @@ class Admins_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'firstName' => 'first_name', 'lastName' => 'last_name', @@ -55,6 +55,7 @@ class Admins_model extends EA_Model { * @return int Returns the admin ID. * * @throws InvalidArgumentException + * @throws Exception */ public function save(array $admin): int { @@ -153,7 +154,7 @@ class Admins_model extends EA_Model { ->where('roles.slug', DB_SLUG_ADMIN) ->where('users.email', $admin['email']) ->where('users.id !=', $admin_id) - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->get() ->num_rows(); @@ -194,7 +195,7 @@ class Admins_model extends EA_Model { * * @return int Returns the admin ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function insert(array $admin): int { @@ -231,6 +232,7 @@ class Admins_model extends EA_Model { * @return int Returns the admin ID. * * @throws RuntimeException + * @throws Exception */ protected function update(array $admin): int { @@ -378,7 +380,7 @@ class Admins_model extends EA_Model { /** * Get all admins that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -386,7 +388,7 @@ class Admins_model extends EA_Model { * * @return array Returns an array of admins. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { $role_id = $this->get_admin_role_id(); @@ -474,9 +476,9 @@ class Admins_model extends EA_Model { * * @param int $admin_id Admin ID. * @param string $name Setting name. - * @param mixed $value Setting value. + * @param mixed|null $value Setting value. */ - public function set_setting(int $admin_id, string $name, $value = NULL) + public function set_setting(int $admin_id, string $name, mixed $value = NULL) { if ( ! $this->db->update('user_settings', [$name => $value], ['id_users' => $admin_id])) { diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index 7519e0fe..9b84cc74 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -20,7 +20,7 @@ class Appointments_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'is_unavailability' => 'boolean', 'id_users_provider' => 'integer', @@ -31,7 +31,7 @@ class Appointments_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'book' => 'book_datetime', 'start' => 'start_datetime', @@ -306,7 +306,7 @@ class Appointments_model extends EA_Model { /** * Get all appointments that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -314,7 +314,7 @@ class Appointments_model extends EA_Model { * * @return array Returns an array of appointments. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Categories_model.php b/application/models/Categories_model.php index 62adcd47..0505d568 100644 --- a/application/models/Categories_model.php +++ b/application/models/Categories_model.php @@ -22,14 +22,14 @@ class Categories_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', ]; /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'name' => 'name', 'description' => 'description', @@ -225,7 +225,7 @@ class Categories_model extends EA_Model { /** * Get all services that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -233,7 +233,7 @@ class Categories_model extends EA_Model { * * @return array Returns an array of service categories. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Consents_model.php b/application/models/Consents_model.php index eb41cd3d..7800a6bf 100644 --- a/application/models/Consents_model.php +++ b/application/models/Consents_model.php @@ -22,7 +22,7 @@ class Consents_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', ]; @@ -130,7 +130,7 @@ class Consents_model extends EA_Model { } else { - return $this->db->update('consents', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $consent_id]); + $this->db->update('consents', ['delete_datetime' => date('Y-m-d H:i:s')], ['id' => $consent_id]); } } @@ -207,7 +207,7 @@ class Consents_model extends EA_Model { /** * Get all consents that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -215,7 +215,7 @@ class Consents_model extends EA_Model { * * @return array Returns an array of consents. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Customers_model.php b/application/models/Customers_model.php index d9c9bf4d..f00e1905 100644 --- a/application/models/Customers_model.php +++ b/application/models/Customers_model.php @@ -22,7 +22,7 @@ class Customers_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'id_roles' => 'integer', ]; @@ -30,7 +30,7 @@ class Customers_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'firstName' => 'first_name', 'lastName' => 'last_name', @@ -133,7 +133,7 @@ class Customers_model extends EA_Model { ->select() ->from('users') ->join('roles', 'roles.id = users.id_roles', 'inner') - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->where('roles.slug', DB_SLUG_CUSTOMER) ->where('users.email', $customer['email']) ->where('users.id !=', $customer_id) @@ -285,7 +285,7 @@ class Customers_model extends EA_Model { /** * Get all customers that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -293,7 +293,7 @@ class Customers_model extends EA_Model { * * @return array Returns an array of customers. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { $role_id = $this->get_customer_role_id(); @@ -361,7 +361,7 @@ class Customers_model extends EA_Model { ->from('users') ->join('roles', 'roles.id = users.id_roles', 'inner') ->where('users.email', $customer['email']) - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->where('roles.slug', DB_SLUG_CUSTOMER) ->get() ->num_rows(); @@ -391,7 +391,7 @@ class Customers_model extends EA_Model { ->from('users') ->join('roles', 'roles.id = users.id_roles', 'inner') ->where('users.email', $customer['email']) - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->where('roles.slug', DB_SLUG_CUSTOMER) ->get() ->row_array(); diff --git a/application/models/Providers_model.php b/application/models/Providers_model.php index 21442dc4..8d2c59b4 100755 --- a/application/models/Providers_model.php +++ b/application/models/Providers_model.php @@ -22,7 +22,7 @@ class Providers_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'is_private' => 'boolean', 'id_roles' => 'integer', @@ -31,7 +31,7 @@ class Providers_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'firstName' => 'first_name', 'lastName' => 'last_name', @@ -57,6 +57,7 @@ class Providers_model extends EA_Model { * @return int Returns the provider ID. * * @throws InvalidArgumentException + * @throws Exception */ public function save(array $provider): int { @@ -168,7 +169,7 @@ class Providers_model extends EA_Model { ->where('roles.slug', DB_SLUG_PROVIDER) ->where('users.email', $provider['email']) ->where('users.id !=', $provider_id) - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->get() ->num_rows(); @@ -209,7 +210,7 @@ class Providers_model extends EA_Model { * * @return int Returns the provider ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function insert(array $provider): int { @@ -248,7 +249,7 @@ class Providers_model extends EA_Model { * * @return int Returns the provider ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function update(array $provider): int { @@ -398,7 +399,7 @@ class Providers_model extends EA_Model { /** * Get all providers that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -406,7 +407,7 @@ class Providers_model extends EA_Model { * * @return array Returns an array of providers. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { $role_id = $this->get_provider_role_id(); @@ -519,9 +520,9 @@ class Providers_model extends EA_Model { * * @param int $provider_id Provider ID. * @param string $name Setting name. - * @param mixed $value Setting value. + * @param mixed|null $value Setting value. */ - public function set_setting(int $provider_id, string $name, $value = NULL) + public function set_setting(int $provider_id, string $name, mixed $value = NULL) { if ( ! $this->db->update('user_settings', [$name => $value], ['id_users' => $provider_id])) { @@ -579,6 +580,7 @@ class Providers_model extends EA_Model { * @param array $working_plan_exception Associative array with the working plan exception data. * * @throws InvalidArgumentException + * @throws Exception */ public function save_working_plan_exception(int $provider_id, string $date, array $working_plan_exception) { @@ -793,22 +795,18 @@ class Providers_model extends EA_Model { foreach ($resources as $resource) { - switch ($resource) + $provider['services'] = match ($resource) { - case 'services': - $provider['services'] = $this - ->db - ->select('services.*') - ->from('services') - ->join('services_providers', 'services_providers.id_services = services.id', 'inner') - ->where('id_users', $provider['id']) - ->get() - ->result_array(); - break; - - default: - throw new InvalidArgumentException('The requested provider relation is not supported: ' . $resource); - } + 'services' => $this + ->db + ->select('services.*') + ->from('services') + ->join('services_providers', 'services_providers.id_services = services.id', 'inner') + ->where('id_users', $provider['id']) + ->get() + ->result_array(), + default => throw new InvalidArgumentException('The requested provider relation is not supported: ' . $resource), + }; } } diff --git a/application/models/Roles_model.php b/application/models/Roles_model.php index 525fc4ad..405995f7 100644 --- a/application/models/Roles_model.php +++ b/application/models/Roles_model.php @@ -22,7 +22,7 @@ class Roles_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'is_admin' => 'boolean', 'appointments' => 'integer', @@ -223,7 +223,7 @@ class Roles_model extends EA_Model { /** * Get all roles that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -231,7 +231,7 @@ class Roles_model extends EA_Model { * * @return array Returns an array of roles. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Secretaries_model.php b/application/models/Secretaries_model.php index 5a562c2d..4c0ba22b 100644 --- a/application/models/Secretaries_model.php +++ b/application/models/Secretaries_model.php @@ -22,7 +22,7 @@ class Secretaries_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'id_roles' => 'integer', ]; @@ -30,7 +30,7 @@ class Secretaries_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'firstName' => 'first_name', 'lastName' => 'last_name', @@ -55,6 +55,7 @@ class Secretaries_model extends EA_Model { * @return int Returns the secretary ID. * * @throws InvalidArgumentException + * @throws Exception */ public function save(array $secretary): int { @@ -166,7 +167,7 @@ class Secretaries_model extends EA_Model { ->where('roles.slug', DB_SLUG_SECRETARY) ->where('users.email', $secretary['email']) ->where('users.id !=', $secretary_id) - ->where('users.delete_datetime', NULL) + ->where('users.delete_datetime') ->get() ->num_rows(); @@ -207,7 +208,7 @@ class Secretaries_model extends EA_Model { * * @return int Returns the secretary ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function insert(array $secretary): int { @@ -247,7 +248,7 @@ class Secretaries_model extends EA_Model { * * @return int Returns the secretary ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function update(array $secretary): int { @@ -393,7 +394,7 @@ class Secretaries_model extends EA_Model { /** * Get all secretaries that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -401,7 +402,7 @@ class Secretaries_model extends EA_Model { * * @return array Returns an array of secretaries. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { $role_id = $this->get_secretary_role_id(); @@ -496,9 +497,9 @@ class Secretaries_model extends EA_Model { * * @param int $secretary_id Secretary ID. * @param string $name Setting name. - * @param mixed $value Setting value. + * @param mixed|null $value Setting value. */ - public function set_setting(int $secretary_id, string $name, $value = NULL) + public function set_setting(int $secretary_id, string $name, mixed $value = NULL) { if ( ! $this->db->update('user_settings', [$name => $value], ['id_users' => $secretary_id])) { @@ -644,22 +645,18 @@ class Secretaries_model extends EA_Model { foreach ($resources as $resource) { - switch ($resource) + $secretary['providers'] = match ($resource) { - case 'providers': - $secretary['providers'] = $this - ->db - ->select('users.*') - ->from('users') - ->join('secretaries_providers', 'secretaries_providers.id_users_provider = users.id', 'inner') - ->where('id_users_secretary', $secretary['id']) - ->get() - ->result_array(); - break; - - default: - throw new InvalidArgumentException('The requested secretary relation is not supported: ' . $resource); - } + 'providers' => $this + ->db + ->select('users.*') + ->from('users') + ->join('secretaries_providers', 'secretaries_providers.id_users_provider = users.id', 'inner') + ->where('id_users_secretary', $secretary['id']) + ->get() + ->result_array(), + default => throw new InvalidArgumentException('The requested secretary relation is not supported: ' . $resource), + }; } } diff --git a/application/models/Services_model.php b/application/models/Services_model.php index a66851ae..a59c83fe 100644 --- a/application/models/Services_model.php +++ b/application/models/Services_model.php @@ -22,7 +22,7 @@ class Services_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'price' => 'float', 'attendants_number' => 'integer', @@ -33,7 +33,7 @@ class Services_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'name' => 'name', 'duration' => 'duration', @@ -281,7 +281,7 @@ class Services_model extends EA_Model { /** * Get all services that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -289,7 +289,7 @@ class Services_model extends EA_Model { * * @return array Returns an array of services. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { @@ -417,20 +417,16 @@ class Services_model extends EA_Model { foreach ($resources as $resource) { - switch ($resource) + $service['category'] = match ($resource) { - case 'category': - $service['category'] = $this - ->db - ->get_where('categories', [ - 'id' => $service['id_categories'] ?? $service['categoryId'] ?? NULL - ]) - ->row_array(); - break; - - default: - throw new InvalidArgumentException('The requested appointment relation is not supported: ' . $resource); - } + 'category' => $this + ->db + ->get_where('categories', [ + 'id' => $service['id_categories'] ?? $service['categoryId'] ?? NULL + ]) + ->row_array(), + default => throw new InvalidArgumentException('The requested appointment relation is not supported: ' . $resource), + }; } } diff --git a/application/models/Settings_model.php b/application/models/Settings_model.php index bf56ea73..3511481e 100644 --- a/application/models/Settings_model.php +++ b/application/models/Settings_model.php @@ -22,14 +22,14 @@ class Settings_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', ]; /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'name' => 'name', 'value' => 'value', ]; @@ -224,7 +224,7 @@ class Settings_model extends EA_Model { /** * Get all settings that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -232,7 +232,7 @@ class Settings_model extends EA_Model { * * @return array Returns an array of settings. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Unavailabilities_model.php b/application/models/Unavailabilities_model.php index aa139816..730967fc 100644 --- a/application/models/Unavailabilities_model.php +++ b/application/models/Unavailabilities_model.php @@ -20,7 +20,7 @@ class Unavailabilities_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'is_unavailability' => 'boolean', 'id_users_provider' => 'integer', @@ -31,7 +31,7 @@ class Unavailabilities_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'book' => 'book_datetime', 'start' => 'start_datetime', @@ -275,7 +275,7 @@ class Unavailabilities_model extends EA_Model { /** * Get all unavailabilities that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -283,7 +283,7 @@ class Unavailabilities_model extends EA_Model { * * @return array Returns an array of unavailabilities. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { @@ -386,20 +386,16 @@ class Unavailabilities_model extends EA_Model { foreach ($resources as $resource) { - switch ($resource) + $unavailability['provider'] = match ($resource) { - case 'provider': - $unavailability['provider'] = $this - ->db - ->get_where('users', [ - 'id' => $unavailability['id_users_provider'] ?? $unavailability['providerId'] ?? NULL - ]) - ->row_array(); - break; - - default: - throw new InvalidArgumentException('The requested unavailability relation is not supported: ' . $resource); - } + 'provider' => $this + ->db + ->get_where('users', [ + 'id' => $unavailability['id_users_provider'] ?? $unavailability['providerId'] ?? NULL + ]) + ->row_array(), + default => throw new InvalidArgumentException('The requested unavailability relation is not supported: ' . $resource), + }; } } diff --git a/application/models/Users_model.php b/application/models/Users_model.php index 7e3db0af..b2102f80 100644 --- a/application/models/Users_model.php +++ b/application/models/Users_model.php @@ -22,7 +22,7 @@ class Users_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'id_roles' => 'integer', ]; @@ -30,7 +30,7 @@ class Users_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'firstName' => 'first_name', 'lastName' => 'last_name', @@ -55,6 +55,7 @@ class Users_model extends EA_Model { * @return int Returns the user ID. * * @throws InvalidArgumentException + * @throws Exception */ public function save(array $user): int { @@ -109,7 +110,7 @@ class Users_model extends EA_Model { * * @return int Returns the user ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function insert(array $user): int { @@ -140,7 +141,7 @@ class Users_model extends EA_Model { * * @return int Returns the user ID. * - * @throws RuntimeException + * @throws RuntimeException|Exception */ protected function update(array $user): int { @@ -274,7 +275,7 @@ class Users_model extends EA_Model { /** * Get all users that match the provided criteria. * - * @param array|string $where Where conditions + * @param array|string|null $where Where conditions * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -282,7 +283,7 @@ class Users_model extends EA_Model { * * @return array Returns an array of users. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) { diff --git a/application/models/Webhooks_model.php b/application/models/Webhooks_model.php index 57dd9cb1..4dc30c03 100644 --- a/application/models/Webhooks_model.php +++ b/application/models/Webhooks_model.php @@ -22,7 +22,7 @@ class Webhooks_model extends EA_Model { /** * @var array */ - protected $casts = [ + protected array $casts = [ 'id' => 'integer', 'is_active' => 'boolean', 'is_ssl_verified' => 'boolean', @@ -31,7 +31,7 @@ class Webhooks_model extends EA_Model { /** * @var array */ - protected $api_resource = [ + protected array $api_resource = [ 'id' => 'id', 'name' => 'name', 'url' => 'url', @@ -222,7 +222,7 @@ class Webhooks_model extends EA_Model { /** * Get all webhooks that match the provided criteria. * - * @param array|string $where Where conditions. + * @param array|string|null $where Where conditions. * @param int|null $limit Record limit. * @param int|null $offset Record offset. * @param string|null $order_by Order by. @@ -230,7 +230,7 @@ class Webhooks_model extends EA_Model { * * @return array Returns an array of webhooks. */ - public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array + public function get(array|string $where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array { if ($where !== NULL) {