Skip to content

Commit

Permalink
Type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed May 9, 2024
1 parent 3a6b34d commit 002501c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 3 additions & 0 deletions galette/lib/Galette/Core/Picture.php
Expand Up @@ -804,6 +804,9 @@ private function resizeImage(string $source, string $ext, string $dest = null, a
}
}

$h = (int)$h;
$w = (int)$w;

// Resized image.
$thumb = imagecreatetruecolor($w, $h);

Expand Down
10 changes: 5 additions & 5 deletions galette/lib/Galette/DynamicFields/DynamicField.php
Expand Up @@ -635,31 +635,31 @@ public function check(array $values): bool
$this->errors[] = _T("- Field name already used.");
}

if ($this->hasWidth() && isset($values['field_width']) && trim($values['field_width']) != '') {
if ($this->hasWidth() && isset($values['field_width'])) {
if (!is_numeric($values['field_width']) || $values['field_width'] <= 0) {
$this->errors[] = _T("- Width must be a positive integer!");
} else {
$this->width = $values['field_width'];
}
}

if ($this->hasHeight() && isset($values['field_height']) && trim($values['field_height']) != '') {
if ($this->hasHeight() && isset($values['field_height'])) {
if (!is_numeric($values['field_height']) || $values['field_height'] <= 0) {
$this->errors[] = _T("- Height must be a positive integer!");
} else {
$this->height = $values['field_height'];
}
}

if ($this->hasSize() && isset($values['field_size']) && trim($values['field_size']) != '') {
if ($this->hasSize() && isset($values['field_size'])) {
if (!is_numeric($values['field_size']) || $values['field_size'] <= 0) {
$this->errors[] = _T("- Size must be a positive integer!");
} else {
$this->size = $values['field_size'];
}
}

if ($this->hasMinSize() && isset($values['field_min_size']) && trim($values['field_min_size']) != '') {
if ($this->hasMinSize() && isset($values['field_min_size'])) {
if (!is_numeric($values['field_min_size']) || $values['field_min_size'] <= 0) {
$this->errors[] = _T("- Min size must be a positive integer!");
} else {
Expand All @@ -678,7 +678,7 @@ public function check(array $values): bool
}
}

if (isset($values['field_repeat']) && trim($values['field_repeat']) != '') {
if (isset($values['field_repeat'])) {
if (!is_numeric($values['field_repeat'])) {
$this->errors[] = _T("- Repeat must be an integer!");
} else {
Expand Down
14 changes: 10 additions & 4 deletions galette/lib/Galette/Entity/Adherent.php
Expand Up @@ -1269,8 +1269,8 @@ public function check(array $values, array $required, array $disabled): bool|arr
} else {
$owned_group = false;
foreach ($values['groups_adh'] as $group) {
list($gid) = explode('|', $group);
if ($login->isGroupManager($gid)) {
list($gid) = explode('|', (string)$group);
if ($login->isGroupManager((int)$gid)) {
$owned_group = true;
}
}
Expand Down Expand Up @@ -1379,6 +1379,12 @@ public function validate(string $field, mixed $value, array $values): void
);
}
break;
//booleans
case 'bool_admin_adh':
case 'bool_exempt_adh':
case 'bool_display_info':
$this->$prop = (bool)$value;
break;
case 'titre_adh':
if ($value !== '') {
if ($value == '-1') {
Expand Down Expand Up @@ -1509,7 +1515,7 @@ public function validate(string $field, mixed $value, array $values): void
if (!$result) {
$this->errors[] = str_replace(
'%id',
$value,
(string)$value,
_T("Status #%id does not exists in database.")
);
break;
Expand All @@ -1519,7 +1525,7 @@ public function validate(string $field, mixed $value, array $values): void
'An error occurred checking status existence: ' . $e->getMessage(),
Analog::ERROR
);
$this->errors[] = _T("An error has occurred while looking if status does exists.");
throw $e;
}
break;
case 'sexe_adh':
Expand Down
4 changes: 2 additions & 2 deletions tests/Galette/Core/tests/units/Password.php
Expand Up @@ -111,11 +111,11 @@ private function createMember(): int
$this->zdb->execute($insert);

if ($this->zdb->isPostgres()) {
return $this->zdb->driver->getLastGeneratedValue(
return (int)$this->zdb->driver->getLastGeneratedValue(
PREFIX_DB . 'adherents_id_seq'
);
} else {
return $this->zdb->driver->getLastGeneratedValue();
return (int)$this->zdb->driver->getLastGeneratedValue();
}
}

Expand Down

0 comments on commit 002501c

Please sign in to comment.