]> git.agnieray.net Git - galette.git/commitdiff
Drop old (and problematic!) underscore prefix
authorJohan Cwiklinski <johan@x-tnd.be>
Wed, 27 Mar 2024 18:34:56 +0000 (19:34 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Thu, 28 Mar 2024 06:34:10 +0000 (07:34 +0100)
14 files changed:
galette/lib/Galette/Core/Install.php
galette/lib/Galette/Core/Mailing.php
galette/lib/Galette/Core/Pagination.php
galette/lib/Galette/Core/PluginInstall.php
galette/lib/Galette/Entity/Adherent.php
galette/lib/Galette/Entity/Contribution.php
galette/lib/Galette/Entity/ImportModel.php
galette/lib/Galette/Entity/Transaction.php
galette/lib/Galette/Features/Dependencies.php
galette/lib/Galette/Features/Dynamics.php
galette/lib/Galette/Filters/AdvancedMembersList.php
galette/lib/Galette/Filters/MembersList.php
galette/lib/Galette/IO/CsvIn.php
tests/Galette/Repository/tests/units/Members.php

index 40fd81b1084ea216af8b9230004e89e72e50b173..a2fc6bc8fc1f7c5cae7d96fb8ec4938f32020946 100644 (file)
@@ -57,36 +57,36 @@ class Install
         '0.704' => '0.76'
     );
 
-    protected int $_step;
-    private ?string $_mode;
-    private ?string $_installed_version = null;
-
-    private string $_db_type;
-    private string $_db_host;
-    private string $_db_port;
-    private string $_db_name;
-    private string $_db_user;
-    private ?string $_db_pass;
-    private ?string $_db_prefix = null;
-
-    private bool $_db_connected;
+    protected int $step;
+    private ?string $mode;
+    private ?string $installed_version = null;
+
+    private string $db_type;
+    private string $db_host;
+    private string $db_port;
+    private string $db_name;
+    private string $db_user;
+    private ?string $db_pass;
+    private ?string $db_prefix = null;
+
+    private bool $db_connected;
     /** @var array<string, string> */
-    private array $_report;
+    private array $report;
 
-    private string $_admin_login;
-    private string $_admin_pass;
+    private string $admin_login;
+    private string $admin_pass;
 
