Upgrade to 3.8.3

This commit is contained in:
Bastian Allgeier
2022-12-06 15:37:13 +01:00
parent f9e812cb0c
commit 8381ccb96c
69 changed files with 752 additions and 966 deletions

View File

@@ -521,10 +521,10 @@ class A
is_array($result[$key]) === true &&
is_array($value) === true
) {
$result[$key] = array_replace_recursive($result[$key], $value);
} else {
$result[$key] = $value;
$value = array_replace_recursive($result[$key], $value);
}
$result[$key] = $value;
}
return $result;
@@ -717,10 +717,10 @@ class A
{
foreach ($update as $key => $value) {
if ($value instanceof Closure) {
$array[$key] = call_user_func($value, static::get($array, $key));
} else {
$array[$key] = $value;
$value = call_user_func($value, static::get($array, $key));
}
$array[$key] = $value;
}
return $array;

View File

@@ -99,11 +99,11 @@ class Collection extends Iterator implements Countable
*/
public function __set(string $key, $value): void
{
if ($this->caseSensitive === true) {
$this->data[$key] = $value;
} else {
$this->data[strtolower($key)] = $value;
if ($this->caseSensitive !== true) {
$key = strtolower($key);
}
$this->data[$key] = $value;
}
/**
@@ -380,11 +380,11 @@ class Collection extends Iterator implements Countable
public function find(...$keys)
{
if (count($keys) === 1) {
if (is_array($keys[0]) === true) {
$keys = $keys[0];
} else {
if (is_array($keys[0]) === false) {
return $this->findByKey($keys[0]);
}
$keys = $keys[0];
}
$result = [];
@@ -551,12 +551,14 @@ class Collection extends Iterator implements Countable
// make sure we have a proper key for each group
if (is_array($value) === true) {
throw new Exception('You cannot group by arrays or objects');
} elseif (is_object($value) === true) {
}
if (is_object($value) === true) {
if (method_exists($value, '__toString') === false) {
throw new Exception('You cannot group by arrays or objects');
} else {
$value = (string)$value;
}
$value = (string)$value;
}
if (isset($groups[$value]) === false) {

View File

@@ -2,6 +2,7 @@
namespace Kirby\Toolkit;
use AllowDynamicProperties;
use ArgumentCountError;
use Closure;
use Kirby\Exception\Exception;
@@ -17,7 +18,11 @@ use TypeError;
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://opensource.org/licenses/MIT
*
* @todo remove the following psalm suppress when PHP >= 8.2 required
* @psalm-suppress UndefinedAttributeClass
*/
#[AllowDynamicProperties]
class Component
{
/**

View File

@@ -290,13 +290,11 @@ class I18n
return $translation($count);
}
if (is_string($translation) === true) {
$message = $translation;
} elseif (isset($translation[$count]) === true) {
$message = $translation[$count];
} else {
$message = end($translation);
}
$message = match (true) {
is_string($translation) => $translation,
isset($translation[$count]) => $translation[$count],
default => end($translation)
};
if ($formatNumber === true) {
$count = static::formatNumber($count, $locale);

View File

@@ -15,6 +15,10 @@ use IteratorAggregate;
* @link https://getkirby.com
* @copyright Bastian Allgeier
* @license https://opensource.org/licenses/MIT
*
* @psalm-suppress MissingTemplateParam Implementing template params in this class would
* require implementing them throughout the code base
* https://github.com/getkirby/kirby/pull/4886#pullrequestreview-1203577545
*/
class Iterator implements IteratorAggregate
{

View File

@@ -101,7 +101,10 @@ class Obj extends stdClass
$result = [];
foreach ((array)$this as $key => $value) {
if (is_object($value) === true && method_exists($value, 'toArray')) {
if (
is_object($value) === true &&
method_exists($value, 'toArray')
) {
$result[$key] = $value->toArray();
} else {
$result[$key] = $value;

View File

@@ -406,9 +406,9 @@ class Pagination
if ($this->page < $min || $this->page > $max) {
if (static::$validate === true) {
throw new ErrorPageException('Pagination page ' . $this->page . ' does not exist, expected ' . $min . '-' . $max);
} else {
$this->page = max(min($this->page, $max), $min);
}
$this->page = max(min($this->page, $max), $min);
}
return $this;

View File

@@ -165,8 +165,8 @@ class Query
// the args are everything inside the *outer* parentheses
$args = Str::substr($part, Str::position($part, '(') + 1, -1);
$args = preg_split(self::PARAMETERS, $args);
$args = array_map('self::parameter', $args);
$args = preg_split(static::PARAMETERS, $args);
$args = array_map([$this, 'parameter'], $args);
return compact('method', 'args');
}
@@ -217,7 +217,7 @@ class Query
if (substr($arg, 0, 1) === '[' && substr($arg, -1) === ']') {
$arg = substr($arg, 1, -1);
$arg = preg_split(self::PARAMETERS, $arg);
return array_map('self::parameter', $arg);
return array_map([$this, 'parameter'], $arg);
}
// resolve parameter for objects and methods itself

View File

@@ -450,7 +450,7 @@ class Str
*/
public static function esc(string $string, string $context = 'html'): string
{
if (method_exists('Kirby\Toolkit\Escape', $context) === true) {
if (method_exists(Escape::class, $context) === true) {
return Escape::$context($string);
}