Improve type-safety

This commit is contained in:
Joshua Ramon Enslin 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. * Autotranslater class for times.
*/ */
class NodaTimeAutotranslater { final class NodaTimeAutotranslater {
const USECASE_MONTH = 1; const USECASE_MONTH = 1;
const USECASE_DAY = 2; const USECASE_DAY = 2;
@ -74,11 +74,11 @@ class NodaTimeAutotranslater {
*/ */
public function translate(array $timeInfo):void { 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"); 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"; $dateStr = "{$timeInfo['zeit_zaehlzeit_jahr']}-{$timeInfo['zeit_zaehlzeit_monat']}-05 00:00:01";
$usecase = self::USECASE_MONTH; $usecase = self::USECASE_MONTH;
} }
@ -94,7 +94,10 @@ class NodaTimeAutotranslater {
setlocale(LC_TIME, $locale); setlocale(LC_TIME, $locale);
if ($locale !== setlocale(LC_TIME, "0")) continue; if ($locale !== setlocale(LC_TIME, "0")) continue;
if ($usecase === self::USECASE_MONTH) $tLangValue = strftime(getMonthFormatByLang($tLang), $dateGeneral ?: 0); 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->bind_param("iss", $this->_znum, $tLang, $tLangValue);
$this->_insertStmt->execute(); $this->_insertStmt->execute();

View File

@ -173,7 +173,7 @@ final class NodaTimeSplitter {
} }
else if ($moda[0] === $moda[1] && trim($moda[2], " 0") !== "" && trim($moda[3], " 0") === "") { else if ($moda[0] === $moda[1] && trim($moda[2], " 0") !== "" && trim($moda[3], " 0") === "") {
setlocale(LC_TIME, NodaTimeAutotranslater::LANGS_TO_LOCALES['de']); setlocale(LC_TIME, NodaTimeAutotranslater::LANGS_TO_LOCALES['de']);
return strftime(getMonthFormatByLang("de"), strtotime("{$moda[0]}-{$moda[2]}-01 01:01:01")); return strftime(getMonthFormatByLang("de"), MD_STD::strtotime("{$moda[0]}-{$moda[2]}-01 01:01:01"));
} }
return ""; return "";