From 36085970630afb79fbcee636f5e4e17d58df0977 Mon Sep 17 00:00:00 2001 From: Yurii Date: Tue, 7 Apr 2026 11:53:38 +0300 Subject: [PATCH] Util deprecation removals --- application/Espo/Core/Utils/Util.php | 138 +----------------------- tests/unit/Espo/Core/Utils/UtilTest.php | 91 ---------------- 2 files changed, 5 insertions(+), 224 deletions(-) diff --git a/application/Espo/Core/Utils/Util.php b/application/Espo/Core/Utils/Util.php index 8b8b3123ab..8455ca5c6b 100644 --- a/application/Espo/Core/Utils/Util.php +++ b/application/Espo/Core/Utils/Util.php @@ -205,17 +205,17 @@ class Util $newValue = array_merge($currentArray[$newName], $newValue); } else if ( - !static::isSingleArray($newValue) || - !static::isSingleArray($currentArray[$newName]) + !self::isSingleArray($newValue) || + !self::isSingleArray($currentArray[$newName]) ) { - $newValue = static::merge($currentArray[$newName], $newValue); + $newValue = self::merge($currentArray[$newName], $newValue); } } // check if exists __APPEND__ identifier and remove its if (!isset($currentArray[$newName]) && is_array($newValue)) { - $newValue = static::unsetInArrayByValue($mergeIdentifier, $newValue); + $newValue = self::unsetInArrayByValue($mergeIdentifier, $newValue); } $currentArray[$newName] = $newValue; @@ -409,40 +409,6 @@ class Util return null; } - - /** - * Replace a search-string in an array recursively. - * - * @param string $search - * @param string $replace - * @param string[]|string $array - * @param bool $isKeys - * @return string|array - * - * @todo Maybe to remove the method. - * @deprecated - */ - public static function replaceInArray($search = '', $replace = '', $array = [], $isKeys = true) - { - if (!is_array($array)) { - return str_replace($search, $replace, $array); - } - - $newArr = []; - - foreach ($array as $key => $value) { - $addKey = $key; - - if ($isKeys) { - $addKey = str_replace($search, $replace, $key); - } - - $newArr[$addKey] = static::replaceInArray($search, $replace, $value, $isKeys); - } - - return $newArr; - } - /** * Unset content items defined in the unset.json. * @@ -574,54 +540,9 @@ class Util } /** - * Check if two variables are equal. - * - * @param mixed $var1 - * @param mixed $var2 - * @deprecated As of v9.4. - * @todo Remove in v10.0. - */ - public static function areEqual($var1, $var2): bool - { - if (is_array($var1)) { - static::ksortRecursive($var1); - } - - if (is_array($var2)) { - static::ksortRecursive($var2); - } - - return ($var1 === $var2); - } - - /** - * Sort array recursively. - * * @param array $array - * @deprecated As of v9.4. - * @todo Remove in v10.0. */ - public static function ksortRecursive(&$array): bool - { - if (!is_array($array)) { - return false; - } - - ksort($array); - - foreach ($array as $key => $value) { - static::ksortRecursive($array[$key]); - } - - return true; - } - - /** - * @param array $array - * @deprecated - * @todo Make private. - */ - public static function isSingleArray(array $array): bool + private static function isSingleArray(array $array): bool { foreach ($array as $key => $value) { if (!is_int($key)) { @@ -711,33 +632,6 @@ class Util return preg_replace("/([^\w\d\-_~,;:\[\]\(\).])/u", '_', $fileName); } - /** - * Improved computing the difference of arrays. - * - * @deprecated As of v7.4. - * @param array $array1 - * @param array $array2 - * @return array - */ - public static function arrayDiff(array $array1, array $array2) - { - $diff = []; - - foreach ($array1 as $key1 => $value1) { - if (array_key_exists($key1, $array2)) { - if ($value1 !== $array2[$key1]) { - $diff[$key1] = $array2[$key1]; - } - - continue; - } - - $diff[$key1] = $value1; - } - - return array_merge($diff, array_diff_key($array2, $array1)); - } - /** * Fill an array with specific keys. * @@ -1066,26 +960,4 @@ class Util return implode('', $shuffle($array)); } - - /** - * @deprecated Use `normalizeScopeName`. - * - * @param string $name - * @return string - */ - public static function normilizeScopeName($name) - { - return self::normalizeScopeName($name); - } - - /** - * @deprecated Use `normalizeClassName`. - * - * @param string $name - * @return string - */ - public static function normilizeClassName($name) - { - return self::normalizeClassName($name); - } } diff --git a/tests/unit/Espo/Core/Utils/UtilTest.php b/tests/unit/Espo/Core/Utils/UtilTest.php index 821d34f4b0..7a7490f921 100644 --- a/tests/unit/Espo/Core/Utils/UtilTest.php +++ b/tests/unit/Espo/Core/Utils/UtilTest.php @@ -1141,29 +1141,6 @@ class UtilTest extends TestCase $this->assertEquals('myNameMyPostfix', Util::getNaming('my_name', 'my_postfix', 'postfix', '_')); } - public function testReplaceInArray() - { - $testArray = [ - 'option' => [ - 'default' => '{0}', - 'testKey' => [ - '{0}' => 'testVal', - ], - ], - ]; - - $testResult = [ - 'option' => [ - 'default' => 'DONE', - 'testKey' => [ - 'DONE' => 'testVal', - ], - ], - ]; - - $this->assertEquals($testResult, Util::replaceInArray('{0}', 'DONE', $testArray, true)); - } - #[DataProvider('getClassNames')] public function testGetClassName1($path, $expectedClassName = 'Espo\EntryPoints\Download') { @@ -1534,74 +1511,6 @@ class UtilTest extends TestCase $this->assertEquals($result, Util::unsetInArrayByValue('__APPEND__', $newArray, false)); } - public function testArrayDiff() - { - $array1 = array ( - 'type' => 'enum', - 'options' => - array ( - 0 => '', - 1 => 'Call', - 2 => 'Email', - 3 => 'Existing Customer', - 4 => 'Partner', - 5 => 'Public Relations', - 6 => 'Campaign', - 7 => 'Other', - ), - 'default' => '', - 'required' => true, - 'isSorted' => false, - 'audited' => false, - 'readOnly' => false, - 'tooltip' => false, - 'newAttr1' => false, - ); - - $array2 = array ( - 'type' => 'enum', - 'options' => - array ( - 0 => '', - 1 => 'Call', - 2 => 'Email', - 3 => 'Existing Customer', - 4 => 'Partner', - 5 => 'Public Relations', - 6 => 'Web Site', - 7 => 'Campaign', - 8 => 'Other', - ), - 'default' => '', - 'required' => false, - 'isSorted' => false, - 'audited' => false, - 'readOnly' => false, - 'tooltip' => false, - 'newAttr2' => false, - ); - - $result = array ( - 'options' => - array ( - 0 => '', - 1 => 'Call', - 2 => 'Email', - 3 => 'Existing Customer', - 4 => 'Partner', - 5 => 'Public Relations', - 6 => 'Web Site', - 7 => 'Campaign', - 8 => 'Other', - ), - 'required' => false, - 'newAttr1' => false, - 'newAttr2' => false, - ); - - $this->assertEquals($result, Util::arrayDiff($array1, $array2)); - } - static public function htmlList() { return [