modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2024-06-15 15:23:42 +04:00
parent 8c0c1a2f85
commit 88379a441c
1 changed files with 37 additions and 20 deletions

View File

@ -36,35 +36,43 @@ class A {
return false; return false;
} }
static function merge(?array &$dest, ...$merges): void { static function merge(&$dest, ...$merges): void {
self::ensure_narray($dest);
$dest = cl::merge($dest, ...$merges); $dest = cl::merge($dest, ...$merges);
} }
static final function select(?array &$dest, ?array $mappings, bool $inverse=false): void { static final function select(&$dest, ?array $mappings, bool $inverse=false): void {
self::ensure_narray($dest);
$dest = cl::select($dest, $mappings, $inverse); $dest = cl::select($dest, $mappings, $inverse);
} }
static final function selectm(?array &$dest, ?array $mappings, ?array $merge=null): void { static final function selectm(&$dest, ?array $mappings, ?array $merge=null): void {
self::ensure_narray($dest);
$dest = cl::selectm($dest, $mappings, $merge); $dest = cl::selectm($dest, $mappings, $merge);
} }
static final function mselect(?array &$dest, ?array $merge, ?array $mappings): void { static final function mselect(&$dest, ?array $merge, ?array $mappings): void {
self::ensure_narray($dest);
$dest = cl::mselect($dest, $merge, $mappings); $dest = cl::mselect($dest, $merge, $mappings);
} }
static final function pselect(?array &$dest, ?array $pkeys): void { static final function pselect(&$dest, ?array $pkeys): void {
self::ensure_narray($dest);
$dest = cl::pselect($dest, $pkeys); $dest = cl::pselect($dest, $pkeys);
} }
static final function pselectm(?array &$dest, ?array $pkeys, ?array $merge=null): void { static final function pselectm(&$dest, ?array $pkeys, ?array $merge=null): void {
self::ensure_narray($dest);
$dest = cl::pselectm($dest, $pkeys, $merge); $dest = cl::pselectm($dest, $pkeys, $merge);
} }
static final function mpselect(?array &$dest, ?array $merge, ?array $pkeys): void { static final function mpselect(&$dest, ?array $merge, ?array $pkeys): void {
self::ensure_narray($dest);
$dest = cl::mpselect($dest, $merge, $pkeys); $dest = cl::mpselect($dest, $merge, $pkeys);
} }
static final function set_nn(?array &$dest, $key, $value) { static final function set_nn(&$dest, $key, $value) {
self::ensure_narray($dest);
if ($value !== null) { if ($value !== null) {
if ($key === null) $dest[] = $value; if ($key === null) $dest[] = $value;
else $dest[$key] = $value; else $dest[$key] = $value;
@ -72,11 +80,12 @@ class A {
return $value; return $value;
} }
static final function append_nn(?array &$dest, $value, $key=null) { static final function append_nn(&$dest, $value) {
return self::set_nn($dest, $key, $value); return self::set_nn($dest, null, $value);
} }
static final function set_nz(?array &$dest, $key, $value) { static final function set_nz(&$dest, $key, $value) {
self::ensure_narray($dest);
if ($value !== null && $value !== false) { if ($value !== null && $value !== false) {
if ($key === null) $dest[] = $value; if ($key === null) $dest[] = $value;
else $dest[$key] = $value; else $dest[$key] = $value;
@ -84,11 +93,13 @@ class A {
return $value; return $value;
} }
static final function append_nz(?array &$dest, $value, $key=null) { static final function append_nz(&$dest, $value) {
return self::set_nz($dest, $key, $value); self::ensure_narray($dest);
return self::set_nz($dest, null, $value);
} }
static final function prepend_nn(?array &$dest, $value) { static final function prepend_nn(&$dest, $value) {
self::ensure_narray($dest);
if ($value !== null) { if ($value !== null) {
if ($dest === null) $dest = []; if ($dest === null) $dest = [];
array_unshift($dest, $value); array_unshift($dest, $value);
@ -96,7 +107,8 @@ class A {
return $value; return $value;
} }
static final function prepend_nz(?array &$dest, $value) { static final function prepend_nz(&$dest, $value) {
self::ensure_narray($dest);
if ($value !== null && $value !== false) { if ($value !== null && $value !== false) {
if ($dest === null) $dest = []; if ($dest === null) $dest = [];
array_unshift($dest, $value); array_unshift($dest, $value);
@ -104,7 +116,8 @@ class A {
return $value; return $value;
} }
static final function replace_nx(?array &$dest, $key, $value) { static final function replace_nx(&$dest, $key, $value) {
self::ensure_narray($dest);
if ($dest !== null && !array_key_exists($key, $dest)) { if ($dest !== null && !array_key_exists($key, $dest)) {
return $dest[$key] = $value; return $dest[$key] = $value;
} else { } else {
@ -112,29 +125,33 @@ class A {
} }
} }
static final function replace_n(?array &$dest, $key, $value) { static final function replace_n(&$dest, $key, $value) {
self::ensure_narray($dest);
$pvalue = $dest[$key] ?? null; $pvalue = $dest[$key] ?? null;
if ($pvalue === null) $dest[$key] = $value; if ($pvalue === null) $dest[$key] = $value;
return $pvalue; return $pvalue;
} }
static final function replace_z(?array &$dest, $key, $value) { static final function replace_z(&$dest, $key, $value) {
self::ensure_narray($dest);
$pvalue = $dest[$key] ?? null; $pvalue = $dest[$key] ?? null;
if ($pvalue === null || $pvalue === false) $dest[$key] = $value; if ($pvalue === null || $pvalue === false) $dest[$key] = $value;
return $pvalue; return $pvalue;
} }
static final function pop(?array $dest, $key, $default=null) { static final function pop(&$dest, $key, $default=null) {
if ($dest === null) return $default; if ($dest === null) return $default;
self::ensure_narray($dest);
if ($key === null) return array_pop($dest); if ($key === null) return array_pop($dest);
$value = $dest[$key] ?? $default; $value = $dest[$key] ?? $default;
unset($dest[$key]); unset($dest[$key]);
return $value; return $value;
} }
static final function popx(?array $dest, ?array $keys): array { static final function popx(&$dest, ?array $keys): array {
$values = []; $values = [];
if ($dest === null) return $values; if ($dest === null) return $values;
self::ensure_narray($dest);
if ($keys === null) return $values; if ($keys === null) return $values;
foreach ($keys as $key) { foreach ($keys as $key) {
$values[$key] = self::pop($dest, $key); $values[$key] = self::pop($dest, $key);