Rétablir la compatibilité avec PHP 8.2

This commit is contained in:
Alexandre NOEL 2026-09-03 22:43:59 +02:00
commit 63224d8b06
12 changed files with 16 additions and 16 deletions

View file

@ -215,7 +215,7 @@ final class AccountingController
if (($f['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK || ($f['size'] ?? 0) > 20 * 1024 * 1024) { if (($f['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK || ($f['size'] ?? 0) > 20 * 1024 * 1024) {
throw new RuntimeException(t('accounting.document_invalid')); throw new RuntimeException(t('accounting.document_invalid'));
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($f['tmp_name']); $mime = (new finfo(FILEINFO_MIME_TYPE))->file($f['tmp_name']);
$ext = $ext =
['application/pdf' => 'pdf', 'image/jpeg' => 'jpg', 'image/png' => 'png', 'image/webp' => 'webp'][$mime] ?? ['application/pdf' => 'pdf', 'image/jpeg' => 'jpg', 'image/png' => 'png', 'image/webp' => 'webp'][$mime] ??
null; null;

View file

@ -144,7 +144,7 @@ final class GrantsController
header('Location: /admin/grants?year=' . $year . '&error=document'); header('Location: /admin/grants?year=' . $year . '&error=document');
return; return;
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($f['tmp_name']) ?: 'application/octet-stream'; $mime = (new finfo(FILEINFO_MIME_TYPE))->file($f['tmp_name']) ?: 'application/octet-stream';
$allowed = ['application/pdf' => 'pdf', 'application/vnd.oasis.opendocument.text' => 'odt']; $allowed = ['application/pdf' => 'pdf', 'application/vnd.oasis.opendocument.text' => 'odt'];
if (!isset($allowed[$mime])) { if (!isset($allowed[$mime])) {
header('Location: /admin/grants?year=' . $year . '&error=format'); header('Location: /admin/grants?year=' . $year . '&error=format');

View file

@ -288,7 +288,7 @@ final class MedicalDocumentsController
if (($f['error'] ?? 1) !== UPLOAD_ERR_OK || ($f['size'] ?? 0) <= 0 || $f['size'] > self::MAX_BYTES) { if (($f['error'] ?? 1) !== UPLOAD_ERR_OK || ($f['size'] ?? 0) <= 0 || $f['size'] > self::MAX_BYTES) {
throw new RuntimeException(t('medical_document.file_invalid')); throw new RuntimeException(t('medical_document.file_invalid'));
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($f['tmp_name']); $mime = (new finfo(FILEINFO_MIME_TYPE))->file($f['tmp_name']);
if (!isset(self::TYPES[$mime])) { if (!isset(self::TYPES[$mime])) {
throw new RuntimeException(t('medical_document.file_type')); throw new RuntimeException(t('medical_document.file_type'));
} }
@ -319,7 +319,7 @@ final class MedicalDocumentsController
} }
private static function fr(string $date): string private static function fr(string $date): string
{ {
return new DateTimeImmutable($date)->format('d/m/Y'); return (new DateTimeImmutable($date))->format('d/m/Y');
} }
private static function fail(string $message): void private static function fail(string $message): void
{ {

View file

@ -229,7 +229,7 @@ final class PublicSiteController
http_response_code(404); http_response_code(404);
return; return;
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($path) ?: 'application/octet-stream'; $mime = (new finfo(FILEINFO_MIME_TYPE))->file($path) ?: 'application/octet-stream';
header('Content-Type: ' . $mime); header('Content-Type: ' . $mime);
header('Content-Length: ' . filesize($path)); header('Content-Length: ' . filesize($path));
header('Cache-Control: public,max-age=3600'); header('Cache-Control: public,max-age=3600');

View file

@ -91,7 +91,7 @@ final class SettingsController
http_response_code(404); http_response_code(404);
return; return;
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($path) ?: 'application/octet-stream'; $mime = (new finfo(FILEINFO_MIME_TYPE))->file($path) ?: 'application/octet-stream';
header('Content-Type: ' . $mime); header('Content-Type: ' . $mime);
header('Content-Length: ' . filesize($path)); header('Content-Length: ' . filesize($path));
header('Cache-Control: private, max-age=3600'); header('Cache-Control: private, max-age=3600');

View file

@ -198,7 +198,7 @@ final class AgendaService
? $end ? $end
->modify( ->modify(
$start->getTimestamp() - $start->getTimestamp() -
new DateTimeImmutable($row['starts_at'])->getTimestamp() . (new DateTimeImmutable($row['starts_at']))->getTimestamp() .
' seconds', ' seconds',
) )
->format('Y-m-d H:i:s') ->format('Y-m-d H:i:s')

View file

@ -31,7 +31,7 @@ final class AssociationBrand
throw new RuntimeException(t('service.logo.too_large')); throw new RuntimeException(t('service.logo.too_large'));
} }
$tmp = (string) $upload['tmp_name']; $tmp = (string) $upload['tmp_name'];
$mime = new finfo(FILEINFO_MIME_TYPE)->file($tmp); $mime = (new finfo(FILEINFO_MIME_TYPE))->file($tmp);
$extension = self::MIME_EXTENSIONS[$mime] ?? null; $extension = self::MIME_EXTENSIONS[$mime] ?? null;
if (!$extension) { if (!$extension) {
throw new RuntimeException(t('service.logo.format')); throw new RuntimeException(t('service.logo.format'));

View file

@ -16,7 +16,7 @@ final class BackupService
if (!is_dir($backupDir) && !mkdir($backupDir, 0775, true) && !is_dir($backupDir)) { if (!is_dir($backupDir) && !mkdir($backupDir, 0775, true) && !is_dir($backupDir)) {
throw new RuntimeException(t('service.backup.directory_failed')); throw new RuntimeException(t('service.backup.directory_failed'));
} }
$stamp = new DateTimeImmutable('now', new DateTimeZone('Europe/Paris'))->format('Ymd-His'); $stamp = (new DateTimeImmutable('now', new DateTimeZone('Europe/Paris')))->format('Ymd-His');
$suffix = $reason === 'pre-restore' ? '-avant-restauration' : ''; $suffix = $reason === 'pre-restore' ? '-avant-restauration' : '';
$target = $backupDir . '/globinours-' . $stamp . $suffix . '.zip'; $target = $backupDir . '/globinours-' . $stamp . $suffix . '.zip';
// Certains volumes synchronisés acceptent les ZIP mais SQLite ne peut pas // Certains volumes synchronisés acceptent les ZIP mais SQLite ne peut pas
@ -50,7 +50,7 @@ final class BackupService
$manifest = [ $manifest = [
'application' => 'Globinours', 'application' => 'Globinours',
'format_version' => self::FORMAT_VERSION, 'format_version' => self::FORMAT_VERSION,
'created_at' => new DateTimeImmutable('now', new DateTimeZone('Europe/Paris'))->format( 'created_at' => (new DateTimeImmutable('now', new DateTimeZone('Europe/Paris')))->format(
DateTimeInterface::ATOM, DateTimeInterface::ATOM,
), ),
'reason' => $reason, 'reason' => $reason,
@ -434,7 +434,7 @@ final class BackupService
private static function describe(string $path): array private static function describe(string $path): array
{ {
$modified = new DateTimeImmutable('@' . (filemtime($path) ?: time()))->setTimezone( $modified = (new DateTimeImmutable('@' . (filemtime($path) ?: time())))->setTimezone(
new DateTimeZone('Europe/Paris'), new DateTimeZone('Europe/Paris'),
); );
return ['name' => basename($path), 'size' => filesize($path) ?: 0, 'date' => $modified->format('d/m/Y H:i:s')]; return ['name' => basename($path), 'size' => filesize($path) ?: 0, 'date' => $modified->format('d/m/Y H:i:s')];

View file

@ -84,7 +84,7 @@ final class PrivacyService
'deposited_animals' => 'deposited_animals' =>
'SELECT internal_code,name,intake_date,intake_type,intake_reason,intake_circumstances FROM animals WHERE depositor_contact_id=? ORDER BY intake_date', 'SELECT internal_code,name,intake_date,intake_type,intake_reason,intake_circumstances FROM animals WHERE depositor_contact_id=? ORDER BY intake_date',
]; ];
$payload = ['generated_at' => new DateTimeImmutable()->format(DATE_ATOM), 'contact' => $contact]; $payload = ['generated_at' => (new DateTimeImmutable())->format(DATE_ATOM), 'contact' => $contact];
foreach ($queries as $key => $sql) { foreach ($queries as $key => $sql) {
$q = $db->prepare($sql); $q = $db->prepare($sql);
$q->execute([$id]); $q->execute([$id]);

View file

@ -124,7 +124,7 @@ final class PrivateMediaService
http_response_code(404); http_response_code(404);
return; return;
} }
$mime = new finfo(FILEINFO_MIME_TYPE)->file($path) ?: 'application/octet-stream'; $mime = (new finfo(FILEINFO_MIME_TYPE))->file($path) ?: 'application/octet-stream';
PrivacyService::logAccess( PrivacyService::logAccess(
'private_' . $kind, 'private_' . $kind,
$id, $id,

View file

@ -136,7 +136,7 @@ final class SystemHealthService
return [ return [
'checks' => $checks, 'checks' => $checks,
'summary' => $summary, 'summary' => $summary,
'generated_at' => new DateTimeImmutable('now', new DateTimeZone('Europe/Paris'))->format('d/m/Y H:i:s'), 'generated_at' => (new DateTimeImmutable('now', new DateTimeZone('Europe/Paris')))->format('d/m/Y H:i:s'),
'php' => PHP_VERSION, 'php' => PHP_VERSION,
'sqlite' => (string) $db->query('SELECT sqlite_version()')->fetchColumn(), 'sqlite' => (string) $db->query('SELECT sqlite_version()')->fetchColumn(),
]; ];
@ -181,7 +181,7 @@ final class SystemHealthService
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: []; $lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) ?: [];
$dates = []; $dates = [];
for ($i = 0; $i < $days; $i++) { for ($i = 0; $i < $days; $i++) {
$dates[] = new DateTimeImmutable("-$i days")->format('d-M-Y'); $dates[] = (new DateTimeImmutable("-$i days"))->format('d-M-Y');
} }
$count = 0; $count = 0;
foreach (array_slice($lines, -1000) as $line) { foreach (array_slice($lines, -1000) as $line) {

View file

@ -164,7 +164,7 @@ try {
$outside = AgendaService::save([ $outside = AgendaService::save([
'item_type' => 'task', 'item_type' => 'task',
'title' => 'Semaine suivante', 'title' => 'Semaine suivante',
'date' => new DateTimeImmutable('monday next week')->format('Y-m-d'), 'date' => (new DateTimeImmutable('monday next week'))->format('Y-m-d'),
'time' => '10:00', 'time' => '10:00',
]); ]);
$ids = array_map('intval', array_column(AgendaService::week(new DateTimeImmutable('today')), 'id')); $ids = array_map('intval', array_column(AgendaService::week(new DateTimeImmutable('today')), 'id'));