diff options
| author | 2023-04-19 09:16:48 +0200 | |
|---|---|---|
| committer | 2023-04-19 09:16:48 +0200 | |
| commit | ef82e218ea7f7a6b007e0558c0b90d0e2ba95155 (patch) | |
| tree | 01b9a3ab2307d492266a67ad665cfe8caf11de34 /lib | |
| parent | 687d0b40a89bfaa5fcf99e76b3094c7c4e744f73 (diff) | |
PHPStan Level 7 Minz_ActionController and lib_date (#5313)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/ActionController.php | 9 | ||||
| -rw-r--r-- | lib/lib_date.php | 29 |
2 files changed, 25 insertions, 13 deletions
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.php index 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.php index 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); |
