Improve type-safety

This commit is contained in:
2020-09-18 21:38:49 +02:00
committed by Stefan Rohde-Enslin
parent 4aa2a5df2f
commit c298794a32
2 changed files with 8 additions and 5 deletions

View File

@ -10,7 +10,7 @@ require_once __DIR__ . '/inc/datesByCountry.php';
/**
* Autotranslater class for times.
*/
class NodaTimeAutotranslater {
final class NodaTimeAutotranslater {
const USECASE_MONTH = 1;
const USECASE_DAY = 2;
@ -74,11 +74,11 @@ class NodaTimeAutotranslater {
*/
public function translate(array $timeInfo):void {
if (!self::check_translatability($timeInfo['zeit_zaehlzeit_monat'])) {
if (!self::check_translatability((string)$timeInfo['zeit_zaehlzeit_monat'])) {
throw new MDgenericInvalidInputsException("Non-translatable date");
}
if (trim($timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") {
if (trim((string)$timeInfo['zeit_zaehlzeit_tag'], ", .0") === "") {
$dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01";
$usecase = self::USECASE_MONTH;
}
@ -94,7 +94,10 @@ class NodaTimeAutotranslater {
setlocale(LC_TIME, $locale);
if ($locale !== setlocale(LC_TIME, "0")) continue;
if ($usecase === self::USECASE_MONTH) $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0);
else if ($usecase === self::USECASE_DAY) $tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0);
else { # if ($usecase === self::USECASE_DAY)
$tLangValue = strftime(getDateFormatByLang($tLang), $dateGeneral ?: 0);
}
$this->_insertStmt->bind_param("iss", $this->_znum, $tLang, $tLangValue);
$this->_insertStmt->execute();