From 4a52c6666138720904e7057564347e150869c18b Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Thu, 9 May 2024 21:11:40 +0200 Subject: [PATCH] Types fixes --- galette/lib/Galette/Core/Preferences.php | 59 ++++++++++++++++++++- galette/lib/Galette/Entity/Adherent.php | 17 ++---- galette/lib/Galette/Entity/Contribution.php | 12 +++-- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/galette/lib/Galette/Core/Preferences.php b/galette/lib/Galette/Core/Preferences.php index 229ccb94a..9932a8148 100644 --- a/galette/lib/Galette/Core/Preferences.php +++ b/galette/lib/Galette/Core/Preferences.php @@ -52,7 +52,7 @@ * @property string $pref_pays Country * @property integer $pref_postal_address Postal address to use, one of self::POSTAL_ADDRESS* * @property integer $pref_postal_staff_member Staff member ID from which retrieve postal address - * @property boolean $pref_disable_members_socials + * @property boolean $pref_disable_members_socials Disable social networks for members * @property string $pref_lang Default instance language * @property integer $pref_numrows Default number of rows in lists * @property integer $pref_log History, one of self::LOG_* @@ -991,7 +991,58 @@ public function __get(string $name): mixed $forbidden = array('defaults'); $virtuals = array('vpref_email', 'vpref_email_newadh'); $types = [ - 'int' => ['pref_numrows'] + 'int' => [ + 'pref_card_address', + 'pref_card_hsize', + 'pref_card_hspace', + 'pref_card_marges_h', + 'pref_card_marges_v', + 'pref_card_vsize', + 'pref_card_vspace', + 'pref_default_paymenttype', + 'pref_etiq_marges_v', + 'pref_etiq_marges_h', + 'pref_etiq_hspace', + 'pref_etiq_vspace', + 'pref_etiq_hsize', + 'pref_etiq_vsize', + 'pref_etiq_cols', + 'pref_etiq_rows', + 'pref_etiq_corps', + 'pref_filter_account', + 'pref_log', + 'pref_mail_method', + 'pref_numrows', + 'pref_postal_address', + 'pref_postal_staff_member', + 'pref_password_length', + 'pref_password_strength', + 'pref_publicpages_visibility', + 'pref_redirect_on_create', + 'pref_statut' + ], + 'bool' => [ + 'pref_bool_create_member', + 'pref_bool_groupsmanagers_create_member', + 'pref_bool_groupsmanagers_edit_member', + 'pref_bool_groupsmanagers_edit_groups', + 'pref_bool_groupsmanagers_exports', + 'pref_bool_groupsmanagers_mailings', + 'pref_bool_mailadh', + 'pref_bool_mailowner', + 'pref_bool_publicpages', + 'pref_bool_selfsubscribe', + 'pref_bool_wrap_mails', + 'pref_disable_members_socials', + 'pref_editor_enabled', + 'pref_etiq_border', + 'pref_force_picture_ratio', + 'pref_mail_smtp_auth', + 'pref_mail_smtp_secure', + 'pref_mail_allow_unsecure', + 'pref_password_blacklist', + 'pref_show_id', + ] ]; if (!in_array($name, $forbidden) && isset($this->prefs[$name])) { @@ -1022,6 +1073,10 @@ public function __get(string $name): mixed $value = (int)$value; } + if (in_array($name, $types['bool'])) { + $value = (bool)$value; + } + return $value; } } elseif (in_array($name, $virtuals)) { diff --git a/galette/lib/Galette/Entity/Adherent.php b/galette/lib/Galette/Entity/Adherent.php index cdba9fb45..ea856fce2 100644 --- a/galette/lib/Galette/Entity/Adherent.php +++ b/galette/lib/Galette/Entity/Adherent.php @@ -515,15 +515,7 @@ public function loadSocials(): void private function getDefaultStatus(): int { global $preferences; - if ($preferences->pref_statut != '') { - return $preferences->pref_statut; - } else { - Analog::log( - 'Unable to get pref_statut; is it defined in preferences?', - Analog::ERROR - ); - return Status::DEFAULT_STATUS; - } + return $preferences->pref_statut; } /** @@ -1176,9 +1168,8 @@ public function check(array $values, array $required, array $disabled): bool|arr if (isset($values[$key])) { $value = $values[$key]; - if ($value !== true && $value !== false) { - //@phpstan-ignore-next-line - $value = trim($value ?? ''); + if (is_string($value)) { + $value = trim($value); } } elseif (empty($this->id)) { switch ($key) { @@ -1219,7 +1210,7 @@ public function check(array $values, array $required, array $disabled): bool|arr // if the field is enabled, check it if (!in_array($key, $disabled)) { // fill up the adherent structure - if ($value !== null && $value !== true && $value !== false && !is_object($value)) { + if (is_string($value)) { $value = stripslashes($value); } diff --git a/galette/lib/Galette/Entity/Contribution.php b/galette/lib/Galette/Entity/Contribution.php index 05871eac4..df56f3f06 100644 --- a/galette/lib/Galette/Entity/Contribution.php +++ b/galette/lib/Galette/Entity/Contribution.php @@ -430,14 +430,17 @@ public function check(array $values, array $required, array $disabled): bool|arr $prop = $this->fields[$key]['propname']; if (isset($values[$key])) { - $value = trim($values[$key]); + $value = $values[$key]; + if (is_string($value)) { + $value = trim($value); + } } else { - $value = ''; + $value = null; } // if the field is enabled, check it if (!isset($disabled[$key])) { - // fill up the adherent structure + // fill up the contribution structure //$this->$prop = stripslashes($value); //not relevant here! // now, check validity @@ -461,7 +464,8 @@ public function check(array $values, array $required, array $disabled): bool|arr } break; case 'montant_cotis': - $value = strtr($value, ',', '.'); + //FIXME: this is a hack to allow comma as decimal separator + $value = strtr((string)$value, ',', '.'); if (!empty($value) || $value === '0') { $this->amount = (double)$value; }