Skip to content

Commit

Permalink
Types fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 9, 2024
1 parent 2086e31 commit a6dd292
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion galette/includes/functions.inc.php
Expand Up @@ -37,5 +37,5 @@ function isValidWebUrl(string $url): bool
return (preg_match(
'#^http[s]?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i',
$url
));
) === 1);
}
2 changes: 1 addition & 1 deletion galette/lib/Galette/Core/Db.php
Expand Up @@ -195,7 +195,7 @@ public function getDbVersion(bool $check_table = false): string
$results = $this->execute($select);
$result = $results->current();
return number_format(
$result->version,
(float)$result->version,
3,
'.',
''
Expand Down
17 changes: 14 additions & 3 deletions galette/lib/Galette/Core/Preferences.php
Expand Up @@ -508,7 +508,11 @@ public function check(array $values, Login $login): bool
// obtain fields
foreach ($this->getFieldsNames() as $fieldname) {
if (isset($values[$fieldname])) {
$value = trim($values[$fieldname]);
if (is_string($values[$fieldname])) {
$value = trim($values[$fieldname]);
} else {
$value = $values[$fieldname];
}
} else {
$value = "";
}
Expand Down Expand Up @@ -592,7 +596,7 @@ public function check(array $values, Login $login): bool

// missing required fields?
foreach ($this->required as $val) {
if (!isset($values[$val]) || isset($values[$val]) && trim($values[$val]) == '') {
if (!isset($values[$val]) || empty($values[$val])) {
$this->errors[] = str_replace(
'%field',
$val,
Expand Down Expand Up @@ -986,6 +990,9 @@ public function __get(string $name): mixed
{
$forbidden = array('defaults');
$virtuals = array('vpref_email', 'vpref_email_newadh');
$types = [
'int' => ['pref_numrows']
];

if (!in_array($name, $forbidden) && isset($this->prefs[$name])) {
if (
Expand All @@ -1000,7 +1007,7 @@ public function __get(string $name): mixed
$this->prefs[$name] = self::$defaults['pref_adhesion_form'];
}
$value = $this->prefs[$name];
if (TYPE_DB === \Galette\Core\Db::PGSQL) {
if (TYPE_DB === Db::PGSQL) {
if ($value === 'f') {
$value = false;
}
Expand All @@ -1011,6 +1018,10 @@ public function __get(string $name): mixed
$value = $values[0]; //take first as default
}

if (in_array($name, $types['int'])) {
$value = (int)$value;
}

return $value;
}
} elseif (in_array($name, $virtuals)) {
Expand Down

0 comments on commit a6dd292

Please sign in to comment.