PHPStan Level 7 Minz_ActionController and lib_date (#5313)

This commit is contained in:
Alexandre Alapetite
2023-04-19 09:16:48 +02:00
committed by GitHub
parent 687d0b40a8
commit ef82e218ea
3 changed files with 26 additions and 16 deletions

View File

@@ -28,11 +28,14 @@ class Minz_ActionController {
public function __construct () {
$this->csp_policies = self::$csp_default;
$view = null;
if (class_exists(self::$viewType)) {
$this->view = new self::$viewType();
} else {
$this->view = new Minz_View();
$view = new self::$viewType();
if (!($view instanceof Minz_View)) {
$view = null;
}
}
$this->view = $view ?? new Minz_View();
$view_path = Minz_Request::controllerName() . '/' . Minz_Request::actionName() . '.phtml';
$this->view->_path($view_path);
$this->view->attributeParams ();

View File

@@ -56,10 +56,11 @@ function _dateCeiling(string $isoDate): string {
return $x[0] . '1231T' . $t;
case 6:
$d = @strtotime($x[0] . '01');
return $x[0] . date('t', $d) . 'T' . $t;
default:
return $x[0] . 'T' . $t;
if ($d != false) {
return $x[0] . date('t', $d) . 'T' . $t;
}
}
return $x[0] . 'T' . $t;
}
function _noDelimit(?string $isoDate): ?string {
@@ -101,10 +102,14 @@ function parseDateInterval(string $dateInterval): array {
try {
$di2 = new DateInterval($d2);
$dt1 = @date_create(); //new DateTime() would create an Exception if the default time zone is not defined
if ($min !== null && $min !== false) {
$dt1->setTimestamp($min);
if ($dt1 === false) {
$max = false;
} else {
if ($min !== null && $min !== false) {
$dt1->setTimestamp($min);
}
$max = $dt1->add($di2)->getTimestamp() - 1;
}
$max = $dt1->add($di2)->getTimestamp() - 1;
} catch (Exception $e) {
$max = false;
}
@@ -118,12 +123,16 @@ function parseDateInterval(string $dateInterval): array {
try {
$di1 = new DateInterval($d1);
$dt2 = @date_create();
if ($max !== null && $max !== false) {
$dt2->setTimestamp($max);
}
$min = $dt2->sub($di1)->getTimestamp() + 1;
} catch (Exception $e) {
if ($dt2 === false) {
$min = false;
} else {
if ($max !== null && $max !== false) {
$dt2->setTimestamp($max);
}
$min = $dt2->sub($di1)->getTimestamp() + 1;
}
} catch (Exception $e) {
$min = false;
}
}
return array($min, $max);

View File

@@ -35,8 +35,6 @@
./cli/delete-user.php
./cli/do-install.php
./cli/manipulate.translation.php
./lib/lib_date.php
./lib/Minz/ActionController.php
./lib/Minz/Error.php
./lib/Minz/Mailer.php
./lib/Minz/Migrator.php