-    private bool $_error;
+    private bool $error;
 
     /**
      * Main constructor
      */
     public function __construct()
     {
-        $this->_step = self::STEP_CHECK;
-        $this->_mode = null;
-        $this->_db_connected = false;
-        $this->_db_prefix = null;
+        $this->step = self::STEP_CHECK;
+        $this->mode = null;
+        $this->db_connected = false;
+        $this->db_prefix = null;
     }
 
     /**
@@ -97,7 +97,7 @@ class Install
     public function getStepTitle(): string
     {
         $step_title = null;
-        switch ($this->_step) {
+        switch ($this->step) {
             case self::STEP_CHECK:
                 $step_title = _T("Checks");
                 break;
@@ -153,11 +153,11 @@ class Install
     /**
      * Get current mode
      *
-     * @return string
+     * @return ?string
      */
     public function getMode(): ?string
     {
-        return $this->_mode;
+        return $this->mode;
     }
 
     /**
@@ -167,7 +167,7 @@ class Install
      */
     public function isInstall(): bool
     {
-        return $this->_mode === self::INSTALL;
+        return $this->mode === self::INSTALL;
     }
 
     /**
@@ -177,7 +177,7 @@ class Install
      */
     public function isUpgrade(): bool
     {
-        return $this->_mode === self::UPDATE;
+        return $this->mode === self::UPDATE;
     }
 
     /**
@@ -190,7 +190,7 @@ class Install
     public function setMode(string $mode): self
     {
         if ($mode === self::INSTALL || $mode === self::UPDATE) {
-            $this->_mode = $mode;
+            $this->mode = $mode;
         } else {
             throw new \UnexpectedValueException('Unknown mode "' . $mode . '"');
         }
@@ -205,22 +205,22 @@ class Install
      */
     public function atPreviousStep(): void
     {
-        if ($this->_step > 0) {
+        if ($this->step > 0) {
             if (
-                $this->_step - 1 !== self::STEP_DB_INSTALL
-                && $this->_step !== self::STEP_END
+                $this->step - 1 !== self::STEP_DB_INSTALL
+                && $this->step !== self::STEP_END
             ) {
-                if ($this->_step === self::STEP_DB_INSTALL) {
-                    $this->_step = self::STEP_DB_CHECKS;
+                if ($this->step === self::STEP_DB_INSTALL) {
+                    $this->step = self::STEP_DB_CHECKS;
                 } else {
-                    if ($this->_step === self::STEP_DB_UPGRADE) {
+                    if ($this->step === self::STEP_DB_UPGRADE) {
                         $this->setInstalledVersion(null);
                     }
-                    $this->_step = $this->_step - 1;
+                    $this->step = $this->step - 1;
                 }
             } else {
                 $msg = null;
-                if ($this->_step === self::STEP_END) {
+                if ($this->step === self::STEP_END) {
                     $msg = 'Ok man, install is finished already!';
                 } else {
                     $msg = 'It is forbidden to rerun database install!';
@@ -237,7 +237,7 @@ class Install
      */
     public function isCheckStep(): bool
     {
-        return $this->_step === self::STEP_CHECK;
+        return $this->step === self::STEP_CHECK;
     }
 
     /**
@@ -247,7 +247,7 @@ class Install
      */
     public function atTypeStep(): void
     {
-        $this->_step = self::STEP_TYPE;
+        $this->step = self::STEP_TYPE;
     }
 
     /**
@@ -257,7 +257,7 @@ class Install
      */
     public function isTypeStep(): bool
     {
-        return $this->_step === self::STEP_TYPE;
+        return $this->step === self::STEP_TYPE;
     }
 
     /**
@@ -267,7 +267,7 @@ class Install
      */
     public function atDbStep(): void
     {
-        $this->_step = self::STEP_DB;
+        $this->step = self::STEP_DB;
     }
 
     /**
@@ -277,7 +277,7 @@ class Install
      */
     public function isDbStep(): bool
     {
-        return $this->_step === self::STEP_DB;
+        return $this->step === self::STEP_DB;
     }
 
     /**
@@ -287,7 +287,7 @@ class Install
      */
     public function postCheckDb(): bool
     {
-        return $this->_step >= self::STEP_DB_CHECKS;
+        return $this->step >= self::STEP_DB_CHECKS;
     }
 
     /**
@@ -303,7 +303,7 @@ class Install
         switch ($type) {
             case Db::MYSQL:
             case Db::PGSQL:
-                $this->_db_type = $type;
+                $this->db_type = $type;
                 break;
             default:
                 $errs[] = _T("Database type unknown");
@@ -318,7 +318,7 @@ class Install
      */
     public function getDbType(): ?string
     {
-        return $this->_db_type ?? null;
+        return $this->db_type ?? null;
     }
 
     /**
@@ -334,11 +334,11 @@ class Install
      */
     public function setDsn(string $host, string $port, string $name, string $user, ?string $pass): void
     {
-        $this->_db_host = $host;
-        $this->_db_port = $port;
-        $this->_db_name = $name;
-        $this->_db_user = $user;
-        $this->_db_pass = $pass;
+        $this->db_host = $host;
+        $this->db_port = $port;
+        $this->db_name = $name;
+        $this->db_user = $user;
+        $this->db_pass = $pass;
     }
 
     /**
@@ -350,7 +350,7 @@ class Install
      */
     public function setTablesPrefix(string $prefix): self
     {
-        $this->_db_prefix = $prefix;
+        $this->db_prefix = $prefix;
         return $this;
     }
 
@@ -361,7 +361,7 @@ class Install
      */
     public function getDbHost(): ?string
     {
-        return $this->_db_host ?? null;
+        return $this->db_host ?? null;
     }
 
     /**
@@ -371,7 +371,7 @@ class Install
      */
     public function getDbPort(): ?string
     {
-        return $this->_db_port ?? null;
+        return $this->db_port ?? null;
     }
 
     /**
@@ -381,7 +381,7 @@ class Install
      */
     public function getDbName(): ?string
     {
-        return $this->_db_name ?? null;
+        return $this->db_name ?? null;
     }
 
     /**
@@ -391,7 +391,7 @@ class Install
      */
     public function getDbUser(): ?string
     {
-        return $this->_db_user ?? null;
+        return $this->db_user ?? null;
     }
 
     /**
@@ -401,7 +401,7 @@ class Install
      */
     public function getDbPass(): string
     {
-        return $this->_db_pass;
+        return $this->db_pass;
     }
 
     /**
@@ -411,7 +411,7 @@ class Install
      */
     public function getTablesPrefix(): ?string
     {
-        return $this->_db_prefix;
+        return $this->db_prefix;
     }
 
     /**
@@ -421,7 +421,7 @@ class Install
      */
     public function atDbCheckStep(): void
     {
-        $this->_step = self::STEP_DB_CHECKS;
+        $this->step = self::STEP_DB_CHECKS;
     }
 
     /**
@@ -431,7 +431,7 @@ class Install
      */
     public function isDbCheckStep(): bool
     {
-        return $this->_step === self::STEP_DB_CHECKS;
+        return $this->step === self::STEP_DB_CHECKS;
     }
 
     /**
@@ -444,12 +444,12 @@ class Install
     public function testDbConnexion(): bool
     {
         return Db::testConnectivity(
-            $this->_db_type,
-            $this->_db_user,
-            $this->_db_pass,
-            $this->_db_host,
-            $this->_db_port,
-            $this->_db_name
+            $this->db_type,
+            $this->db_user,
+            $this->db_pass,
+            $this->db_host,
+            $this->db_port,
+            $this->db_name
         );
     }
 
@@ -460,7 +460,7 @@ class Install
      */
     public function isDbConnected(): bool
     {
-        return $this->_db_connected;
+        return $this->db_connected;
     }
 
     /**
@@ -470,7 +470,7 @@ class Install
      */
     public function atVersionSelection(): void
     {
-        $this->_step = self::STEP_VERSION;
+        $this->step = self::STEP_VERSION;
     }
 
     /**
@@ -480,7 +480,7 @@ class Install
      */
     public function isVersionSelectionStep(): bool
     {
-        return $this->_step === self::STEP_VERSION;
+        return $this->step === self::STEP_VERSION;
     }
 
     /**
@@ -490,7 +490,7 @@ class Install
      */
     public function atDbInstallStep(): void
     {
-        $this->_step = self::STEP_DB_INSTALL;
+        $this->step = self::STEP_DB_INSTALL;
     }
 
     /**
@@ -500,7 +500,7 @@ class Install
      */
     public function isDbinstallStep(): bool
     {
-        return $this->_step === self::STEP_DB_INSTALL;
+        return $this->step === self::STEP_DB_INSTALL;
     }
 
     /**
@@ -510,7 +510,7 @@ class Install
      */
     public function atDbUpgradeStep(): void
     {
-        $this->_step = self::STEP_DB_UPGRADE;
+        $this->step = self::STEP_DB_UPGRADE;
     }
 
     /**
@@ -520,7 +520,7 @@ class Install
      */
     public function isDbUpgradeStep(): bool
     {
-        return $this->_step === self::STEP_DB_UPGRADE;
+        return $this->step === self::STEP_DB_UPGRADE;
     }
 
 
@@ -541,11 +541,11 @@ class Install
         if ($this->isUpgrade()) {
             $update_scripts = self::getUpdateScripts(
                 $path,
-                $this->_db_type,
-                $this->_installed_version
+                $this->db_type,
+                $this->installed_version
             );
         } else {
-            $update_scripts['current'] = $this->_db_type . '.sql';
+            $update_scripts['current'] = $this->db_type . '.sql';
         }
 
         return $update_scripts;
@@ -618,7 +618,7 @@ class Install
     {
         $fatal_error = false;
         $update_scripts = $this->getScripts($spath);
-        $this->_report = array();
+        $this->report = array();
         $scripts_path = ($spath ?? GALETTE_ROOT . '/install') . '/scripts/';
 
         foreach ($update_scripts as $key => $val) {
@@ -655,7 +655,7 @@ class Install
                     if ($updater instanceof \Galette\Updater\AbstractUpdater) {
                         $updater->run($zdb, $this);
                         $ret = $updater->getReport();
-                        $this->_report = array_merge($this->_report, $ret);
+                        $this->report = array_merge($this->report, $ret);
                     } else {
                         $fatal_error = true;
                         Analog::log(
@@ -670,7 +670,7 @@ class Install
                         _T("%version script has been successfully executed :)")
                     );
                     $ret['res'] = true;
-                    $this->_report[] = $ret;
+                    $this->report[] = $ret;
                 } catch (\RuntimeException $e) {
                     Analog::log(
                         $e->getMessage(),
@@ -682,7 +682,7 @@ class Install
                         _T("Unable to run %version update script :(")
                     );
                     $fatal_error = true;
-                    $this->_report[] = $ret;
+                    $this->report[] = $ret;
                 }
             }
 
@@ -712,7 +712,7 @@ class Install
         // load in the sql parser
         include_once GALETTE_ROOT . 'includes/sql_parse.php';
 
-        $sql_query = preg_replace('/galette_/', $this->_db_prefix, $sql_query);
+        $sql_query = preg_replace('/galette_/', $this->db_prefix, $sql_query);
         $sql_query = remove_remarks($sql_query);
 
         $sql_query = split_sql_file($sql_query, ';');
@@ -781,7 +781,7 @@ class Install
             }
         }
 
-        $this->_report = array_merge($this->_report, $queries_results);
+        $this->report = array_merge($this->report, $queries_results);
         return !$fatal_error;
     }
 
@@ -792,7 +792,7 @@ class Install
      */
     public function getDbInstallReport(): array
     {
-        return $this->_report;
+        return $this->report;
     }
 
     /**
@@ -802,7 +802,7 @@ class Install
      */
     public function reinitReport(): void
     {
-        $this->_report = array();
+        $this->report = array();
     }
 
     /**
@@ -812,7 +812,7 @@ class Install
      */
     public function atAdminStep(): void
     {
-        $this->_step = self::STEP_ADMIN;
+        $this->step = self::STEP_ADMIN;
     }
 
     /**
@@ -822,7 +822,7 @@ class Install
      */
     public function isAdminStep(): bool
     {
-        return $this->_step === self::STEP_ADMIN;
+        return $this->step === self::STEP_ADMIN;
     }
 
     /**
@@ -835,8 +835,8 @@ class Install
      */
     public function setAdminInfos(string $login, string $pass): void
     {
-        $this->_admin_login = $login;
-        $this->_admin_pass = password_hash($pass, PASSWORD_BCRYPT);
+        $this->admin_login = $login;
+        $this->admin_pass = password_hash($pass, PASSWORD_BCRYPT);
     }
 
     /**
@@ -846,7 +846,7 @@ class Install
      */
     public function getAdminLogin(): string
     {
-        return $this->_admin_login;
+        return $this->admin_login;
     }
 
     /**
@@ -856,7 +856,7 @@ class Install
      */
     public function getAdminPass(): string
     {
-        return $this->_admin_pass;
+        return $this->admin_pass;
     }
 
     /**
@@ -866,7 +866,7 @@ class Install
      */
     public function atTelemetryStep(): void
     {
-        $this->_step = self::STEP_TELEMETRY;
+        $this->step = self::STEP_TELEMETRY;
     }
 
     /**
@@ -876,7 +876,7 @@ class Install
      */
     public function isTelemetryStep(): bool
     {
-        return $this->_step === self::STEP_TELEMETRY;
+        return $this->step === self::STEP_TELEMETRY;
     }
 
     /**
@@ -886,7 +886,7 @@ class Install
      */
     public function atGaletteInitStep(): void
     {
-        $this->_step = self::STEP_GALETTE_INIT;
+        $this->step = self::STEP_GALETTE_INIT;
     }
 
     /**
@@ -896,7 +896,7 @@ class Install
      */
     public function isGaletteInitStep(): bool
     {
-        return $this->_step === self::STEP_GALETTE_INIT;
+        return $this->step === self::STEP_GALETTE_INIT;
     }
 
     /**
@@ -1057,26 +1057,26 @@ class Install
 
         if (
             isset($existing['db_type'])
-            && $existing['db_type'] == $this->_db_type
+            && $existing['db_type'] == $this->db_type
             && isset($existing['db_host'])
-            && $existing['db_host'] == $this->_db_host
+            && $existing['db_host'] == $this->db_host
             && isset($existing['db_port'])
-            && $existing['db_port'] == $this->_db_port
+            && $existing['db_port'] == $this->db_port
             && isset($existing['db_user'])
-            && $existing['db_user'] == $this->_db_user
+            && $existing['db_user'] == $this->db_user
             && isset($existing['pwd_db'])
-            && $existing['pwd_db'] == $this->_db_pass
+            && $existing['pwd_db'] == $this->db_pass
             && isset($existing['db_name'])
-            && $existing['db_name'] == $this->_db_name
+            && $existing['db_name'] == $this->db_name
             && isset($existing['prefix'])
-            && $existing['prefix'] == $this->_db_prefix
+            && $existing['prefix'] == $this->db_prefix
         ) {
             Analog::log(
                 'Config file is already up-to-date, nothing to do.',
                 Analog::INFO
             );
 
-            $this->_report[] = array(
+            $this->report[] = array(
                 'message'   => _T("Config file already exists and is up to date"),
                 'res'       => true
             );
@@ -1090,13 +1090,13 @@ class Install
             && $fd = @fopen($conffile, 'w')
         ) {
                 $data = "<?php
-define('TYPE_DB', '" . $this->_db_type . "');
-define('HOST_DB', '" . $this->_db_host . "');
-define('PORT_DB', '" . $this->_db_port . "');
-define('USER_DB', '" . $this->_db_user . "');
-define('PWD_DB', '" . $this->_db_pass . "');
-define('NAME_DB', '" . $this->_db_name . "');
-define('PREFIX_DB', '" . $this->_db_prefix . "');
+define('TYPE_DB', '" . $this->db_type . "');
+define('HOST_DB', '" . $this->db_host . "');
+define('PORT_DB', '" . $this->db_port . "');
+define('USER_DB', '" . $this->db_user . "');
+define('PWD_DB', '" . $this->db_pass . "');
+define('NAME_DB', '" . $this->db_name . "');
+define('PREFIX_DB', '" . $this->db_prefix . "');
 ";
             fwrite($fd, $data);
             fclose($fd);
@@ -1112,7 +1112,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
             $ret['error'] = $str;
             $error = true;
         }
-        $this->_report[] = $ret;
+        $this->report[] = $ret;
         return !$error;
     }
 
@@ -1151,7 +1151,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
 
             $models = new \Galette\Repository\PdfModels($zdb, $preferences, $login);
 
-            $this->_error = false;
+            $this->error = false;
 
             //Install preferences
             $res = $preferences->installInit(
@@ -1185,7 +1185,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
             $res = $models->installInit(false);
             $this->proceedReport(_T("PDF models"), $res);
 
-            return !$this->_error;
+            return !$this->error;
         } elseif ($this->isUpgrade()) {
             $preferences = new Preferences($zdb);
             $preferences->store();
@@ -1221,11 +1221,11 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
 
         if ($res instanceof \Exception) {
             $ret['debug'] = $res->getMessage();
-            $this->_error = true;
+            $this->error = true;
         } else {
             $ret['res'] = true;
         }
-        $this->_report[] = $ret;
+        $this->report[] = $ret;
     }
     /**
      * Retrieve galette initialization report
@@ -1234,7 +1234,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
      */
     public function getInitializationReport(): array
     {
-        return $this->_report;
+        return $this->report;
     }
 
     /**
@@ -1244,7 +1244,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
      */
     public function atEndStep(): void
     {
-        $this->_step = self::STEP_END;
+        $this->step = self::STEP_END;
     }
 
     /**
@@ -1254,7 +1254,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
      */
     public function isEndStep(): bool
     {
-        return $this->_step === self::STEP_END;
+        return $this->step === self::STEP_END;
     }
 
     /**
@@ -1266,7 +1266,7 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
      */
     public function setInstalledVersion(?string $version): void
     {
-        $this->_installed_version = $version;
+        $this->installed_version = $version;
     }
 
     /**
@@ -1299,6 +1299,6 @@ define('PREFIX_DB', '" . $this->_db_prefix . "');
      */
     public function isStepPassed($step): bool
     {
-        return $this->_step > $step;
+        return $this->step > $step;
     }
 }
index 5e8fedde8feb8f8fe5a1e7488fab04fcfdd5d4c6..0cc0dc5ed2890006133ffc88ca2fb0ec36160752 100644 (file)
@@ -41,7 +41,6 @@ use Laminas\Db\ResultSet\ResultSet;
  * @property-read string $alt_message
  * @property-read string $wrapped_message
  * @property-read PHPMailer\PHPMailer\PHPMailer $mail
- * @property-read PHPMailer\PHPMailer\PHPMailer $_mail
  * @property-read array $errors
  * @property-read array $recipients
  * @property-read array $unreachables
@@ -521,7 +520,6 @@ class Mailing extends GaletteMail
                 case 'html':
                     return $this->isHTML();
                 case 'mail':
-                case '_mail':
                     return $this->getPhpMailer();
                 case 'errors':
                     return $this->getErrors();
@@ -578,7 +576,6 @@ class Mailing extends GaletteMail
                 case 'wrapped_message':
                 case 'html':
                 case 'mail':
-                case '_mail':
                 case 'errors':
                 case 'recipients':
                 case 'tmp_path':
index d58c16efd3e4958b3848b3e22a7987e38b805a63..40bc8dac4e7a16e964bd97f8e8e3416d7e6498ed 100644 (file)
@@ -373,7 +373,7 @@ abstract class Pagination
         } else {
             Analog::log(
                 '[' . get_class($this) .
-                '|Pagination] Unable to get proprety `' . $name . '`',
+                '|Pagination] Unable to get property `' . $name . '`',
                 Analog::WARNING
             );
         }
@@ -461,7 +461,7 @@ abstract class Pagination
             default:
                 Analog::log(
                     '[' . get_class($this) .
-                    '|Pagination] Unable to set proprety `' . $name . '`',
+                    '|Pagination] Unable to set property `' . $name . '`',
                     Analog::WARNING
                 );
                 break;
index ecbfa86a79e0a3779ff3e7774a77da3f815627d0..3b2b2775a8c3029be770caa9eb088db7f717f5dd 100644 (file)
@@ -58,22 +58,22 @@ class PluginInstall extends Install
      */
     public function atPreviousStep(): void
     {
-        if ($this->_step > 0) {
+        if ($this->step > 0) {
             if (
-                $this->_step - 1 !== self::STEP_DB_INSTALL
-                && $this->_step !== self::STEP_END
+                $this->step - 1 !== self::STEP_DB_INSTALL
+                && $this->step !== self::STEP_END
             ) {
-                if ($this->_step === self::STEP_DB_INSTALL) {
-                    $this->_step = self::STEP_DB_CHECKS;
+                if ($this->step === self::STEP_DB_INSTALL) {
+                    $this->step = self::STEP_DB_CHECKS;
                 } else {
-                    if ($this->_step === self::STEP_DB_UPGRADE) {
+                    if ($this->step === self::STEP_DB_UPGRADE) {
                         $this->setInstalledVersion(null);
                     }
-                    $this->_step = $this->_step - 1;
+                    $this->step = $this->step - 1;
                 }
             } else {
                 $msg = null;
-                if ($this->_step === self::STEP_END) {
+                if ($this->step === self::STEP_END) {
                     $msg = 'Ok man, install is finished already!';
                 } else {
                     $msg = 'It is forbidden to rerun database install!';
index 5b0a5968be62b6b4bae9c2cbcf4797d8972cfbdd..b3c21bd6a18643e5b9d524e76126f2c903af721b 100644 (file)
@@ -46,15 +46,15 @@ use Galette\Features\Dynamics;
  *
  * @author Johan Cwiklinski <johan@x-tnd.be>
  *
- * @property integer $id
- * @property integer|Title $title Either a title id or an instance of Title
+ * @property ?integer $id
+ * @property integer|Title|null $title Either a title id or an instance of Title
  * @property string $stitle Title label
  * @property string $company_name
  * @property string $name
  * @property ?string $surname
  * @property string $nickname
- * @property string $birthdate Localized birthdate
- * @property string $rbirthdate Raw birthdate
+ * @property ?string $birthdate Localized birthdate
+ * @property ?string $rbirthdate Raw birthdate
  * @property string $birth_place
  * @property integer $gender
  * @property string $sgender Gender label
@@ -62,16 +62,16 @@ use Galette\Features\Dynamics;
  * @property string $language
  * @property integer $status
  * @property string $sstatus Status label
- * @property string $address
- * @property string $zipcode
- * @property string $town
+ * @property ?string $address
+ * @property ?string $zipcode
+ * @property ?string $town
  * @property ?string $country
  * @property string $phone
  * @property string $gsm
- * @property string $email
+ * @property ?string $email
  * @property string $gnupgid
  * @property string $fingerprint
- * @property string $login
+ * @property ?string $login
  * @property string $creation_date Localized creation date
  * @property string $modification_date Localized modification date
  * @property string $due_date Localized due date
@@ -80,7 +80,7 @@ use Galette\Features\Dynamics;
  * @property Picture $picture
  * @property array $groups
  * @property array $managed_groups
- * @property integer|Adherent $parent Parent id if parent dep is not loaded, Adherent instance otherwise
+ * @property integer|Adherent|null $parent Parent id if parent dep is not loaded, Adherent instance otherwise
  * @property array $children
  * @property boolean $admin better to rely on isAdmin()
  * @property boolean $staff better to rely on isStaff()
@@ -102,7 +102,7 @@ use Galette\Features\Dynamics;
  * @property Social $social Social networks/Contact
  * @property string $number Member number
  * @property-read bool $self_adh
- * @property string $region
+ * @property ?string $region
  */
 class Adherent
 {
@@ -124,68 +124,68 @@ class Adherent
     public const AFTER_ADD_LIST = 4;
     public const AFTER_ADD_HOME = 5;
 
-    private ?int $_id;
+    private ?int $id;
     //Identity
-    private Title|string|null $_title = null;
-    private ?string $_company_name;
-    private ?string $_name;
-    private ?string $_surname;
-    private ?string $_nickname;
-    private ?string $_birthdate;
-    private ?string $_birth_place;
-    private int $_gender;
-    private string $_job;
-    private string $_language;
-    private bool $_active;
-    private int $_status;
+    private Title|string|null $title = null;
+    private ?string $company_name;
+    private ?string $name;
+    private ?string $surname;
+    private ?string $nickname;
+    private ?string $birthdate;
+    private ?string $birth_place;
+    private int $gender;
+    private string $job;
+    private string $language;
+    private bool $active;
+    private int $status;
     //Contact information
-    private ?string $_address = null;
-    private ?string $_zipcode = null;
-    private ?string $_town = null;
-    private ?string $_country = null;
-    private ?string $_phone;
-    private ?string $_gsm;
-    private ?string $_email;
-    private ?string $_gnupgid;
-    private ?string $_fingerprint;
+    private ?string $address = null;
+    private ?string $zipcode = null;
+    private ?string $town = null;
+    private ?string $country = null;
+    private ?string $phone;
+    private ?string $gsm;
+    private ?string $email;
+    private ?string $gnupgid;
+    private ?string $fingerprint;
     //Galette relative information
-    private bool $_appears_in_list;
-    private bool $_admin;
-    private bool $_staff = false;
-    private bool $_due_free;
-    private ?string $_login;
-    private ?string $_password;
-    private string $_creation_date;
-    private string $_modification_date;
-    private ?string $_due_date;
-    private string $_others_infos;
-    private ?string $_others_infos_admin;
-    private ?Picture $_picture = null;
-    private int $_oldness;
-    private ?int $_days_remaining = null;
+    private bool $appears_in_list;
+    private bool $admin;
+    private bool $staff = false;
+    private bool $due_free;
+    private ?string $login;
+    private ?string $password;
+    private string $creation_date;
+    private string $modification_date;
+    private ?string $due_date;
+    private string $others_infos;
+    private ?string $others_infos_admin;
+    private ?Picture $picture = null;
+    private int $oldness;
+    private ?int $days_remaining = null;
     /** @var array<int, Group> */
-    private array $_groups = [];
+    private array $groups = [];
     /** @var array<int, Group> */
-    private array $_managed_groups = [];
-    private int|Adherent|null $_parent;
+    private array $managed_groups = [];
+    private int|Adherent|null $parent;
     /** @var array<int, Adherent>|null */
-    private ?array $_children = [];
-    private bool $_duplicate = false;
+    private ?array $children = [];
+    private bool $duplicate = false;
     /** @var array<int,Social> */
-    private array $_socials;
-    private ?string $_number = null;
-    private ?string $_region = null;
+    private array $socials;
+    private ?string $number = null;
+    private ?string $region = null;
 
-    private string $_row_classes;
+    private string $row_classes;
 
-    private bool $_self_adh = false;
+    private bool $self_adh = false;
 
     private Db $zdb;
     private Preferences $preferences;
     /** @var array<string, mixed> */
     private array $fields;
     private History $history;
-    private int $_due_status = Contribution::STATUS_UNKNOWN;
+    private int $due_status = Contribution::STATUS_UNKNOWN;
 
     /** @var array<string> */
     private array $parent_fields = [
@@ -240,22 +240,22 @@ class Adherent
             if (is_int($args) && $args > 0) {
                 $this->load($args);
             } else {
-                $this->_active = true;
-                $this->_language = $i18n->getID();
-                $this->_creation_date = date("Y-m-d");
-                $this->_status = $this->getDefaultStatus();
-                $this->_title = null;
-                $this->_gender = self::NC;
+                $this->active = true;
+                $this->language = $i18n->getID();
+                $this->creation_date = date("Y-m-d");
+                $this->status = $this->getDefaultStatus();
+                $this->title = null;
+                $this->gender = self::NC;
                 $gp = new Password($this->zdb);
-                $this->_password = $gp->makeRandomPassword();
-                $this->_picture = new Picture();
-                $this->_admin = false;
-                $this->_staff = false;
-                $this->_due_free = false;
-                $this->_appears_in_list = false;
-                $this->_parent = null;
-
-                if ($this->_deps['dynamics'] === true) {
+                $this->password = $gp->makeRandomPassword();
+                $this->picture = new Picture();
+                $this->admin = false;
+                $this->staff = false;
+                $this->due_free = false;
+                $this->appears_in_list = false;
+                $this->parent = null;
+
+                if ($this->deps['dynamics'] === true) {
                     $this->loadDynamicFields();
                 }
             }
@@ -348,87 +348,87 @@ class Adherent
      */
     private function loadFromRS(ArrayObject $r): void
     {
-        $this->_self_adh = false;
-        $this->_id = $r->id_adh;
+        $this->self_adh = false;
+        $this->id = $r->id_adh;
         //Identity
         if ($r->titre_adh !== null) {
-            $this->_title = new Title((int)$r->titre_adh);
+            $this->title = new Title((int)$r->titre_adh);
         }
-        $this->_company_name = $r->societe_adh;
-        $this->_name = $r->nom_adh;
-        $this->_surname = $r->prenom_adh;
-        $this->_nickname = $r->pseudo_adh;
+        $this->company_name = $r->societe_adh;
+        $this->name = $r->nom_adh;
+        $this->surname = $r->prenom_adh;
+        $this->nickname = $r->pseudo_adh;
         if ($r->ddn_adh != '1901-01-01') {
-            $this->_birthdate = $r->ddn_adh;
-        }
-        $this->_birth_place = $r->lieu_naissance;
-        $this->_gender = (int)$r->sexe_adh;
-        $this->_job = $r->prof_adh;
-        $this->_language = $r->pref_lang;
-        $this->_active = $r->activite_adh == 1;
-        $this->_status = (int)$r->id_statut;
+            $this->birthdate = $r->ddn_adh;
+        }
+        $this->birth_place = $r->lieu_naissance;
+        $this->gender = (int)$r->sexe_adh;
+        $this->job = $r->prof_adh;
+        $this->language = $r->pref_lang;
+        $this->active = $r->activite_adh == 1;
+        $this->status = (int)$r->id_statut;
         //Contact information
-        $this->_address = $r->adresse_adh;
-        $this->_zipcode = $r->cp_adh;
-        $this->_town = $r->ville_adh;
-        $this->_region = $r->region_adh;
-        $this->_country = $r->pays_adh;
-        $this->_phone = $r->tel_adh;
-        $this->_gsm = $r->gsm_adh;
-        $this->_email = $r->email_adh;
-        $this->_gnupgid = $r->gpgid;
-        $this->_fingerprint = $r->fingerprint;
+        $this->address = $r->adresse_adh;
+        $this->zipcode = $r->cp_adh;
+        $this->town = $r->ville_adh;
+        $this->region = $r->region_adh;
+        $this->country = $r->pays_adh;
+        $this->phone = $r->tel_adh;
+        $this->gsm = $r->gsm_adh;
+        $this->email = $r->email_adh;
+        $this->gnupgid = $r->gpgid;
+        $this->fingerprint = $r->fingerprint;
         //Galette relative information
-        $this->_appears_in_list = $r->bool_display_info == 1;
-        $this->_admin = $r->bool_admin_adh == 1;
+        $this->appears_in_list = $r->bool_display_info == 1;
+        $this->admin = $r->bool_admin_adh == 1;
         if (
             isset($r->priorite_statut)
             && $r->priorite_statut < Members::NON_STAFF_MEMBERS
         ) {
-            $this->_staff = true;
+            $this->staff = true;
         }
-        $this->_due_free = $r->bool_exempt_adh == 1;
-        $this->_login = $r->login_adh;
-        $this->_password = $r->mdp_adh;
-        $this->_creation_date = $r->date_crea_adh;
+        $this->due_free = $r->bool_exempt_adh == 1;
+        $this->login = $r->login_adh;
+        $this->password = $r->mdp_adh;
+        $this->creation_date = $r->date_crea_adh;
         if ($r->date_modif_adh != '1901-01-01') {
-            $this->_modification_date = $r->date_modif_adh;
+            $this->modification_date = $r->date_modif_adh;
         } else {
-            $this->_modification_date = $this->_creation_date;
+            $this->modification_date = $this->creation_date;
         }
-        $this->_due_date = $r->date_echeance;
-        $this->_others_infos = $r->info_public_adh;
-        $this->_others_infos_admin = $r->info_adh;
-        $this->_number = $r->num_adh;
+        $this->due_date = $r->date_echeance;
+        $this->others_infos = $r->info_public_adh;
+        $this->others_infos_admin = $r->info_adh;
+        $this->number = $r->num_adh;
 
         if ($r->parent_id !== null) {
-            $this->_parent = (int)$r->parent_id;
-            if ($this->_deps['parent'] === true) {
+            $this->parent = (int)$r->parent_id;
+            if ($this->deps['parent'] === true) {
                 $this->loadParent();
             }
         }
 
-        if ($this->_deps['children'] === true) {
+        if ($this->deps['children'] === true) {
             $this->loadChildren();
         }
 
-        if ($this->_deps['picture'] === true) {
-            $this->_picture = new Picture($this->_id);
+        if ($this->deps['picture'] === true) {
+            $this->picture = new Picture($this->id);
         }
 
-        if ($this->_deps['groups'] === true) {
+        if ($this->deps['groups'] === true) {
             $this->loadGroups();
         }
 
-        if ($this->_deps['dues'] === true) {
+        if ($this->deps['dues'] === true) {
             $this->checkDues();
         }
 
-        if ($this->_deps['dynamics'] === true) {
+        if ($this->deps['dynamics'] === true) {
             $this->loadDynamicFields();
         }
 
-        if ($this->_deps['socials'] === true) {
+        if ($this->deps['socials'] === true) {
             $this->loadSocials();
         }
     }
@@ -440,9 +440,9 @@ class Adherent
      */
     private function loadParent(): void
     {
-        if (isset($this->_parent) && !$this->_parent instanceof Adherent) {
-            $deps = array_fill_keys(array_keys($this->_deps), false);
-            $this->_parent = new Adherent($this->zdb, (int)$this->_parent, $deps);
+        if (isset($this->parent) && !$this->parent instanceof Adherent) {
+            $deps = array_fill_keys(array_keys($this->deps), false);
+            $this->parent = new Adherent($this->zdb, (int)$this->parent, $deps);
         }
     }
 
@@ -453,27 +453,27 @@ class Adherent
      */
     private function loadChildren(): void
     {
-        $this->_children = array();
+        $this->children = array();
         try {
             $id = self::PK;
             $select = $this->zdb->select(self::TABLE);
             $select->columns(
                 array($id)
-            )->where(['parent_id' => $this->_id]);
+            )->where(['parent_id' => $this->id]);
 
             $results = $this->zdb->execute($select);
 
             if ($results->count() > 0) {
                 foreach ($results as $row) {
-                    $deps = $this->_deps;
+                    $deps = $this->deps;
                     $deps['children'] = false;
                     $deps['parent'] = false;
-                    $this->_children[] = new Adherent($this->zdb, (int)$row->$id, $deps);
+                    $this->children[] = new Adherent($this->zdb, (int)$row->$id, $deps);
                 }
             }
         } catch (Throwable $e) {
             Analog::log(
-                'Cannot load children for member #' . $this->_id . ' | ' .
+                'Cannot load children for member #' . $this->id . ' | ' .
                 $e->getMessage(),
                 Analog::WARNING
             );
@@ -488,8 +488,8 @@ class Adherent
      */
     public function loadGroups(): void
     {
-        $this->_groups = Groups::loadGroups($this->_id);
-        $this->_managed_groups = Groups::loadManagedGroups($this->_id);
+        $this->groups = Groups::loadGroups($this->id);
+        $this->managed_groups = Groups::loadManagedGroups($this->id);
     }
 
     /**
@@ -499,7 +499,7 @@ class Adherent
      */
     public function loadSocials(): void
     {
-        $this->_socials = Social::getListForMember($this->_id);
+        $this->socials = Social::getListForMember($this->id);
     }
 
     /**
@@ -531,50 +531,50 @@ class Adherent
     {
         //how many days since our beloved member has been created
         $now = new DateTime();
-        $this->_oldness = $now->diff(
-            new DateTime($this->_creation_date)
+        $this->oldness = $now->diff(
+            new DateTime($this->creation_date)
         )->days;
 
-        $this->_row_classes = '';
+        $this->row_classes = '';
         if ($this->isDueFree()) {
             //no fee required, we don't care about dates
-            $this->_row_classes .= ' cotis-exempt';
-            $this->_due_status = Contribution::STATUS_DUEFREE;
+            $this->row_classes .= ' cotis-exempt';
+            $this->due_status = Contribution::STATUS_DUEFREE;
         } else {
             //ok, fee is required. Let's check the dates
-            if ($this->_due_date == '') {
-                $this->_row_classes .= ' cotis-never';
-                $this->_due_status = Contribution::STATUS_NEVER;
+            if ($this->due_date == '') {
+                $this->row_classes .= ' cotis-never';
+                $this->due_status = Contribution::STATUS_NEVER;
             } else {
                 // To count the days remaining, the next begin date is required.
-                $due_date = new DateTime($this->_due_date);
+                $due_date = new DateTime($this->due_date);
                 $next_begin_date = clone $due_date;
                 $next_begin_date->add(new \DateInterval('P1D'));
                 $date_diff = $now->diff($next_begin_date);
-                $this->_days_remaining = $date_diff->days;
+                $this->days_remaining = $date_diff->days;
                 // Active
                 if ($date_diff->invert == 0 && $date_diff->days >= 0) {
-                    $this->_days_remaining = $date_diff->days;
-                    if ($this->_days_remaining <= 30) {
+                    $this->days_remaining = $date_diff->days;
+                    if ($this->days_remaining <= 30) {
                         if ($date_diff->days == 0) {
-                            $this->_row_classes .= ' cotis-lastday';
+                            $this->row_classes .= ' cotis-lastday';
                         }
-                        $this->_row_classes .= ' cotis-soon';
-                        $this->_due_status = Contribution::STATUS_IMPENDING;
+                        $this->row_classes .= ' cotis-soon';
+                        $this->due_status = Contribution::STATUS_IMPENDING;
                     } else {
-                        $this->_row_classes .= ' cotis-ok';
-                        $this->_due_status = Contribution::STATUS_UPTODATE;
+                        $this->row_classes .= ' cotis-ok';
+                        $this->due_status = Contribution::STATUS_UPTODATE;
                     }
                 // Expired
                 } elseif ($date_diff->invert == 1 && $date_diff->days >= 0) {
-                    $this->_days_remaining = $date_diff->days;
+                    $this->days_remaining = $date_diff->days;
                     //check if member is still active
                     if ($this->isActive()) {
-                        $this->_row_classes .= ' cotis-late';
-                        $this->_due_status = Contribution::STATUS_LATE;
+                        $this->row_classes .= ' cotis-late';
+                        $this->due_status = Contribution::STATUS_LATE;
                     } else {
-                        $this->_row_classes .= ' cotis-old';
-                        $this->_due_status = Contribution::STATUS_OLD;
+                        $this->row_classes .= ' cotis-old';
+                        $this->due_status = Contribution::STATUS_OLD;
                     }
                 }
             }
@@ -582,12 +582,12 @@ class Adherent
 
         if (!$this->isActive()) {
             //anyway, if a member is no longer active, its due status is old.
-            $this->_due_status = Contribution::STATUS_OLD;
+            $this->due_status = Contribution::STATUS_OLD;
         }
 
-        if ($this->_due_status === Contribution::STATUS_UNKNOWN) {
+        if ($this->due_status === Contribution::STATUS_UNKNOWN) {
             throw new \RuntimeException(
-                'Unable to determine due status for member #' . $this->_id
+                'Unable to determine due status for member #' . $this->id
             );
         }
     }
@@ -599,7 +599,7 @@ class Adherent
      */
     public function isAdmin(): bool
     {
-        return $this->_admin;
+        return $this->admin;
     }
 
     /**
@@ -609,7 +609,7 @@ class Adherent
      */
     public function isStaff(): bool
     {
-        return $this->_staff;
+        return $this->staff;
     }
 
     /**
@@ -619,7 +619,7 @@ class Adherent
      */
     public function isDueFree(): bool
     {
-        return $this->_due_free;
+        return $this->due_free;
     }
 
     /**
@@ -635,7 +635,7 @@ class Adherent
             $this->loadGroups();
         }
 
-        foreach ($this->_groups as $g) {
+        foreach ($this->groups as $g) {
             if ($g->getName() == $group_name) {
                 return true;
             }
@@ -657,7 +657,7 @@ class Adherent
         }
 
         if ($group_name !== null) {
-            foreach ($this->_managed_groups as $mg) {
+            foreach ($this->managed_groups as $mg) {
                 if ($mg->getName() == $group_name) {
                     return true;
                 }
@@ -679,7 +679,7 @@ class Adherent
      */
     public function isCompany(): bool
     {
-        return trim($this->_company_name ?? '') != '';
+        return trim($this->company_name ?? '') != '';
     }
 
     /**
@@ -689,7 +689,7 @@ class Adherent
      */
     public function isMan(): bool
     {
-        return $this->_gender === self::MAN;
+        return $this->gender === self::MAN;
     }
 
     /**
@@ -699,7 +699,7 @@ class Adherent
      */
     public function isWoman(): bool
     {
-        return $this->_gender === self::WOMAN;
+        return $this->gender === self::WOMAN;
     }
 
 
@@ -710,7 +710,7 @@ class Adherent
      */
     public function appearsInMembersList(): bool
     {
-        return $this->_appears_in_list;
+        return $this->appears_in_list;
     }
 
     /**
@@ -720,7 +720,7 @@ class Adherent
      */
     public function isActive(): bool
     {
-        return $this->_active;
+        return $this->active;
     }
 
     /**
@@ -730,7 +730,7 @@ class Adherent
      */
     public function hasPicture(): bool
     {
-        return $this->_picture->hasPicture();
+        return $this->picture->hasPicture();
     }
 
     /**
@@ -740,7 +740,7 @@ class Adherent
      */
     public function hasParent(): bool
     {
-        return !empty($this->_parent);
+        return !empty($this->parent);
     }
 
     /**
@@ -750,7 +750,7 @@ class Adherent
      */
     public function hasChildren(): bool
     {
-        if (!isset($this->children) || $this->_children === null) {
+        if (!isset($this->children) || $this->children === null) {
             if ($this->id) {
                 Analog::log(
                     'Children has not been loaded!',
@@ -759,7 +759,7 @@ class Adherent
             }
             return false;
         } else {
-            return count($this->_children) > 0;
+            return count($this->children) > 0;
         }
     }
 
@@ -774,7 +774,7 @@ class Adherent
     {
         $strclass = ($this->isActive()) ? 'active-account' : 'inactive-account';
         if ($public === false) {
-            $strclass .= $this->_row_classes ?? '';
+            $strclass .= $this->row_classes ?? '';
         }
         return $strclass;
     }
@@ -790,25 +790,25 @@ class Adherent
         $never_contributed = false;
         $now = new DateTime();
         // To count the days remaining, the next begin date is required.
-        if (!isset($this->_due_date)) {
-            $this->_due_date = $now->format('Y-m-d');
+        if (!isset($this->due_date)) {
+            $this->due_date = $now->format('Y-m-d');
             $never_contributed = true;
         }
-        $due_date = new DateTime($this->_due_date);
+        $due_date = new DateTime($this->due_date);
         $next_begin_date = clone $due_date;
         $next_begin_date->add(new \DateInterval('P1D'));
         $date_diff = $now->diff($next_begin_date);
         if ($this->isDueFree()) {
             $ret = _T("Freed of dues");
         } elseif ($never_contributed === true) {
-            if ($this->_active) {
+            if ($this->active) {
                 $patterns = array('/%days/', '/%date/');
-                $cdate = new DateTime($this->_creation_date);
-                if (!isset($this->_oldness)) {
+                $cdate = new DateTime($this->creation_date);
+                if (!isset($this->oldness)) {
                     $this->checkDues();
                 }
                 $replace = array(
-                    $this->_oldness,
+                    $this->oldness,
                     $cdate->format(__("Y-m-d"))
                 );
 
@@ -821,17 +821,17 @@ class Adherent
                 $ret = _T("Never contributed");
             }
         // Last active or first expired day
-        } elseif ($this->_days_remaining === 0) {
+        } elseif ($this->days_remaining === 0) {
             if ($date_diff->invert == 0) {
                 $ret = _T("Last day!");
             } else {
                 $ret = _T("Late since today!");
             }
         // Active
-        } elseif ($date_diff->invert == 0 && $this->_days_remaining > 0) {
+        } elseif ($date_diff->invert == 0 && $this->days_remaining > 0) {
             $patterns = array('/%days/', '/%date/');
             $replace = array(
-                $this->_days_remaining,
+                $this->days_remaining,
                 $due_date->format(__("Y-m-d"))
             );
             $ret = preg_replace(
@@ -840,14 +840,14 @@ class Adherent
                 _T("%days days remaining (ending on %date)")
             );
         // Expired
-        } elseif ($date_diff->invert == 1 && $this->_days_remaining > 0) {
+        } elseif ($date_diff->invert == 1 && $this->days_remaining > 0) {
             $patterns = array('/%days/', '/%date/');
             $replace = array(
                 // We need the number of days expired, not the number of days remaining.
-                $this->_days_remaining + 1,
+                $this->days_remaining + 1,
                 $due_date->format(__("Y-m-d"))
             );
-            if ($this->_active) {
+            if ($this->active) {
                 $ret = preg_replace(
                     $patterns,
                     $replace,
@@ -1015,7 +1015,7 @@ class Adherent
      */
     public function setSelfMembership(): void
     {
-        $this->_self_adh = true;
+        $this->self_adh = true;
     }
 
     /**
@@ -1034,10 +1034,10 @@ class Adherent
             return true;
         } else {
             //let's check from due date, if present
-            if (!isset($this->_due_date)) {
+            if (!isset($this->due_date)) {
                 return false;
             } else {
-                $due_date = new DateTime($this->_due_date);
+                $due_date = new DateTime($this->due_date);
                 $now = new DateTime();
                 $now->setTime(0, 0, 0);
                 return $due_date >= $now;
@@ -1098,7 +1098,7 @@ class Adherent
         //no parent if checkbox was unchecked
         if (
             !isset($values['attach'])
-            && !empty($this->_id)
+            && !empty($this->id)
             && isset($values['parent_id'])
         ) {
             unset($values['parent_id']);
@@ -1106,13 +1106,13 @@ class Adherent
 
         if (isset($values['duplicate'])) {
             //if we're duplicating, keep a trace (if an error occurs)
-            $this->_duplicate = true;
+            $this->duplicate = true;
         }
 
         foreach ($fields as $key) {
             //first, let's sanitize values
             $key = strtolower($key);
-            $prop = '_' . $this->fields[$key]['propname'];
+            $prop = $this->fields[$key]['propname'];
 
             if (isset($values[$key])) {
                 $value = $values[$key];
@@ -1120,7 +1120,7 @@ class Adherent
                     //@phpstan-ignore-next-line
                     $value = trim($value ?? '');
                 }
-            } elseif (empty($this->_id)) {
+            } elseif (empty($this->id)) {
                 switch ($key) {
                     case 'bool_admin_adh':
                     case 'bool_exempt_adh':
@@ -1149,7 +1149,7 @@ class Adherent
                 }
             } else {
                 //keep stored value on update
-                if ($prop != '_password' || isset($values['mdp_adh']) && isset($values['mdp_adh2'])) {
+                if ($prop != 'password' || isset($values['mdp_adh']) && isset($values['mdp_adh2'])) {
                     $value = $this->$prop;
                 } else {
                     $value = null;
@@ -1169,7 +1169,7 @@ class Adherent
                     if ($key !== 'mdp_adh') {
                         $this->validate($key, $value, $values);
                     }
-                } elseif (empty($this->_id)) {
+                } elseif (empty($this->id)) {
                     //ensure login and password are not empty
                     if (($key == 'login_adh' || $key == 'mdp_adh') && !isset($required[$key])) {
                         $p = new Password($this->zdb);
@@ -1192,7 +1192,7 @@ class Adherent
 
         // missing required fields?
         foreach ($required as $key => $val) {
-            $prop = '_' . $this->fields[$key]['propname'];
+            $prop = $this->fields[$key]['propname'];
 
             if (!isset($disabled[$key])) {
                 $mandatory_missing = false;
@@ -1214,7 +1214,7 @@ class Adherent
 
         //attach to/detach from parent
         if (isset($values['detach_parent'])) {
-            $this->_parent = null;
+            $this->parent = null;
         }
 
         if ($login->isGroupManager() && !$login->isAdmin() && !$login->isStaff() && $this->parent_id !== $login->id) {
@@ -1269,7 +1269,7 @@ class Adherent
     {
         global $preferences;
 
-        $prop = '_' . $this->fields[$field]['propname'];
+        $prop = $this->fields[$field]['propname'];
 
         if ($value === null || (is_string($value) && trim($value) == '')) {
             //empty values are OK
@@ -1351,10 +1351,10 @@ class Adherent
                     $select->columns(
                         array(self::PK)
                     )->where(array('email_adh' => $value));
-                    if (!empty($this->_id)) {
+                    if (!empty($this->id)) {
                         $select->where->notEqualTo(
                             self::PK,
-                            $this->_id
+                            $this->id
                         );
                     }
 
@@ -1389,10 +1389,10 @@ class Adherent
                             $select->columns(
                                 array(self::PK)
                             )->where(array('login_adh' => $value));
-                            if (!empty($this->_id)) {
+                            if (!empty($this->id)) {
                                 $select->where->notEqualTo(
                                     self::PK,
-                                    $this->_id
+                                    $this->id
                                 );
                             }
 
@@ -1415,13 +1415,13 @@ class Adherent
                 break;
             case 'mdp_adh':
                 if (
-                    $this->_self_adh !== true
+                    $this->self_adh !== true
                     && (!isset($values['mdp_adh2'])
                     || $values['mdp_adh2'] != $value)
                 ) {
                     $this->errors[] = _T("- The passwords don't match!");
                 } elseif (
-                    $this->_self_adh === true
+                    $this->self_adh === true
                     && !crypt($value, $values['mdp_crypt']) == $values['mdp_crypt']
                 ) {
                     $this->errors[] = _T("Password misrepeated: ");
@@ -1502,7 +1502,7 @@ class Adherent
 
         if (!$login->isAdmin() && !$login->isStaff() && !$login->isGroupManager() && $this->id == '') {
             if ($this->preferences->pref_bool_create_member) {
-                $this->_parent = $login->id;
+                $this->parent = $login->id;
             }
         }
 
@@ -1513,9 +1513,9 @@ class Adherent
             foreach ($fields as $field) {
                 if (
                     $field !== 'date_modif_adh'
-                    || empty($this->_id)
+                    || empty($this->id)
                 ) {
-                    $prop = '_' . $this->fields[$field]['propname'];
+                    $prop = $this->fields[$field]['propname'];
                     if (
                         ($field === 'bool_admin_adh'
                         || $field === 'bool_exempt_adh'
@@ -1527,12 +1527,12 @@ class Adherent
                         $values[$field] = $this->zdb->isPostgres() ? 'false' : 0;
                     } elseif ($field === 'parent_id') {
                         //handle parents
-                        if (!isset($this->_parent)) {
+                        if (!isset($this->parent)) {
                             $values['parent_id'] = new Expression('NULL');
                         } elseif ($this->parent instanceof Adherent) {
-                            $values['parent_id'] = $this->_parent->id;
+                            $values['parent_id'] = $this->parent->id;
                         } else {
-                            $values['parent_id'] = $this->_parent;
+                            $values['parent_id'] = $this->parent;
                         }
                     } else {
                         $values[$field] = $this->$prop;
@@ -1542,35 +1542,35 @@ class Adherent
 
             //an empty value will cause date to be set to 1901-01-01, a null
             //will result in 0000-00-00. We want a database NULL value here.
-            if (!$this->_birthdate) {
+            if (!$this->birthdate) {
                 $values['ddn_adh'] = new Expression('NULL');
             }
-            if (!$this->_due_date) {
+            if (!$this->due_date) {
                 $values['date_echeance'] = new Expression('NULL');
             }
 
-            if ($this->_title instanceof Title) {
-                $values['titre_adh'] = $this->_title->id;
+            if ($this->title instanceof Title) {
+                $values['titre_adh'] = $this->title->id;
             } else {
                 $values['titre_adh'] = new Expression('NULL');
             }
 
-            if (!$this->_parent) {
+            if (!$this->parent) {
                 $values['parent_id'] = new Expression('NULL');
             }
 
-            if (!$this->_number) {
+            if (!$this->number) {
                 $values['num_adh'] = new Expression('NULL');
             }
 
             //fields that cannot be null
             $notnull = [
-                '_surname'  => 'prenom_adh',
-                '_nickname' => 'pseudo_adh',
-                '_address'  => 'adresse_adh',
-                '_zipcode'  => 'cp_adh',
-                '_town'     => 'ville_adh',
-                '_region'   => 'region_adh'
+                'surname'  => 'prenom_adh',
+                'nickname' => 'pseudo_adh',
+                'address'  => 'adresse_adh',
+                'zipcode'  => 'cp_adh',
+                'town'     => 'ville_adh',
+                'region'   => 'region_adh'
             ];
             foreach ($notnull as $prop => $field) {
                 if (!isset($this->$prop) || $this->$prop === null) {
@@ -1578,24 +1578,24 @@ class Adherent
                 }
             }
 
-            if (empty($this->_id)) {
+            if (empty($this->id)) {
                 //we're inserting a new member
                 unset($values[self::PK]);
                 //set modification date
-                $this->_modification_date = date('Y-m-d');
-                $values['date_modif_adh'] = $this->_modification_date;
+                $this->modification_date = date('Y-m-d');
+                $values['date_modif_adh'] = $this->modification_date;
 
                 $insert = $this->zdb->insert(self::TABLE);
                 $insert->values($values);
                 $add = $this->zdb->execute($insert);
                 if ($add->count() > 0) {
-                    $this->_id = $this->zdb->getLastGeneratedValue($this);
-                    $this->_picture = new Picture($this->_id);
+                    $this->id = $this->zdb->getLastGeneratedValue($this);
+                    $this->picture = new Picture($this->id);
                     // logging
-                    if ($this->_self_adh) {
+                    if ($this->self_adh) {
                         $hist->add(
                             _T("Self_subscription as a member: ") .
-                            $this->getNameWithCase($this->_name, $this->_surname),
+                            $this->getNameWithCase($this->name, $this->surname),
                             $this->sname
                         );
                     } else {
@@ -1616,19 +1616,19 @@ class Adherent
                 //we're editing an existing member
                 if (!$this->isDueFree()) {
                     // deadline
-                    $due_date = Contribution::getDueDate($this->zdb, $this->_id);
+                    $due_date = Contribution::getDueDate($this->zdb, $this->id);
                     if ($due_date) {
                         $values['date_echeance'] = $due_date;
                     }
                 }
 
-                if (!$this->_password) {
+                if (!$this->password) {
                     unset($values['mdp_adh']);
                 }
 
                 $update = $this->zdb->update(self::TABLE);
                 $update->set($values);
-                $update->where([self::PK => $this->_id]);
+                $update->where([self::PK => $this->id]);
 
                 $edit = $this->zdb->execute($update);
 
@@ -1675,10 +1675,10 @@ class Adherent
             $update = $this->zdb->update(self::TABLE);
             $update->set(
                 array('date_modif_adh' => $modif_date)
-            )->where([self::PK => $this->_id]);
+            )->where([self::PK => $this->id]);
 
             $this->zdb->execute($update);
-            $this->_modification_date = $modif_date;
+            $this->modification_date = $modif_date;
         } catch (Throwable $e) {
             Analog::log(
                 'Something went wrong updating modif date :\'( | ' .
@@ -1742,11 +1742,6 @@ class Adherent
         }
 
         if (in_array($name, $virtuals)) {
-            if (substr($name, 0, 1) !== '_') {
-                $real = '_' . substr($name, 1);
-            } else {
-                $real = $name;
-            }
             switch ($name) {
                 case 'sadmin':
                     return (($this->isAdmin()) ? _T("Yes") : _T("No"));
@@ -1755,31 +1750,30 @@ class Adherent
                 case 'sappears_in_list':
                     return (($this->appearsInMembersList()) ? _T("Yes") : _T("No"));
                 case 'sstaff':
-                    return (($this->$real) ? _T("Yes") : _T("No"));
+                    return (($this->isStaff()) ? _T("Yes") : _T("No"));
                 case 'sactive':
                     return (($this->isActive()) ? _T("Active") : _T("Inactive"));
                 case 'stitle':
-                    if (isset($this->_title) && $this->_title instanceof Title) {
-                        return $this->_title->tshort;
+                    if (isset($this->title) && $this->title instanceof Title) {
+                        return $this->title->tshort;
                     } else {
                         return null;
                     }
                 case 'sstatus':
                     $status = new Status($this->zdb);
-                    return $status->getLabel($this->_status);
+                    return $status->getLabel($this->status);
                 case 'sfullname':
                     return $this->getNameWithCase(
-                        $this->_name ?? '',
-                        $this->_surname ?? '',
-                        (isset($this->_title) ? $this->title : false)
+                        $this->name,
+                        $this->surname,
+                        ($this->title ?? false)
                     );
                 case 'saddress':
-                    $address = $this->_address;
-                    return $address;
+                    return $this->address;
                 case 'sname':
-                    return $this->getNameWithCase($this->_name, $this->_surname);
+                    return $this->getNameWithCase($this->name, $this->surname);
                 case 'rbirthdate':
-                    return $this->_birthdate;
+                    return $this->birthdate;
                 case 'sgender':
                     switch ($this->gender) {
                         case self::MAN:
@@ -1796,57 +1790,51 @@ class Adherent
 
         //for backward compatibility
         if (in_array($name, $socials)) {
-            $values = Social::getListForMember($this->_id, $name);
+            $values = Social::getListForMember($this->id, $name);
             return $values[0] ?? null;
         }
 
-        if (substr($name, 0, 1) !== '_') {
-            $rname = '_' . $name;
-        } else {
-            $rname = $name;
-        }
-
         switch ($name) {
             case 'id':
             case 'id_statut':
-                if (isset($this->$rname) && $this->$rname !== null) {
-                    return (int)$this->$rname;
+                if (isset($this->$name) && $this->$name !== null) {
+                    return (int)$this->$name;
                 } else {
                     return null;
                 }
             case 'address':
-                return $this->$rname ?? '';
+                return $this->$name ?? '';
             case 'birthdate':
             case 'creation_date':
             case 'modification_date':
             case 'due_date':
-                if (isset($this->$rname) && $this->$rname != '') {
+                if (isset($this->$name) && $this->$name != '') {
                     try {
-                        $d = new DateTime($this->$rname);
+                        $d = new DateTime($this->$name);
                         return $d->format(__("Y-m-d"));
                     } catch (Throwable $e) {
                         //oops, we've got a bad date :/
                         Analog::log(
-                            'Bad date (' . $this->$rname . ') | ' .
+                            'Bad date (' . $this->$name . ') | ' .
                             $e->getMessage(),
                             Analog::INFO
                         );
-                        return $this->$rname;
+                        return $this->$name;
                     }
                 }
                 return null;
             case 'parent_id':
-                return ($this->_parent instanceof Adherent) ? $this->_parent->id : (int)$this->_parent;
+                return ($this->parent instanceof Adherent) ? $this->parent->id : (int)$this->parent;
             default:
-                if (!property_exists($this, $rname)) {
+                if (!property_exists($this, $name)) {
                     Analog::log(
-                        "Unknown property '$rname'",
+                        "Unknown property '$name'",
                         Analog::WARNING
                     );
                     return null;
                 } else {
-                    if (isset($this->$rname)) {
-                        return $this->$rname;
+                    if (isset($this->$name)) {
+                        return $this->$name;
                     }
                     return null;
                 }
@@ -1908,12 +1896,6 @@ class Adherent
             return true;
         }
 
-        if (substr($name, 0, 1) !== '_') {
-            $rname = '_' . $name;
-        } else {
-            $rname = $name;
-        }
-
         switch ($name) {
             case 'id':
             case 'id_statut':
@@ -1925,7 +1907,7 @@ class Adherent
             case 'parent_id':
                 return true;
             default:
-                return property_exists($this, $rname);
+                return property_exists($this, $name);
         }
     }
 
@@ -1938,7 +1920,7 @@ class Adherent
      */
     public function getEmail(): string
     {
-        $email = $this->_email;
+        $email = $this->email;
         if (empty($email) && $this->hasParent()) {
             $this->loadParent();
             $email = $this->parent->email;
@@ -1955,7 +1937,7 @@ class Adherent
      */
     public function getAddress(): string
     {
-        $address = $this->_address;
+        $address = $this->address;
         if (empty($address) && $this->hasParent()) {
             $this->loadParent();
             $address = $this->parent->address;
@@ -1972,8 +1954,8 @@ class Adherent
      */
     public function getZipcode(): string
     {
-        $address = $this->_address;
-        $zip = $this->_zipcode;
+        $address = $this->address;
+        $zip = $this->zipcode;
         if (empty($address) && $this->hasParent()) {
             $this->loadParent();
             $zip = $this->parent->zipcode;
@@ -1990,8 +1972,8 @@ class Adherent
      */
     public function getTown(): string
     {
-        $address = $this->_address;
-        $town = $this->_town;
+        $address = $this->address;
+        $town = $this->town;
         if (empty($address) && $this->hasParent()) {
             $this->loadParent();
             $town = $this->parent->town;
@@ -2008,8 +1990,8 @@ class Adherent
      */
     public function getRegion(): string
     {
-        $address = $this->_address;
-        $region = $this->_region;
+        $address = $this->address;
+        $region = $this->region;
         if (empty($address) && $this->hasParent()) {
             $this->loadParent();
             $region = $this->parent->region;
@@ -2026,8 +2008,8 @@ class Adherent
      */
     public function getCountry(): string
     {
-        $address = $this->_address;
-        $country = $this->_country;
+        $address = $this->address;
+        $country = $this->country;
         if (empty($address) && $this->hasParent()) {
             $this->loadParent();
             $country = $this->parent->country;
@@ -2043,14 +2025,14 @@ class Adherent
      */
     public function getAge(): string
     {
-        if (!isset($this->_birthdate) && $this->_birthdate == null) {
+        if (!isset($this->birthdate) && $this->birthdate == null) {
             return '';
         }
 
-        $d = DateTime::createFromFormat('Y-m-d', $this->_birthdate);
+        $d = DateTime::createFromFormat('Y-m-d', $this->birthdate);
         if ($d === false) {
             Analog::log(
-                'Invalid birthdate: ' . $this->_birthdate,
+                'Invalid birthdate: ' . $this->birthdate,
                 Analog::ERROR
             );
             return '';
@@ -2132,34 +2114,34 @@ class Adherent
     public function setDuplicate(): void
     {
         //mark as duplicated
-        $this->_duplicate = true;
-        $infos = $this->_others_infos_admin;
-        $this->_others_infos_admin = str_replace(
+        $this->duplicate = true;
+        $infos = $this->others_infos_admin;
+        $this->others_infos_admin = str_replace(
             ['%name', '%id'],
-            [$this->sname, $this->_id],
+            [$this->sname, $this->id],
             _T('Duplicated from %name (%id)')
         );
         if (!empty($infos)) {
-            $this->_others_infos_admin .= "\n" . $infos;
+            $this->others_infos_admin .= "\n" . $infos;
         }
         //drop id_adh
-        $this->_id = null;
+        $this->id = null;
         //drop email, must be unique
-        $this->_email = null;
+        $this->email = null;
         //drop creation date
-        $this->_creation_date = date("Y-m-d");
+        $this->creation_date = date("Y-m-d");
         //drop login
-        $this->_login = null;
+        $this->login = null;
         //reset picture
-        $this->_picture = new Picture();
+        $this->picture = new Picture();
         //remove birthdate
-        $this->_birthdate = null;
+        $this->birthdate = null;
         //remove surname
-        $this->_surname = null;
+        $this->surname = null;
         //not admin
-        $this->_admin = false;
+        $this->admin = false;
         //not due free
-        $this->_due_free = false;
+        $this->due_free = false;
     }
 
     /**
@@ -2182,7 +2164,7 @@ class Adherent
         if (!$this->isDepEnabled('groups')) {
             $this->loadGroups();
         }
-        return $this->_groups;
+        return $this->groups;
     }
 
     /**
@@ -2195,7 +2177,7 @@ class Adherent
         if (!$this->isDepEnabled('groups')) {
             $this->loadGroups();
         }
-        return $this->_managed_groups;
+        return $this->managed_groups;
     }
 
     /**
@@ -2236,7 +2218,7 @@ class Adherent
         global $preferences;
 
         //admin and staff users can edit, as well as member itself
-        if ($this->id && $login->id == $this->id || $login->isAdmin() || $login->isStaff()) {
+        if (isset($this->id) && $login->id == $this->id || $login->isAdmin() || $login->isStaff()) {
             return true;
         }
 
@@ -2285,7 +2267,7 @@ class Adherent
      */
     public function isDuplicate(): bool
     {
-        return $this->_duplicate;
+        return $this->duplicate;
     }
 
     /**
@@ -2320,7 +2302,7 @@ class Adherent
      */
     public function setParent(int $id): self
     {
-        $this->_parent = $id;
+        $this->parent = $id;
         $this->loadParent();
         return $this;
     }
@@ -2332,7 +2314,7 @@ class Adherent
      */
     public function getDueStatus(): int
     {
-        return $this->_due_status;
+        return $this->due_status;
     }
 
     /**
index 595605c93ce541a8aa09914ab4c980fcb188473b..191b2463e86675a9401bc1da532f81ec827ef7e8 100644 (file)
@@ -22,6 +22,7 @@
 namespace Galette\Entity;
 
 use ArrayObject;
+use DateInterval;
 use DateTime;
 use Galette\Events\GaletteEvent;
 use Galette\Features\HasEvent;
@@ -84,19 +85,19 @@ class Contribution
     public const STATUS_LATE = 4;
     public const STATUS_OLD = 5;
 
-    private int $_id;
-    private ?string $_date = null;
-    private ?int $_member = null;
-    private ?ContributionsTypes $_type = null;
-    private ?float $_amount = null;
-    private ?int $_payment_type;
-    private ?float $_orig_amount = null;
-    private ?string $_info = null;
-    private ?string $_begin_date = null;
-    private ?string $_end_date = null;
-    private ?Transaction $_transaction = null;
-    private bool $_is_cotis;
-    private ?int $_extension = null;
+    private int $id;
+    private ?string $date = null;
+    private ?int $member = null;
+    private ?ContributionsTypes $type = null;
+    private ?float $amount = null;
+    private ?int $payment_type;
+    private ?float $orig_amount = null;
+    private ?string $info = null;
+    private ?string $begin_date = null;
+    private ?string $end_date = null;
+    private ?Transaction $transaction = null;
+    private bool $is_cotis;
+    private ?int $extension = null;
     /** @var array<int, PaymentType> */
     private array $ptypes_list;
 
@@ -136,7 +137,7 @@ class Contribution
         $this->login = $login;
 
         global $preferences;
-        $this->_payment_type = $preferences->pref_default_paymenttype;
+        $this->payment_type = $preferences->pref_default_paymenttype;
 
         $this
             ->setFields()
@@ -149,39 +150,39 @@ class Contribution
         if (is_int($args)) {
             $this->load($args);
         } elseif (is_array($args)) {
-            $this->_date = date("Y-m-d");
+            $this->date = date("Y-m-d");
             if (isset($args['adh']) && $args['adh'] != '') {
-                $this->_member = (int)$args['adh'];
+                $this->member = (int)$args['adh'];
             }
             if (isset($args['trans'])) {
-                $this->_transaction = new Transaction($this->zdb, $this->login, (int)$args['trans']);
-                if (!isset($this->_member)) {
-                    $this->_member = $this->_transaction->member;
+                $this->transaction = new Transaction($this->zdb, $this->login, (int)$args['trans']);
+                if (!isset($this->member)) {
+                    $this->member = $this->transaction->member;
                 }
-                $this->_amount = $this->_transaction->getMissingAmount();
+                $this->amount = $this->transaction->getMissingAmount();
             }
             $this->setContributionType((int)$args['type']);
             //calculate begin date for membership fee
-            $this->_begin_date = $this->_date;
-            if ($this->_is_cotis) {
-                $due_date = self::getDueDate($this->zdb, $this->_member);
+            $this->begin_date = $this->date;
+            if ($this->is_cotis) {
+                $due_date = self::getDueDate($this->zdb, $this->member);
                 if ($due_date != '') {
                     $now = new \DateTime();
                     $due_date = new \DateTime($due_date);
                     if ($due_date < $now) {
                         // Member didn't renew on time
-                        $this->_begin_date = $now->format('Y-m-d');
+                        $this->begin_date = $now->format('Y-m-d');
                     } else {
                         // Caution : the next_begin_date is the day after the due_date.
                         $next_begin_date = clone $due_date;
                         $next_begin_date->add(new \DateInterval('P1D'));
-                        $this->_begin_date = $next_begin_date->format('Y-m-d');
+                        $this->begin_date = $next_begin_date->format('Y-m-d');
                     }
                 }
                 $this->retrieveEndDate();
             }
             if (isset($args['payment_type'])) {
-                $this->_payment_type = $args['payment_type'];
+                $this->payment_type = $args['payment_type'];
             }
         } elseif (is_object($args)) {
             $this->loadFromRS($args);
@@ -261,11 +262,11 @@ class Contribution
         global $preferences;
 
         $now = new \DateTime();
-        $begin_date = new \DateTime($this->_begin_date);
+        $begin_date = new \DateTime($this->begin_date);
         if ($preferences->pref_beg_membership != '') {
             //case beginning of membership
             list($j, $m) = explode('/', $preferences->pref_beg_membership);
-            $next_begin_date = new \DateTime($begin_date->format('Y') . '-' . $m . '-' . $j);
+            $next_begin_date = new DateTime($begin_date->format('Y') . '-' . $m . '-' . $j);
             while ($next_begin_date <= $begin_date) {
                 $next_begin_date->add(new \DateInterval('P1Y'));
             }
@@ -288,18 +289,18 @@ class Contribution
             // Caution : the end_date to retrieve is the day before the next_begin_date.
             $end_date = clone $next_begin_date;
             $end_date->sub(new \DateInterval('P1D'));
-            $this->_end_date = $end_date->format('Y-m-d');
+            $this->end_date = $end_date->format('Y-m-d');
         } elseif ($preferences->pref_membership_ext != '') {
             //case membership extension
-            if ($this->_extension == null) {
-                $this->_extension = $preferences->pref_membership_ext;
+            if ($this->extension == null) {
+                $this->extension = $preferences->pref_membership_ext;
             }
-            $dext = new \DateInterval('P' . $this->_extension . 'M');
+            $dext = new \DateInterval('P' . $this->extension . 'M');
             // Caution : the end_date to retrieve is the day before the next_begin_date.
             $next_begin_date = $begin_date->add($dext);
             $end_date = clone $next_begin_date;
             $end_date->sub(new \DateInterval('P1D'));
-            $this->_end_date = $end_date->format('Y-m-d');
+            $this->end_date = $end_date->format('Y-m-d');
         } else {
             throw new \RuntimeException(
                 'Unable to define end date; none of pref_beg_membership nor pref_membership_ext are defined!'
@@ -374,14 +375,14 @@ class Contribution
     private function loadFromRS(ArrayObject $r): void
     {
         $pk = self::PK;
-        $this->_id = (int)$r->$pk;
-        $this->_date = $r->date_enreg;
-        $this->_amount = (double)$r->montant_cotis;
+        $this->id = (int)$r->$pk;
+        $this->date = $r->date_enreg;
+        $this->amount = (double)$r->montant_cotis;
         //save original amount, we need it for transactions parts calculations
-        $this->_orig_amount = (double)$r->montant_cotis;
-        $this->_payment_type = $r->type_paiement_cotis;
-        $this->_info = $r->info_cotis;
-        $this->_begin_date = $r->date_debut_cotis;
+        $this->orig_amount = (double)$r->montant_cotis;
+        $this->payment_type = $r->type_paiement_cotis;
+        $this->info = $r->info_cotis;
+        $this->begin_date = $r->date_debut_cotis;
         $end_date = $r->date_fin_cotis;
         //do not work with knows bad dates...
         //the one with BC comes from 0.63/pgsql demo... Why the hell a so
@@ -391,14 +392,14 @@ class Contribution
             && $end_date !== '1901-01-01'
             && $end_date !== '0001-01-01 BC'
         ) {
-            $this->_end_date = $r->date_fin_cotis;
+            $this->end_date = $r->date_fin_cotis;
         }
         $adhpk = Adherent::PK;
-        $this->_member = (int)$r->$adhpk;
+        $this->member = (int)$r->$adhpk;
 
         $transpk = Transaction::PK;
         if ($r->$transpk != '') {
-            $this->_transaction = new Transaction($this->zdb, $this->login, (int)$r->$transpk);
+            $this->transaction = new Transaction($this->zdb, $this->login, (int)$r->$transpk);
         }
 
         $this->setContributionType((int)$r->id_type_cotis);
@@ -424,7 +425,7 @@ class Contribution
         foreach ($fields as $key) {
             //first, let's sanitize values
             $key = strtolower($key);
-            $prop = '_' . $this->fields[$key]['propname'];
+            $prop = $this->fields[$key]['propname'];
 
             if (isset($values[$key])) {
                 $value = trim($values[$key]);
@@ -449,7 +450,7 @@ class Contribution
                         break;
                     case Adherent::PK:
                         if ($value != '') {
-                            $this->_member = (int)$value;
+                            $this->member = (int)$value;
                         }
                         break;
                     case ContributionsTypes::PK:
@@ -460,7 +461,7 @@ class Contribution
                     case 'montant_cotis':
                         $value = strtr($value, ',', '.');
                         if (!empty($value) || $value === '0') {
-                            $this->_amount = (double)$value;
+                            $this->amount = (double)$value;
                         }
                         if (!is_numeric($value) && $value !== '') {
                             $this->errors[] = _T("- The amount must be an integer!");
@@ -468,15 +469,15 @@ class Contribution
                         break;
                     case 'type_paiement_cotis':
                         if ($value != '') {
-                            $this->_payment_type = (int)$value;
+                            $this->payment_type = (int)$value;
                         }
                         break;
                     case 'info_cotis':
-                        $this->_info = $value;
+                        $this->info = $value;
                         break;
                     case Transaction::PK:
                         if ($value != '') {
-                            $this->_transaction = new Transaction($this->zdb, $this->login, (int)$value);
+                            $this->transaction = new Transaction($this->zdb, $this->login, (int)$value);
                         }
                         break;
                     case 'duree_mois_cotis':
@@ -495,7 +496,7 @@ class Contribution
         // missing required fields?
         foreach ($required as $key => $val) {
             if ($val === 1) {
-                $prop = '_' . $this->fields[$key]['propname'];
+                $prop = $this->fields[$key]['propname'];
                 if (
                     !isset($disabled[$key])
                     && (!isset($this->$prop)
@@ -511,10 +512,10 @@ class Contribution
             }
         }
 
-        if ($this->_transaction != null && $this->_amount != null) {
-            $missing = $this->_transaction->getMissingAmount();
+        if ($this->transaction != null && $this->amount != null) {
+            $missing = $this->transaction->getMissingAmount();
             //calculate new missing amount
-            $missing = $missing + $this->_orig_amount - $this->_amount;
+            $missing = $missing + $this->orig_amount - $this->amount;
             if ($missing < 0) {
                 $this->errors[] = _T("- Sum of all contributions exceed corresponding transaction amount.");
             }
@@ -563,17 +564,17 @@ class Contribution
                 array('ct' => PREFIX_DB . ContributionsTypes::TABLE),
                 'c.' . ContributionsTypes::PK . '=ct.' . ContributionsTypes::PK,
                 array()
-            )->where([Adherent::PK => $this->_member])
+            )->where([Adherent::PK => $this->member])
                 ->where(array('cotis_extension' => new Expression('true')))
                 ->where->nest->nest
-                ->greaterThanOrEqualTo('date_debut_cotis', $this->_begin_date)
-                ->lessThanOrEqualTo('date_debut_cotis', $this->_end_date)
+                ->greaterThanOrEqualTo('date_debut_cotis', $this->begin_date)
+                ->lessThanOrEqualTo('date_debut_cotis', $this->end_date)
                 ->unnest
                 ->or->nest
-                ->greaterThanOrEqualTo('date_fin_cotis', $this->_begin_date)
-                ->lessThanOrEqualTo('date_fin_cotis', $this->_end_date);
+                ->greaterThanOrEqualTo('date_fin_cotis', $this->begin_date)
+                ->lessThanOrEqualTo('date_fin_cotis', $this->end_date);
 
-            if ($this->id != '') {
+            if (isset($this->id)) {
                 $select->where->notEqualTo(self::PK, $this->id);
             }
 
@@ -584,7 +585,7 @@ class Contribution
                 $d_begin = new \DateTime($result->date_debut_cotis);
                 $d_end = new \DateTime($result->date_fin_cotis);
 
-                if ($d_begin->format('m-d') == $d_end->format('m-d') && $result->date_fin_cotis == $this->_begin_date) {
+                if ($d_begin->format('m-d') == $d_end->format('m-d') && $result->date_fin_cotis == $this->begin_date) {
                     //see https://bugs.galette.eu/issues/1762
                     return true;
                 }
@@ -625,7 +626,7 @@ class Contribution
             $values = array();
             $fields = self::getDbFields($this->zdb);
             foreach ($fields as $field) {
-                $prop = '_' . $this->fields[$field]['propname'];
+                $prop = $this->fields[$field]['propname'];
                 if (!isset($this->$prop)) {
                     continue;
                 }
@@ -641,11 +642,11 @@ class Contribution
             }
 
             //no end date, let's take database defaults
-            if (!$this->isFee() && !$this->_end_date) {
+            if (!$this->isFee() && !$this->end_date) {
                 unset($values['date_fin_cotis']);
             }
 
-            if (!isset($this->_id) || $this->_id == '') {
+            if (!isset($this->id) || $this->id == '') {
                 //we're inserting a new contribution
                 unset($values[self::PK]);
 
@@ -654,12 +655,12 @@ class Contribution
                 $add = $this->zdb->execute($insert);
 
                 if ($add->count() > 0) {
-                    $this->_id = $this->zdb->getLastGeneratedValue($this);
+                    $this->id = $this->zdb->getLastGeneratedValue($this);
 
                     // logging
                     $hist->add(
                         _T("Contribution added"),
-                        Adherent::getSName($this->zdb, $this->_member)
+                        Adherent::getSName($this->zdb, $this->member)
                     );
                     $event = $this->getAddEventName();
                 } else {
@@ -671,7 +672,7 @@ class Contribution
             } else {
                 //we're editing an existing contribution
                 $update = $this->zdb->update(self::TABLE);
-                $update->set($values)->where([self::PK => $this->_id]);
+                $update->set($values)->where([self::PK => $this->id]);
                 $edit = $this->zdb->execute($update);
 
                 //edit == 0 does not mean there were an error, but that there
@@ -679,7 +680,7 @@ class Contribution
                 if ($edit->count() > 0) {
                     $hist->add(
                         _T("Contribution updated"),
-                        Adherent::getSName($this->zdb, $this->_member)
+                        Adherent::getSName($this->zdb, $this->member)
                     );
                 }
 
@@ -694,7 +695,7 @@ class Contribution
             $this->dynamicsStore(true);
 
             $this->zdb->connection->commit();
-            $this->_orig_amount = $this->_amount;
+            $this->orig_amount = $this->amount;
 
             //send event at the end of process, once all has been stored
             if ($event !== null && $this->areEventsEnabled()) {
@@ -718,7 +719,7 @@ class Contribution
     private function updateDeadline(): bool
     {
         try {
-            $due_date = self::getDueDate($this->zdb, $this->_member);
+            $due_date = self::getDueDate($this->zdb, $this->member);
 
             if ($due_date != '') {
                 $due_date_update = $due_date;
@@ -730,13 +731,13 @@ class Contribution
             $update->set(
                 array('date_echeance' => $due_date_update)
             )->where(
-                [Adherent::PK => $this->_member]
+                [Adherent::PK => $this->member]
             );
             $this->zdb->execute($update);
             return true;
         } catch (Throwable $e) {
             Analog::log(
-                'An error occurred updating member ' . $this->_member .
+                'An error occurred updating member ' . $this->member .
                 '\'s deadline |' .
                 $e->getMessage(),
                 Analog::ERROR
@@ -762,7 +763,7 @@ class Contribution
             }
 
             $delete = $this->zdb->delete(self::TABLE);
-            $delete->where([self::PK => $this->_id]);
+            $delete->where([self::PK => $this->id]);
             $del = $this->zdb->execute($delete);
             if ($del->count() > 0) {
                 $this->updateDeadline();
@@ -785,7 +786,7 @@ class Contribution
             }
             Analog::log(
                 'An error occurred trying to remove contribution #' .
-                $this->_id . ' | ' . $e->getMessage(),
+                $this->id . ' | ' . $e->getMessage(),
                 Analog::ERROR
             );
             throw $e;
@@ -802,7 +803,7 @@ class Contribution
      */
     public function getFieldLabel(string $field, string $entry = 'label'): string
     {
-        if ($field == 'date_debut_cotis' && !empty($this->_is_cotis) && $this->isFee()) {
+        if ($field == 'date_debut_cotis' && !empty($this->is_cotis) && $this->isFee()) {
             $entry = 'cotlabel';
         }
         return $this->trait_getFieldLabel($field, $entry);
@@ -832,7 +833,7 @@ class Contribution
      */
     public function getRowClass(): string
     {
-        return ($this->_end_date != $this->_begin_date && $this->_is_cotis) ?
+        return ($this->end_date != $this->begin_date && $this->is_cotis) ?
             'cotis-normal' : 'cotis-give';
     }
 
@@ -961,7 +962,7 @@ class Contribution
      */
     public function isFee(): bool
     {
-        return $this->_is_cotis;
+        return $this->is_cotis;
     }
 
     /**
@@ -974,7 +975,7 @@ class Contribution
     public function isTransactionPartOf(int $id): bool
     {
         if ($this->isTransactionPart()) {
-            return $id == $this->_transaction->id;
+            return $id == $this->transaction->id;
         } else {
             return false;
         }
@@ -987,7 +988,7 @@ class Contribution
      */
     public function isTransactionPart(): bool
     {
-        return $this->_transaction != null;
+        return $this->transaction != null;
     }
 
     /**
@@ -1021,15 +1022,15 @@ class Contribution
         }
 
         $voucher_path = null;
-        if (isset($this->_id)) {
+        if (isset($this->id)) {
             $voucher = new PdfContribution($this, $this->zdb, $preferences);
             $voucher->store(GALETTE_CACHE_DIR . '/pdf_contribs');
             $voucher_path = $voucher->getPath();
         }
 
         $contrib = array(
-            'id'        => $this->_id,
-            'date'      => $this->_date,
+            'id'        => $this->id,
+            'date'      => $this->date,
             'type'      => $this->getRawType(),
             'amount'    => $this->amount,
             'voucher'   => $voucher_path,
@@ -1040,10 +1041,10 @@ class Contribution
             'payment'   => $payment
         );
 
-        if ($this->_member !== null) {
-            $m = new Adherent($this->zdb, (int)$this->_member);
+        if ($this->member !== null) {
+            $m = new Adherent($this->zdb, (int)$this->member);
             $member = array(
-                'id'            => (int)$this->_member,
+                'id'            => (int)$this->member,
                 'name'          => $m->sfullname,
                 'email'         => $m->email,
                 'organization'  => ($m->isCompany() ? 1 : 0),
@@ -1116,7 +1117,7 @@ class Contribution
      */
     public function getPaymentType(): string
     {
-        if ($this->_payment_type === null) {
+        if ($this->payment_type === null) {
             return '-';
         }
 
@@ -1133,8 +1134,6 @@ class Contribution
      */
     public function __get(string $name)
     {
-        $rname = '_' . $name;
-
         if (in_array($name, $this->forbidden_fields)) {
             Analog::log(
                 "Call to __get for '$name' is forbidden!",
@@ -1148,35 +1147,33 @@ class Contribution
                     throw new \RuntimeException("Call to __get for '$name' is forbidden!");
             }
         } elseif (
-            property_exists($this, $rname)
-            || property_exists($this, $name)
+            property_exists($this, $name)
             || in_array($name, $this->virtual_fields)
         ) {
             switch ($name) {
                 case 'raw_date':
                 case 'raw_begin_date':
                 case 'raw_end_date':
-                    $rname = '_' . substr($name, 4);
-                    return $this->getDate($rname, false);
+                    return $this->getDate(substr($name, 4), false);
                 case 'date':
                 case 'begin_date':
                 case 'end_date':
-                    return $this->getDate($rname);
+                    return $this->getDate($name);
                 case 'duration':
-                    if (isset($this->_is_cotis)) {
+                    if (isset($this->is_cotis)) {
                         // Caution : the end_date stored is actually the due date.
                         // Adding a day to compute the next_begin_date is required
                         // to return the right number of months.
-                        $next_begin_date = new \DateTime($this->_end_date ?? $this->_begin_date);
-                        $next_begin_date->add(new \DateInterval('P1D'));
-                        $begin_date = new \DateTime($this->_begin_date);
+                        $next_begin_date = new DateTime($this->end_date ?? $this->begin_date);
+                        $next_begin_date->add(new DateInterval('P1D'));
+                        $begin_date = new DateTime($this->begin_date);
                         $diff = $next_begin_date->diff($begin_date);
                         return (int)$diff->format('%y') * 12 + (int)$diff->format('%m');
                     } else {
                         return '';
                     }
                 case 'model':
-                    if (!isset($this->_is_cotis)) {
+                    if (!isset($this->is_cotis)) {
                         return null;
                     }
                     return ($this->isFee()) ?
@@ -1184,37 +1181,23 @@ class Contribution
                 case 'fields':
                     return $this->fields;
                 default:
-                    if (property_exists($this, $rname)) {
-                        if (isset($this->$rname)) {
-                            return $this->$rname;
+                    if (property_exists($this, $name)) {
+                        if (isset($this->$name)) {
+                            return $this->$name;
                         }
                     } else {
-                        throw new \LogicException("Property '" . __CLASS__ . "::$rname' does not exist!");
+                        throw new \LogicException("Property '" . __CLASS__ . "::$name' does not exist!");
                     }
             }
         } else {
             Analog::log(
-                "Unknown property '$rname'",
+                "Unknown property '$name'",
                 Analog::WARNING
             );
             return null;
         }
     }
 
-    /**
-     * Global isset method
-     * Required for twig to access properties via __get
-     *
-     * @param string $name name of the property we want to retrieve
-     *
-     * @return bool
-     */
-    public function __isset(string $name): bool
-    {
-        return $this->trait___isset('_' . $name) || $this->trait___isset($name);
-    }
-
-
     /**
      * Global setter method
      *
@@ -1230,11 +1213,10 @@ class Contribution
         $forbidden = array('fields', 'is_cotis', 'end_date');
 
         if (!in_array($name, $forbidden)) {
-            $rname = '_' . $name;
             switch ($name) {
                 case 'transaction':
                     if (is_int($value)) {
-                        $this->$rname = new Transaction($this->zdb, $this->login, $value);
+                        $this->$name = new Transaction($this->zdb, $this->login, $value);
                     } else {
                         Analog::log(
                             'Trying to set a transaction from an id that is not an integer.',
@@ -1246,11 +1228,11 @@ class Contribution
                     $this->setContributionType($value);
                     break;
                 case 'begin_date':
-                    $this->setDate($rname, $value);
+                    $this->setDate($name, $value);
                     break;
                 case 'amount':
                     if (is_numeric($value) && $value > 0) {
-                        $this->$rname = $value;
+                        $this->$name = $value;
                     } else {
                         Analog::log(
                             'Trying to set an amount with a non numeric value, ' .
@@ -1262,7 +1244,7 @@ class Contribution
                 case 'member':
                     if (is_int($value)) {
                         //set type
-                        $this->$rname = $value;
+                        $this->$name = $value;
                     }
                     break;
                 case 'payment_type':
@@ -1359,7 +1341,7 @@ class Contribution
         }
 
         //admin and staff users can edit, as well as member itself
-        if (!$this->id || $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
+        if (!isset($this->id) || $login->id == $this->member || $login->isAdmin() || $login->isStaff()) {
             return true;
         }
 
@@ -1371,7 +1353,7 @@ class Contribution
             ->load($this->login->id);
         if ($parent->hasChildren()) {
             foreach ($parent->children as $child) {
-                if ($child->id === $this->_member) {
+                if ($child->id === $this->member) {
                     return true;
                 }
             }
@@ -1391,12 +1373,12 @@ class Contribution
     public function setContributionType(int $type): self
     {
         //set type
-        $this->_type = new ContributionsTypes($this->zdb, $type);
+        $this->type = new ContributionsTypes($this->zdb, $type);
         //set is_cotis according to type
-        if ($this->_type->extension == 1) {
-            $this->_is_cotis = true;
+        if ($this->type->extension == 1) {
+            $this->is_cotis = true;
         } else {
-            $this->_is_cotis = false;
+            $this->is_cotis = false;
         }
 
         return $this;
@@ -1433,7 +1415,7 @@ class Contribution
             $this->ptypes_list = $ptypes->getList();
         }
         if (isset($this->ptypes_list[$value])) {
-            $this->_payment_type = $value;
+            $this->payment_type = $value;
         } else {
             Analog::log(
                 'Unknown payment type ' . $value,
index 72f5f25894e1fa962610ce08ad3a97df6748a1fb..6d461ad0248b9290727c6489b46b1d6966980881 100644 (file)
@@ -178,7 +178,7 @@ class ImportModel
      */
     public function getFields(): ?array
     {
-        return $this->fields;
+        return $this->fields ?? null;
     }
 
     /**
index 88b4a9f954a37d056645c0eae3738bc2f4e29d2a..e766cb3e07bc23c753f04ff4a8c654d2e6daeb84 100644 (file)
@@ -41,7 +41,7 @@ use Galette\Features\EntityHelper;
  *
  * @property integer $id
  * @property string $date
- * @property integer $amount
+ * @property float $amount
  * @property ?string $description
  * @property ?integer $member
  * @property ?integer $payment_type
@@ -54,12 +54,12 @@ class Transaction
     public const TABLE = 'transactions';
     public const PK = 'trans_id';
 
-    private int $_id;
-    private string $_date;
-    private float $_amount;
-    private ?string $_description = null;
-    private ?int $_member = null;
-    private ?int $_payment_type = null;
+    private int $id;
+    private string $date;
+    private float $amount;
+    private ?string $description = null;
+    private ?int $member = null;
+    private ?int $payment_type = null;
 
     private Db $zdb;
     private Login $login;
@@ -85,7 +85,7 @@ class Transaction
         $this->setFields();
 
         if ($args === null || is_int($args)) {
-            $this->_date = date("Y-m-d");
+            $this->date = date("Y-m-d");
 
             if (is_int($args) && $args > 0) {
                 $this->load($args);
@@ -215,10 +215,10 @@ class Transaction
                 $this->zdb->connection->beginTransaction();
             }
 
-            //remove associated contributions if needeed
+            //remove associated contributions if needed
             if ($this->getDispatchedAmount() > 0) {
                 $c = new Contributions($this->zdb, $this->login);
-                $clist = $c->getListFromTransaction($this->_id);
+                $clist = $c->getListFromTransaction($this->id);
                 $cids = array();
                 foreach ($clist as $cid) {
                     $cids[] = $cid->id;
@@ -228,7 +228,7 @@ class Transaction
 
             //remove transaction itself
             $delete = $this->zdb->delete(self::TABLE);
-            $delete->where([self::PK => $this->_id]);
+            $delete->where([self::PK => $this->id]);
             $del = $this->zdb->execute($delete);
             if ($del->count() > 0) {
                 $this->dynamicsRemove(true);
@@ -252,7 +252,7 @@ class Transaction
             }
             Analog::log(
                 'An error occurred trying to remove transaction #' .
-                $this->_id . ' | ' . $e->getMessage(),
+                $this->id . ' | ' . $e->getMessage(),
                 Analog::ERROR
             );
             throw $e;
@@ -269,13 +269,13 @@ class Transaction
     private function loadFromRS(ArrayObject $r): void
     {
         $pk = self::PK;
-        $this->_id = $r->$pk;
-        $this->_date = $r->trans_date;
-        $this->_amount = $r->trans_amount;
-        $this->_description = $r->trans_desc;
+        $this->id = $r->$pk;
+        $this->date = $r->trans_date;
+        $this->amount = $r->trans_amount;
+        $this->description = $r->trans_desc;
         $adhpk = Adherent::PK;
-        $this->_member = (int)$r->$adhpk;
-        $this->_payment_type = $r->type_paiement_trans;
+        $this->member = (int)$r->$adhpk;
+        $this->payment_type = $r->type_paiement_trans;
 
         $this->loadDynamicFields();
     }
@@ -299,7 +299,7 @@ class Transaction
         foreach ($fields as $key) {
             //first, let's sanitize values
             $key = strtolower($key);
-            $prop = '_' . $this->fields[$key]['propname'];
+            $prop = $this->fields[$key]['propname'];
 
             if (isset($values[$key])) {
                 $value = trim($values[$key]);
@@ -317,18 +317,18 @@ class Transaction
                             $this->setDate($key, $value);
                             break;
                         case Adherent::PK:
-                            $this->_member = (int)$value;
+                            $this->member = (int)$value;
                             break;
                         case 'trans_amount':
                             $value = strtr($value, ',', '.');
-                            $this->_amount = (double)$value;
+                            $this->amount = (double)$value;
                             if (!is_numeric($value)) {
                                 $this->errors[] = _T("- The amount must be an integer!");
                             }
                             break;
                         case 'trans_desc':
                             /** TODO: retrieve field length from database and check that */
-                            $this->_description = strip_tags($value);
+                            $this->description = strip_tags($value);
                             if (mb_strlen($value) > 150) {
                                 $this->errors[] = _T("- Transaction description must be 150 characters long maximum.");
                             }
@@ -344,7 +344,7 @@ class Transaction
                             );
                             $ptlist = $ptypes->getList();
                             if (isset($ptlist[$value])) {
-                                $this->_payment_type = (int)$value;
+                                $this->payment_type = (int)$value;
                             } else {
                                 $this->errors[] = _T("- Unknown payment type");
                             }
@@ -357,7 +357,7 @@ class Transaction
         // missing required fields?
         foreach ($required as $key => $val) {
             if ($val === 1) {
-                $prop = '_' . $this->fields[$key]['propname'];
+                $prop = $this->fields[$key]['propname'];
                 if (!isset($disabled[$key]) && !isset($this->$prop)) {
                     $this->errors[] = str_replace(
                         '%field',
@@ -368,9 +368,9 @@ class Transaction
             }
         }
 
-        if (isset($this->_id)) {
+        if (isset($this->id)) {
             $dispatched = $this->getDispatchedAmount();
-            if ($dispatched > $this->_amount) {
+            if ($dispatched > $this->amount) {
                 $this->errors[] = _T("- Sum of all contributions exceed corresponding transaction amount.");
             }
         }
@@ -412,25 +412,25 @@ class Transaction
             $fields = $this->getDbFields($this->zdb);
             /** FIXME: quote? */
             foreach ($fields as $field) {
-                $prop = '_' . $this->fields[$field]['propname'];
+                $prop = $this->fields[$field]['propname'];
                 if (isset($this->$prop)) {
                     $values[$field] = $this->$prop;
                 }
             }
 
-            if (!isset($this->_id) || $this->_id == '') {
+            if (!isset($this->id) || $this->id == '') {
                 //we're inserting a new transaction
                 unset($values[self::PK]);
                 $insert = $this->zdb->insert(self::TABLE);
                 $insert->values($values);
                 $add = $this->zdb->execute($insert);
                 if ($add->count() > 0) {
-                    $this->_id = $this->zdb->getLastGeneratedValue($this);
+                    $this->id = $this->zdb->getLastGeneratedValue($this);
 
                     // logging
                     $hist->add(
                         _T("Transaction added"),
-                        Adherent::getSName($this->zdb, $this->_member)
+                        Adherent::getSName($this->zdb, $this->member)
                     );
                     $event = 'transaction.add';
                 } else {
@@ -442,14 +442,14 @@ class Transaction
             } else {
                 //we're editing an existing transaction
                 $update = $this->zdb->update(self::TABLE);
-                $update->set($values)->where([self::PK => $this->_id]);
+                $update->set($values)->where([self::PK => $this->id]);
                 $edit = $this->zdb->execute($update);
                 //edit == 0 does not mean there were an error, but that there
                 //were nothing to change
                 if ($edit->count() > 0) {
                     $hist->add(
                         _T("Transaction updated"),
-                        Adherent::getSName($this->zdb, $this->_member)
+                        Adherent::getSName($this->zdb, $this->member)
                     );
                 }
                 $event = 'transaction.edit';
@@ -484,7 +484,7 @@ class Transaction
      */
     public function getDispatchedAmount(): float
     {
-        if (empty($this->_id)) {
+        if (empty($this->id)) {
             return (double)0;
         }
 
@@ -494,7 +494,7 @@ class Transaction
                 array(
                     'sum' => new Expression('SUM(montant_cotis)')
                 )
-            )->where([self::PK => $this->_id]);
+            )->where([self::PK => $this->id]);
 
             $results = $this->zdb->execute($select);
             $result = $results->current();
@@ -517,8 +517,8 @@ class Transaction
      */
     public function getMissingAmount(): float
     {
-        if (empty($this->_id)) {
-            return (double)$this->amount;
+        if (empty($this->id)) {
+            return $this->amount ?? 0;
         }
 
         try {
@@ -527,12 +527,12 @@ class Transaction
                 array(
                     'sum' => new Expression('SUM(montant_cotis)')
                 )
-            )->where([self::PK => $this->_id]);
+            )->where([self::PK => $this->id]);
 
             $results = $this->zdb->execute($select);
             $result = $results->current();
             $dispatched_amount = $result->sum;
-            return (double)$this->_amount - (double)$dispatched_amount;
+            return (double)$this->amount - (double)$dispatched_amount;
         } catch (Throwable $e) {
             Analog::log(
                 'An error occurred retrieving missing amounts | ' .
@@ -550,7 +550,7 @@ class Transaction
      */
     public function getPaymentType(): string
     {
-        if ($this->_payment_type === null) {
+        if ($this->payment_type === null) {
             return '-';
         }
 
@@ -595,25 +595,24 @@ class Transaction
      */
     public function __get(string $name)
     {
-        $rname = '_' . $name;
-        if (!in_array($name, $this->forbidden_fields) && (property_exists($this, $rname) || property_exists($this, $name))) {
+        if (!in_array($name, $this->forbidden_fields) && property_exists($this, $name)) {
             switch ($name) {
                 case 'date':
-                    return $this->getDate($rname);
+                    return $this->getDate($name);
                 case 'id':
-                    if (isset($this->$rname) && $this->$rname !== null) {
-                        return (int)$this->$rname;
+                    if (isset($this->$name) && $this->$name !== null) {
+                        return (int)$this->$name;
                     }
                     return null;
                 case 'amount':
-                    if (isset($this->$rname)) {
-                        return (double)$this->$rname;
+                    if (isset($this->$name)) {
+                        return (double)$this->$name;
                     }
                     return null;
                 case 'fields':
                     return $this->fields;
                 default:
-                    return $this->$rname;
+                    return $this->$name;
             }
         } else {
             Analog::log(
@@ -667,7 +666,7 @@ class Transaction
         }
 
         //admin and staff users can edit, as well as member itself
-        if (!$this->id || $login->id == $this->_member || $login->isAdmin() || $login->isStaff()) {
+        if (!isset($this->id) || $login->id == $this->member || $login->isAdmin() || $login->isStaff()) {
             return true;
         }
 
@@ -679,7 +678,7 @@ class Transaction
             ->load($this->login->id);
         if ($parent->hasChildren()) {
             foreach ($parent->children as $child) {
-                if ($child->id === $this->_member) {
+                if ($child->id === $this->member) {
                     return true;
                 }
             }
index 76185e14c3c957168c315834a0c993367fe64f4e..452426e7a4f7b4cbc9636c35e85781450e7e17c2 100644 (file)
@@ -46,7 +46,7 @@ use Slim\Router;
 trait Dependencies
 {
     /** @var array<string, bool> */
-    protected array $_deps = array(
+    protected array $deps = array(
         'picture'   => true,
         'groups'    => true,
         'dues'      => true,
@@ -65,8 +65,8 @@ trait Dependencies
      */
     public function setDeps(array $deps): self
     {
-        $this->_deps = array_merge(
-            $this->_deps,
+        $this->deps = array_merge(
+            $this->deps,
             $deps
         );
         return $this;
@@ -79,8 +79,8 @@ trait Dependencies
      */
     public function disableAllDeps(): self
     {
-        $this->_deps = array_fill_keys(
-            array_keys($this->_deps),
+        $this->deps = array_fill_keys(
+            array_keys($this->deps),
             false
         );
         return $this;
@@ -93,7 +93,7 @@ trait Dependencies
      */
     public function enableAllDeps(): self
     {
-        foreach ($this->_deps as &$dep) {
+        foreach ($this->deps as &$dep) {
             $dep = true;
         }
         return $this;
@@ -108,13 +108,13 @@ trait Dependencies
      */
     public function enableDep(string $name): self
     {
-        if (!isset($this->_deps[$name])) {
+        if (!isset($this->deps[$name])) {
             Analog::log(
                 'dependency ' . $name . ' does not exists!',
                 Analog::WARNING
             );
         } else {
-            $this->_deps[$name] = true;
+            $this->deps[$name] = true;
         }
 
         return $this;
@@ -129,13 +129,13 @@ trait Dependencies
      */
     public function disableDep(string $name): self
     {
-        if (!isset($this->_deps[$name])) {
+        if (!isset($this->deps[$name])) {
             Analog::log(
                 'dependency ' . $name . ' does not exists!',
                 Analog::WARNING
             );
         } else {
-            $this->_deps[$name] = false;
+            $this->deps[$name] = false;
         }
 
         return $this;
@@ -150,6 +150,6 @@ trait Dependencies
      */
     protected function isDepEnabled(string $name): bool
     {
-        return $this->_deps[$name];
+        return $this->deps[$name];
     }
 }
index ffeb2143e46b9a94ed9ca5d1c4e2d24d5e11d235..c4841aae489c78894e3652744e845bae0a6193fd 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Galette\Features;
 
+use Galette\Core\Login;
 use Galette\Entity\Adherent;
 use Galette\Repository\DynamicFieldsSet;
 use Throwable;
@@ -53,10 +54,11 @@ trait Dynamics
      */
     private function loadDynamicFields(): void
     {
-        if (!property_exists($this, 'login')) {
-            global $login;
-        } else {
+        /** @phpstan-ignore-next-line */
+        if (property_exists($this, 'login') && ($this->login ?? null) instanceof Login) {
             $login = $this->login;
+        } else {
+            global $login;
         }
         $this->dynamics = new DynamicFieldsHandle($this->zdb, $login, $this);
     }
@@ -183,7 +185,7 @@ trait Dynamics
                         }
                         //actual field value
                         if ($value !== null && trim($value) !== '') {
-                            $this->dynamics->setValue($this->id, $field_id, $val_index, $value);
+                            $this->dynamics->setValue($this->id ?? null, $field_id, $val_index, $value);
                         } else {
                             $this->dynamics->unsetValue($field_id, $val_index);
                         }
index f3621427378997c8ccfddbeb0ceaf2750cd11405..aab70d6ac3f713d1ee36c150d8bab65f0c6d8d30 100644 (file)
@@ -35,45 +35,45 @@ use Galette\Repository\PaymentTypes;
  *
  * @author Johan Cwiklinski <johan@x-tnd.be>
  *
- * @property string $creation_date_begin
- * @property string $creation_date_end
- * @property string $modif_date_begin
- * @property string $modif_date_end
- * @property string $due_date_begin
- * @property string $due_date_end
- * @property string $birth_date_begin
- * @property string $birth_date_end
- * @property boolean $show_public_infos
+ * @property ?string $creation_date_begin
+ * @property ?string $creation_date_end
+ * @property ?string $modif_date_begin
+ * @property ?string $modif_date_end
+ * @property ?string $due_date_begin
+ * @property ?string $due_date_end
+ * @property ?string $birth_date_begin
+ * @property ?string $birth_date_end
+ * @property int $show_public_infos
  * @property array|integer $status
- * @property string $contrib_creation_date_begin
- * @property string $contrib_creation_date_end
- * @property string $contrib_begin_date_begin
- * @property string $contrib_begin_date_end
- * @property string $contrib_end_date_begin
- * @property string $contrib_end_date_end
+ * @property ?string $contrib_creation_date_begin
+ * @property ?string $contrib_creation_date_end
+ * @property ?string $contrib_begin_date_begin
+ * @property ?string $contrib_begin_date_end
+ * @property ?string $contrib_end_date_begin
+ * @property ?string $contrib_end_date_end
  * @property array $contributions_types
  * @property array $payments_types
- * @property integer $contrib_min_amount
- * @property integer $contrib_max_amount
+ * @property ?float $contrib_min_amount
+ * @property ?float $contrib_max_amount
  * @property array $contrib_dynamic
  * @property array $free_search
  * @property array $groups_search
  * @property integer $groups_search_log_op
  *
- * @property-read string $rcreation_date_begin
- * @property-read string $rcreation_date_end
- * @property-read string $rmodif_date_begin
- * @property-read string $rmodif_date_end
- * @property-read string $rdue_date_begin
- * @property-read string $rdue_date_end
- * @property-read string $rbirth_date_begin
- * @property-read string $rbirth_date_end
- * @property-read string $rcontrib_creation_date_begin
- * @property-read string $rcontrib_creation_date_end
- * @property-read string $rcontrib_begin_date_begin
- * @property-read string $rcontrib_begin_date_end
- * @property-read string $rcontrib_end_date_begin
- * @property-read string $rcontrib_end_date_end
+ * @property-read ?string $rcreation_date_begin
+ * @property-read ?string $rcreation_date_end
+ * @property-read ?string $rmodif_date_begin
+ * @property-read ?string $rmodif_date_end
+ * @property-read ?string $rdue_date_begin
+ * @property-read ?string $rdue_date_end
+ * @property-read ?string $rbirth_date_begin
+ * @property-read ?string $rbirth_date_end
+ * @property-read ?string $rcontrib_creation_date_begin
+ * @property-read ?string $rcontrib_creation_date_end
+ * @property-read ?string $rcontrib_begin_date_begin
+ * @property-read ?string $rcontrib_begin_date_end
+ * @property-read ?string $rcontrib_end_date_begin
+ * @property-read ?string $rcontrib_end_date_end
  * @property-read array $search_fields
  */
 
@@ -91,29 +91,29 @@ class AdvancedMembersList extends MembersList
     public const OP_BEFORE = 6;
     public const OP_AFTER = 7;
 
-    private ?string $_creation_date_begin = null;
-    private ?string $_creation_date_end = null;
-    private ?string $_modif_date_begin = null;
-    private ?string $_modif_date_end = null;
-    private ?string $_due_date_begin = null;
-    private ?string $_due_date_end = null;
-    private ?string $_birth_date_begin = null;
-    private ?string $_birth_date_end = null;
-    private int $_show_public_infos = Members::FILTER_DC_PUBINFOS;
+    private ?string $creation_date_begin = null;
+    private ?string $creation_date_end = null;
+    private ?string $modif_date_begin = null;
+    private ?string $modif_date_end = null;
+    private ?string $due_date_begin = null;
+    private ?string $due_date_end = null;
+    private ?string $birth_date_begin = null;
+    private ?string $birth_date_end = null;
+    private int $show_public_infos = Members::FILTER_DC_PUBINFOS;
     /** @var array<int> */
-    private array $_status = array();
-    private ?string $_contrib_creation_date_begin = null;
-    private ?string $_contrib_creation_date_end = null;
-    private ?string $_contrib_begin_date_begin = null;
-    private ?string $_contrib_begin_date_end = null;
-    private ?string $_contrib_end_date_begin = null;
-    private ?string $_contrib_end_date_end = null;
+    private array $status = array();
+    private ?string $contrib_creation_date_begin = null;
+    private ?string $contrib_creation_date_end = null;
+    private ?string $contrib_begin_date_begin = null;
+    private ?string $contrib_begin_date_end = null;
+    private ?string $contrib_end_date_begin = null;
+    private ?string $contrib_end_date_end = null;
     /** @var array<int> */
-    private array $_contributions_types = array();
+    private array $contributions_types = array();
     /** @var array<int> */
-    private array $_payments_types = array();
-    private ?int $_contrib_min_amount = null;
-    private ?int $_contrib_max_amount = null;
+    private array $payments_types = array();
+    private ?float $contrib_min_amount = null;
+    private ?float $contrib_max_amount = null;
 
     /** @var array<string> */
     protected array $advancedmemberslist_fields = array(
@@ -167,7 +167,7 @@ class AdvancedMembersList extends MembersList
      *
      * @var array<string,mixed>
      */
-    private array $_free_search = array(
+    private array $free_search = array(
         'empty' => array(
             'field'     => '',
             'search'    => '',
@@ -181,21 +181,21 @@ class AdvancedMembersList extends MembersList
      *
      * @var array<string,mixed>
      */
-    private array $_groups_search = array(
+    private array $groups_search = array(
         'empty' => array(
             'group'    => '',
         )
     );
 
     //defaults to 'OR' for group search
-    private int $_groups_search_log_op = self::OP_OR;
+    private int $groups_search_log_op = self::OP_OR;
 
     /**
      * an empty contributions dynamic field criteria to begin
      *
      * @var array<string,mixed>
      */
-    private array $_contrib_dynamic = array();
+    private array $contrib_dynamic = array();
 
     /**
      * Default constructor
@@ -223,17 +223,17 @@ class AdvancedMembersList extends MembersList
     public function withinContributions(): bool
     {
         if (
-            $this->_contrib_creation_date_begin != null
-            || $this->_contrib_creation_date_end != null
-            || $this->_contrib_begin_date_begin != null
-            || $this->_contrib_begin_date_end != null
-            || $this->_contrib_end_date_begin != null
-            || $this->_contrib_end_date_end != null
-            || $this->_contrib_min_amount != null
-            || $this->_contrib_max_amount != null
-            || count($this->_contrib_dynamic) > 0
-            || count($this->_contributions_types) > 0
-            || count($this->_payments_types) > 0
+            $this->contrib_creation_date_begin != null
+            || $this->contrib_creation_date_end != null
+            || $this->contrib_begin_date_begin != null
+            || $this->contrib_begin_date_end != null
+            || $this->contrib_end_date_begin != null
+            || $this->contrib_end_date_end != null
+            || $this->contrib_min_amount != null
+            || $this->contrib_max_amount != null
+            || count($this->contrib_dynamic) > 0
+            || count($this->contributions_types) > 0
+            || count($this->payments_types) > 0
         ) {
             return true;
         } else {
@@ -250,27 +250,27 @@ class AdvancedMembersList extends MembersList
     {
         parent::reinit();
 
-        $this->_creation_date_begin = null;
-        $this->_creation_date_end = null;
-        $this->_modif_date_begin = null;
-        $this->_modif_date_end = null;
-        $this->_due_date_begin = null;
-        $this->_due_date_end = null;
-        $this->_birth_date_begin = null;
-        $this->_birth_date_end = null;
-        $this->_show_public_infos = Members::FILTER_DC_PUBINFOS;
-        $this->_status = array();
-
-        $this->_contrib_creation_date_begin = null;
-        $this->_contrib_creation_date_end = null;
-        $this->_contrib_begin_date_begin = null;
-        $this->_contrib_begin_date_end = null;
-        $this->_contrib_end_date_begin = null;
-        $this->_contrib_begin_date_end = null;
-        $this->_contributions_types = array();
-        $this->_payments_types = array();
-
-        $this->_free_search = array(
+        $this->creation_date_begin = null;
+        $this->creation_date_end = null;
+        $this->modif_date_begin = null;
+        $this->modif_date_end = null;
+        $this->due_date_begin = null;
+        $this->due_date_end = null;
+        $this->birth_date_begin = null;
+        $this->birth_date_end = null;
+        $this->show_public_infos = Members::FILTER_DC_PUBINFOS;
+        $this->status = array();
+
+        $this->contrib_creation_date_begin = null;
+        $this->contrib_creation_date_end = null;
+        $this->contrib_begin_date_begin = null;
+        $this->contrib_begin_date_end = null;
+        $this->contrib_end_date_begin = null;
+        $this->contrib_begin_date_end = null;
+        $this->contributions_types = array();
+        $this->payments_types = array();
+
+        $this->free_search = array(
             'empty' => array(
                 'field'     => '',
                 'search'    => '',
@@ -279,15 +279,15 @@ class AdvancedMembersList extends MembersList
             )
         );
 
-        $this->_contrib_dynamic = array();
+        $this->contrib_dynamic = array();
 
-        $this->_groups_search = array(
+        $this->groups_search = array(
             'empty' => array(
                 'group'     => '',
             )
         );
 
-        $this->_groups_search_log_op = self::OP_OR;
+        $this->groups_search_log_op = self::OP_OR;
     }
 
     /**
@@ -315,7 +315,6 @@ class AdvancedMembersList extends MembersList
                 in_array($name, $this->advancedmemberslist_fields)
                 || in_array($name, $this->virtuals_advancedmemberslist_fields)
             ) {
-                $rname = '_' . $name;
                 switch ($name) {
                     case 'creation_date_begin':
                     case 'creation_date_end':
@@ -332,18 +331,18 @@ class AdvancedMembersList extends MembersList
                     case 'contrib_end_date_begin':
                     case 'contrib_end_date_end':
                         try {
-                            if ($this->$rname !== null) {
-                                $d = new \DateTime($this->$rname);
+                            if ($this->$name !== null) {
+                                $d = new \DateTime($this->$name);
                                 return $d->format(__("Y-m-d"));
                             }
                         } catch (Throwable $e) {
                             //oops, we've got a bad date :/
                             Analog::log(
-                                'Bad date (' . $this->$rname . ') | ' .
+                                'Bad date (' . $this->$name . ') | ' .
                                 $e->getMessage(),
                                 Analog::INFO
                             );
-                            return $this->$rname;
+                            return $this->$name;
                         }
                         break;
                     case 'rcreation_date_begin':
@@ -360,8 +359,7 @@ class AdvancedMembersList extends MembersList
                     case 'rcontrib_begin_date_end':
                     case 'rcontrib_end_date_begin':
                     case 'rcontrib_end_date_end':
-                        //same as above, but raw format
-                        $rname = '_' . substr($name, 1);
+                        $rname = substr($name, 1);
                         return $this->$rname;
                     case 'search_fields':
                         $search_fields = array_merge($this->memberslist_fields, $this->advancedmemberslist_fields);
@@ -373,10 +371,10 @@ class AdvancedMembersList extends MembersList
                         unset($search_fields[$key]);
                         return $search_fields;
                 }
-                return $this->$rname;
+                return $this->$name;
             } else {
                 Analog::log(
-                    '[AdvancedMembersList] Unable to get proprety `' . $name . '`',
+                    '[AdvancedMembersList] Unable to get property `' . $name . '`',
                     Analog::WARNING
                 );
             }
@@ -433,8 +431,6 @@ class AdvancedMembersList extends MembersList
                 Analog::DEBUG
             );
 
-            $prop = '_' . $name;
-
             switch ($name) {
                 case 'creation_date_begin':
                 case 'creation_date_end':
@@ -456,7 +452,7 @@ class AdvancedMembersList extends MembersList
                             if ($d === false) {
                                 throw new \Exception('Incorrect format');
                             }
-                            $this->$prop = $d->format('Y-m-d');
+                            $this->$name = $d->format('Y-m-d');
                         } catch (Throwable $e) {
                             Analog::log(
                                 'Incorrect date format for ' . $name .
@@ -469,7 +465,7 @@ class AdvancedMembersList extends MembersList
                 case 'contrib_min_amount':
                 case 'contrib_max_amount':
                     if (is_float($value)) {
-                        $this->$prop = $value;
+                        $this->$name = $value;
                     } else {
                         if ($value !== null) {
                             Analog::log(
@@ -482,7 +478,7 @@ class AdvancedMembersList extends MembersList
                     break;
                 case 'show_public_infos':
                     if (is_numeric($value)) {
-                        $this->$prop = $value;
+                        $this->$name = $value;
                     } else {
                         Analog::log(
                             '[AdvancedMembersList] Value for property `' . $name .
@@ -495,14 +491,14 @@ class AdvancedMembersList extends MembersList
                     if (!is_array($value)) {
                         $value = array($value);
                     }
-                    $this->_status = array();
+                    $this->status = array();
                     foreach ($value as $v) {
                         if (is_numeric($v)) {
                             //check status existence
                             $s = new Status($zdb);
                             $res = $s->get($v);
                             if ($res !== false) {
-                                $this->_status[] = $v;
+                                $this->status[] = $v;
                             } else {
                                 Analog::log(
                                     'Status #' . $v . ' does not exists!',
@@ -522,14 +518,14 @@ class AdvancedMembersList extends MembersList
                     if (!is_array($value)) {
                         $value = array($value);
                     }
-                    $this->_contributions_types = array();
+                    $this->contributions_types = array();
                     foreach ($value as $v) {
                         if (is_numeric($v)) {
                             //check type existence
                             $s = new ContributionsTypes($zdb);
                             $res = $s->get($v);
                             if ($res !== false) {
-                                $this->_contributions_types[] = $v;
+                                $this->contributions_types[] = $v;
                             } else {
                                 Analog::log(
                                     'Contribution type #' . $v . ' does not exists!',
@@ -550,7 +546,7 @@ class AdvancedMembersList extends MembersList
                     if (!is_array($value)) {
                         $value = array($value);
                     }
-                    $this->_payments_types = array();
+                    $this->payments_types = array();
                     $ptypes = new PaymentTypes(
                         $zdb,
                         $preferences,
@@ -561,7 +557,7 @@ class AdvancedMembersList extends MembersList
                     foreach ($value as $v) {
                         if (is_numeric($v)) {
                             if (isset($ptlist[$v])) {
-                                $this->_payments_types[] = $v;
+                                $this->payments_types[] = $v;
                             } else {
                                 Analog::log(
                                     'Payment type #' . $v . ' does not exists!',
@@ -578,8 +574,8 @@ class AdvancedMembersList extends MembersList
                     }
                     break;
                 case 'free_search':
-                    if (isset($this->_free_search['empty']) && !isset($value['empty'])) {
-                        unset($this->_free_search['empty']);
+                    if (isset($this->free_search['empty']) && !isset($value['empty'])) {
+                        unset($this->free_search['empty']);
                     }
 
                     if ($this->isValidFreeSearch($value)) {
@@ -614,7 +610,7 @@ class AdvancedMembersList extends MembersList
                                     break;
                             }
 
-                            $this->_free_search[$id] = $value;
+                            $this->free_search[$id] = $value;
                         } else {
                             Analog::log(
                                 '[AdvancedMembersList] bad construct for free filter',
@@ -625,7 +621,7 @@ class AdvancedMembersList extends MembersList
                     break;
                 case 'contrib_dynamic':
                     if (is_array($value)) {
-                        $this->_contrib_dynamic = $value;
+                        $this->contrib_dynamic = $value;
                     } else {
                         Analog::log(
                             '[AdvancedMembersList] Value for dynamic contribution fields filter should be an '
@@ -635,8 +631,8 @@ class AdvancedMembersList extends MembersList
                     }
                     break;
                 case 'groups_search':
-                    if (isset($this->_groups_search['empty'])) {
-                        unset($this->_groups_search['empty']);
+                    if (isset($this->groups_search['empty'])) {
+                        unset($this->groups_search['empty']);
                     }
                     if (is_array($value)) {
                         if (
@@ -645,7 +641,7 @@ class AdvancedMembersList extends MembersList
                         ) {
                             $id = $value['idx'];
                             unset($value['idx']);
-                            $this->_groups_search[$id] = $value;
+                            $this->groups_search[$id] = $value;
                         } else {
                             Analog::log(
                                 '[AdvancedMembersList] bad construct for group filter',
@@ -662,7 +658,7 @@ class AdvancedMembersList extends MembersList
                     break;
                 case 'groups_search_log_op':
                     if ($value == self::OP_AND || $value == self::OP_OR) {
-                        $this->_groups_search_log_op = $value;
+                        $this->groups_search_log_op = $value;
                     } else {
                         Analog::log(
                             '[AdvancedMembersList] Value for group filter logical operator should be '
@@ -683,11 +679,11 @@ class AdvancedMembersList extends MembersList
                             } else {
                                 $id = substr($name, 4, strlen($name));
                             }
-                            $this->_contrib_dynamic[$id] = $value;
+                            $this->contrib_dynamic[$id] = $value;
                         }
                     } else {
                         Analog::log(
-                            '[AdvancedMembersList] Unable to set proprety `' .
+                            '[AdvancedMembersList] Unable to set property `' .
                             $name . '`',
                             Analog::WARNING
                         );
index 1e01425750e0b913c0c8ba874eade7412590194c..3e3df91f2ccf51c4cdd3144c35a866b7eb5e0a53 100644 (file)
@@ -33,12 +33,12 @@ use Slim\Views\Twig;
  *
  * @author Johan Cwiklinski <johan@x-tnd.be>
  *
- * @property string $filter_str
- * @property integer $field_filter
- * @property integer $membership_filter
- * @property integer $filter_account
- * @property integer $email_filter
- * @property integer $group_filter
+ * @property ?string $filter_str
+ * @property ?integer $field_filter
+ * @property ?integer $membership_filter
+ * @property ?integer $filter_account
+ * @property ?integer $email_filter
+ * @property ?integer $group_filter
  * @property array $selected
  * @property array $unreachable
  * @property string $query
@@ -47,17 +47,17 @@ use Slim\Views\Twig;
 class MembersList extends Pagination
 {
     //filters
-    private ?string $_filter_str = null;
-    private ?int $_field_filter = null;
-    private ?int $_membership_filter = null;
-    private ?int $_filter_account = null;
-    private ?int $_email_filter = null;
-    private ?int $_group_filter = null;
+    private ?string $filter_str = null;
+    private ?int $field_filter = null;
+    private ?int $membership_filter = null;
+    private ?int $filter_account = null;
+    private ?int $email_filter = null;
+    private ?int $group_filter = null;
 
     /** @var array<int> */
-    private array $_selected = [];
+    private array $selected = [];
     /** @var array<int> */
-    private array $_unreachable = [];
+    private array $unreachable = [];
 
     protected string $query = '';
 
@@ -102,13 +102,13 @@ class MembersList extends Pagination
         global $preferences;
 
         parent::reinit();
-        $this->_filter_str = null;
-        $this->_field_filter = null;
-        $this->_membership_filter = null;
-        $this->_filter_account = $preferences->pref_filter_account;
-        $this->_email_filter = Members::FILTER_DC_EMAIL;
-        $this->_group_filter = null;
-        $this->_selected = array();
+        $this->filter_str = null;
+        $this->field_filter = null;
+        $this->membership_filter = null;
+        $this->filter_account = $preferences->pref_filter_account;
+        $this->email_filter = Members::FILTER_DC_EMAIL;
+        $this->group_filter = null;
+        $this->selected = array();
     }
 
     /**
@@ -124,12 +124,7 @@ class MembersList extends Pagination
             return parent::__get($name);
         } else {
             if (in_array($name, $this->memberslist_fields)) {
-                if ($name === 'query') {
-                    return $this->$name;
-                } else {
-                    $name = '_' . $name;
-                    return $this->$name;
-                }
+                return $this->$name;
             } else {
                 Analog::log(
                     '[MembersList] Unable to get property `' . $name . '`',
@@ -180,7 +175,6 @@ class MembersList extends Pagination
                 case 'selected':
                 case 'unreachable':
                     if (is_array($value)) {
-                        $name = '_' . $name;
                         $this->$name = $value;
                     } elseif ($value !== null) {
                         Analog::log(
@@ -191,14 +185,12 @@ class MembersList extends Pagination
                     }
                     break;
                 case 'filter_str':
-                    $name = '_' . $name;
                     $this->$name = $value;
                     break;
                 case 'field_filter':
                 case 'membership_filter':
                 case 'filter_account':
                     if (is_numeric($value)) {
-                        $name = '_' . $name;
                         $this->$name = $value;
                     } elseif ($value !== null) {
                         Analog::log(
@@ -213,7 +205,7 @@ class MembersList extends Pagination
                         case Members::FILTER_DC_EMAIL:
                         case Members::FILTER_W_EMAIL:
                         case Members::FILTER_WO_EMAIL:
-                            $this->_email_filter = $value;
+                            $this->email_filter = $value;
                             break;
                         default:
                             Analog::log(
@@ -232,7 +224,7 @@ class MembersList extends Pagination
                         $g = new Group();
                         $res = $g->load($value);
                         if ($res === true) {
-                            $this->_group_filter = $value;
+                            $this->group_filter = $value;
                         } else {
                             Analog::log(
                                 'Group #' . $value . ' does not exists!',
index 1382d19e1c6833526baa7f1950dfdb5b0981e958..d7f426dcb62c71f35d66be86ce3f14239cc95d89 100644 (file)
@@ -52,9 +52,9 @@ class CsvIn extends Csv implements FileInterface
     protected array $extensions = array('csv', 'txt');
 
     /** @var array<string> */
-    private $_fields;
+    private array $fields;
     /** @var array<string> */
-    private array $_default_fields = array(
+    private array $default_fields = array(
         'nom_adh',
         'prenom_adh',
         'ddn_adh',
@@ -75,14 +75,14 @@ class CsvIn extends Csv implements FileInterface
         'info_adh'
     );
 
-    private bool $_dryrun = true;
+    private bool $dryrun = true;
 
     /** @var array<string,mixed>  */
-    private array $_members_fields;
+    private array $members_fields;
     /** @var array<string,mixed> */
-    private array $_members_fields_cats;
+    private array $members_fields_cats;
     /** @var array<string,bool> */
-    private array $_required;
+    private array $required;
     /** @var array<int, string> */
     private array $statuses;
     /** @var Title[]  */
@@ -90,7 +90,7 @@ class CsvIn extends Csv implements FileInterface
     /** @var array<string,string> */
     private array $langs;
     /** @var array<string,int> */
-    private $emails;
+    private array $emails;
     private Db $zdb;
     private Preferences $preferences;
     private History $history;
@@ -124,12 +124,12 @@ class CsvIn extends Csv implements FileInterface
     private function loadFields()
     {
         //at last, we got the defaults
-        $this->_fields = $this->_default_fields;
+        $this->fields = $this->default_fields;
 
         $model = new ImportModel();
         //we go with default fields if model cannot be loaded
         if ($model->load()) {
-            $this->_fields = $model->getFields();
+            $this->fields = $model->getFields();
         }
     }
 
@@ -140,7 +140,7 @@ class CsvIn extends Csv implements FileInterface
      */
     public function getDefaultFields()
     {
-        return $this->_default_fields;
+        return $this->default_fields;
     }
 
     /**
@@ -180,12 +180,12 @@ class CsvIn extends Csv implements FileInterface
         $this->preferences = $preferences;
         $this->history = $history;
         if ($dryrun === false) {
-            $this->_dryrun = false;
+            $this->dryrun = false;
         }
 
         $this->loadFields();
-        $this->_members_fields = $members_fields;
-        $this->_members_fields_cats = $members_fields_cats;
+        $this->members_fields = $members_fields;
+        $this->members_fields_cats = $members_fields_cats;
 
         if (!$this->check($filename)) {
             return self::INVALID_FILE;
@@ -223,21 +223,21 @@ class CsvIn extends Csv implements FileInterface
             return false;
         }
 
-        $cnt_fields = count($this->_fields);
+        $cnt_fields = count($this->fields);
 
         //check required fields
         $fc = new FieldsConfig(
             $this->zdb,
             Adherent::TABLE,
-            $this->_members_fields,
-            $this->_members_fields_cats
+            $this->members_fields,
+            $this->members_fields_cats
         );
         $config_required = $fc->getRequired();
-        $this->_required = array();
+        $this->required = array();
 
         foreach (array_keys($config_required) as $field) {
-            if (in_array($field, $this->_fields)) {
-                $this->_required[$field] = $field;
+            if (in_array($field, $this->fields)) {
+                $this->required[$field] = $field;
             }
         }
 
@@ -245,7 +245,7 @@ class CsvIn extends Csv implements FileInterface
         $dfields = [];
         $member->setDependencies(
             $this->preferences,
-            $this->_members_fields,
+            $this->members_fields,
             $this->history
         );
 
@@ -280,13 +280,13 @@ class CsvIn extends Csv implements FileInterface
 
                     //check required fields
                     if (
-                        in_array($this->_fields[$col], $this->_required)
+                        in_array($this->fields[$col], $this->required)
                         && empty($column)
                     ) {
                         $this->addError(
                             str_replace(
                                 array('%field', '%row'),
-                                array($this->_fields[$col], $row),
+                                array($this->fields[$col], $row),
                                 _T("Field %field is required, but missing in row %row")
                             )
                         );
@@ -295,7 +295,7 @@ class CsvIn extends Csv implements FileInterface
 
                     //check for statuses
                     //if missing, set default one; if not check it does exists
-                    if ($this->_fields[$col] == Status::PK) {
+                    if ($this->fields[$col] == Status::PK) {
                         if (empty($column)) {
                             $column = Status::DEFAULT_STATUS;
                         } else {
@@ -318,7 +318,7 @@ class CsvIn extends Csv implements FileInterface
                     }
 
                     //check for title
-                    if ($this->_fields[$col] == 'titre_adh' && !empty($column)) {
+                    if ($this->fields[$col] == 'titre_adh' && !empty($column)) {
                         if (!isset($this->titles)) {
                             //load existing titles
                             $titles = new Titles($this->zdb);
@@ -337,8 +337,8 @@ class CsvIn extends Csv implements FileInterface
                     }
 
                     //check for email unicity
-                    if ($this->_fields[$col] == 'email_adh' && !empty($column)) {
-                        if ($this->emails === null) {
+                    if ($this->fields[$col] == 'email_adh' && !empty($column)) {
+                        if (!isset($this->emails)) {
                             //load existing emails
                             $this->emails = Members::getEmails($this->zdb);
                         }
@@ -362,7 +362,7 @@ class CsvIn extends Csv implements FileInterface
                     }
 
                     //check for language
-                    if ($this->_fields[$col] == 'pref_lang') {
+                    if ($this->fields[$col] == 'pref_lang') {
                         if (!isset($this->langs)) {
                             //load existing titles
                             /** @var I18n $i18n */
@@ -386,16 +386,16 @@ class CsvIn extends Csv implements FileInterface
                     }
 
                     //passwords
-                    if ($this->_fields[$col] == 'mdp_adh' && !empty($column)) {
-                        $this->_fields['mdp_adh2'] = $column;
+                    if ($this->fields[$col] == 'mdp_adh' && !empty($column)) {
+                        $this->fields['mdp_adh2'] = $column;
                     }
 
-                    if (substr($this->_fields[$col], 0, strlen('dynfield_')) === 'dynfield_') {
+                    if (substr($this->fields[$col], 0, strlen('dynfield_')) === 'dynfield_') {
                         //dynamic field, keep to check later
-                        $dfields[$this->_fields[$col] . '_1'] = $column;
+                        $dfields[$this->fields[$col] . '_1'] = $column;
                     } else {
                         //standard field
-                        $member->validate($this->_fields[$col], $column, $this->_fields);
+                        $member->validate($this->fields[$col], $column, $this->fields);
                     }
                     $errors = $member->getErrors();
                     if (count($errors)) {
@@ -465,29 +465,29 @@ class CsvIn extends Csv implements FileInterface
                     $col = 0;
                     $values = array();
                     foreach ($data as $column) {
-                        if (substr($this->_fields[$col], 0, strlen('dynfield_')) === 'dynfield_') {
+                        if (substr($this->fields[$col], 0, strlen('dynfield_')) === 'dynfield_') {
                             //dynamic field, keep to check later
-                            $values[str_replace('dynfield_', 'info_field_', $this->_fields[$col] . '_1')] = $column;
+                            $values[str_replace('dynfield_', 'info_field_', $this->fields[$col] . '_1')] = $column;
                             $col++;
                             continue;
                         }
 
-                        $values[$this->_fields[$col]] = $column;
-                        if ($this->_fields[$col] === 'societe_adh') {
+                        $values[$this->fields[$col]] = $column;
+                        if ($this->fields[$col] === 'societe_adh') {
                             $values['is_company'] = true;
                         }
                         //check for booleans
                         if (
-                            ($this->_fields[$col] == 'bool_admin_adh'
-                            || $this->_fields[$col] == 'bool_exempt_adh'
-                            || $this->_fields[$col] == 'bool_display_info'
-                            || $this->_fields[$col] == 'activite_adh')
+                            ($this->fields[$col] == 'bool_admin_adh'
+                            || $this->fields[$col] == 'bool_exempt_adh'
+                            || $this->fields[$col] == 'bool_display_info'
+                            || $this->fields[$col] == 'activite_adh')
                             && ($column == null || trim($column) == '')
                         ) {
-                            $values[$this->_fields[$col]] = 0; //defaults to 0 as in Adherent
+                            $values[$this->fields[$col]] = 0; //defaults to 0 as in Adherent
                         }
 
-                        if ($this->_fields[$col] == Status::PK && empty(trim($column))) {
+                        if ($this->fields[$col] == Status::PK && empty(trim($column))) {
                             $values[Status::PK] = Status::DEFAULT_STATUS;
                         }
 
@@ -497,7 +497,7 @@ class CsvIn extends Csv implements FileInterface
                     $member = new Adherent($this->zdb);
                     $member->setDependencies(
                         $this->preferences,
-                        $this->_members_fields,
+                        $this->members_fields,
                         $this->history
                     );
                     //check for empty creation date
@@ -508,9 +508,9 @@ class CsvIn extends Csv implements FileInterface
                         $values['mdp_adh2'] = $values['mdp_adh'];
                     }
 
-                    $valid = $member->check($values, $this->_required, []);
+                    $valid = $member->check($values, $this->required, []);
                     if ($valid === true) {
-                        if ($this->_dryrun === false) {
+                        if ($this->dryrun === false) {
                             $store = $member->store();
                             if ($store !== true) {
                                 $this->addError(
index 6d9b58488c955d22130d510a5493d6c8609be7b9..cd43c7623890d249c6a4e58f3cec687f517b87b4 100644 (file)
@@ -796,7 +796,7 @@ class Members extends GaletteTestCase
 
         $this->assertInstanceOf(\Galette\Entity\Adherent::class, $adh);
         $this->assertTrue($adh->appearsInMembersList());
-        $this->assertNull($adh->_picture);
+        $this->assertNull($adh->picture);
 
         $list = $members->getPublicList(true);
         $this->assertCount(1, $list);