aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Minz/Helper.php7
-rw-r--r--lib/Minz/Request.php9
2 files changed, 11 insertions, 5 deletions
diff --git a/lib/Minz/Helper.php b/lib/Minz/Helper.php
index 92e97ad6c..8ecc1af8d 100644
--- a/lib/Minz/Helper.php
+++ b/lib/Minz/Helper.php
@@ -12,8 +12,13 @@ class Minz_Helper {
/**
* Wrapper for htmlspecialchars.
* Force UTf-8 value and can be used on array too.
+ *
+ * @phpstan-template T of string|array<mixed>
+ * @phpstan-param T $var
+ * @phpstan-return T
+ *
* @param string|array<string> $var
- * @return ($var is array ? array<string> : string)
+ * @return string|array<string>
*/
public static function htmlspecialchars_utf8($var) {
if (is_array($var)) {
diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php
index a03aff18b..7957610e2 100644
--- a/lib/Minz/Request.php
+++ b/lib/Minz/Request.php
@@ -49,8 +49,10 @@ class Minz_Request {
$p = self::$params[$key];
if (is_object($p) || $specialchars) {
return $p;
- } else {
+ } elseif (is_string($p) || is_array($p)) {
return Minz_Helper::htmlspecialchars_utf8($p);
+ } else {
+ return $p;
}
} else {
return $default;
@@ -66,8 +68,7 @@ class Minz_Request {
return $specialchars ? Minz_Helper::htmlspecialchars_utf8(self::$params[$key]) : self::$params[$key];
}
- /** @return bool|null */
- public static function paramTernary(string $key) {
+ public static function paramTernary(string $key): ?bool {
if (isset(self::$params[$key])) {
$p = self::$params[$key];
$tp = is_string($p) ? trim($p) : true;
@@ -457,7 +458,7 @@ class Minz_Request {
/**
* @return array<string>
*/
- public static function getPreferredLanguages() {
+ public static function getPreferredLanguages(): array {
if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches)) {
return $matches['lang'];
}