Przeglądaj źródła

PHPStan Level 7 Minz_ActionController and lib_date (#5313)

Alexandre Alapetite 3 lat temu
rodzic
commit
ef82e218ea
3 zmienionych plików z 25 dodań i 15 usunięć
  1. 6 3
      lib/Minz/ActionController.php
  2. 19 10
      lib/lib_date.php
  3. 0 2
      tests/phpstan-next.txt

+ 6 - 3
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 ();

+ 19 - 10
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);

+ 0 - 2
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