A free, self-hostable news aggregator…
PHPStan Level 7 Minz_ActionController and lib_date (#5313)
Alexandre Alapetiteef82e218ea7f
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.phpindex 8cc9fbc0b..c9551a016 100644--- a/lib/Minz/ActionController.php+++ b/lib/Minz/ActionController.php@@ -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 ();diff --git a/lib/lib_date.php b/lib/lib_date.phpindex d9e1610e6..c1b40ecf6 100644--- a/lib/lib_date.php+++ b/lib/lib_date.php@@ -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);+ if ($dt2 === false) {+ $min = false;+ } else {+ if ($max !== null && $max !== false) {+ $dt2->setTimestamp($max);+ }+ $min = $dt2->sub($di1)->getTimestamp() + 1;}- $min = $dt2->sub($di1)->getTimestamp() + 1;} catch (Exception $e) {- $min = false;+ $min = false;}}return array($min, $max);diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txtindex 246a7a422..f61cc4b22 100644--- a/tests/phpstan-next.txt+++ b/tests/phpstan-next.txt@@ -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