Commit 1e21ea1f authored by Oana-Eliza Alexa's avatar Oana-Eliza Alexa
Browse files

fix indent

1 merge request!76Draft: Resolve "Redesign notifications class"
Showing with 69 additions and 69 deletions
+69 -69
...@@ -2,82 +2,82 @@ ...@@ -2,82 +2,82 @@
class Utils class Utils
{ {
private function __construct() {} private function __construct () {}
/** /**
* @param array $array * @param array $array
* @return array * @return array
* Note : Recursively filters out empty values and arrays at any depth. * Note : Recursively filters out empty values and arrays at any depth.
*/ */
public static function recursiveArrayFilter (array $array): array public static function recursiveArrayFilter (array $array): array
{ {
// First filter the array for non-empty elements // First filter the array for non-empty elements
$filtered = array_filter($array, function ($item) { $filtered = array_filter($array, function ($item) {
if (is_array($item)) { if (is_array($item)) {
// Recursively filter the sub-array // Recursively filter the sub-array
$item = $this->recursiveArrayFilter($item); $item = $this->recursiveArrayFilter($item);
// Only retain non-empty arrays // Only retain non-empty arrays
return !empty($item); return !empty($item);
} else { } else {
// Retain non-empty scalar values // Retain non-empty scalar values
return !empty($item); return !empty($item);
} }
}); });
return $filtered; return $filtered;
} }
/** /**
* Find matching keys between 2 lists. * Find matching keys between 2 lists.
* *
* @param array|null $elements * @param array|null $elements
* @param array $keys * @param array $keys
* @return array * @return array
*/ */
public static function findMatchingKeys (?array $elements, array $keys): array public static function findMatchingKeys (?array $elements, array $keys): array
{ {
$matching = []; $matching = [];
if (!empty($elements)) { if (!empty($elements)) {
foreach ($elements as $element) { foreach ($elements as $element) {
foreach ($keys as $key) { foreach ($keys as $key) {
if (!empty($element) && array_key_exists($key, $element)) { if (!empty($element) && array_key_exists($key, $element)) {
$matching[] = $key; $matching[] = $key;
} }
}
}
} }
}
return $matching;
} }
/** return $matching;
* @param $array }
* @return array
* Note : simply return all values of a multi-dimensional array.
*/
public static function getArrayValuesRecursive ($array)
{
$values = [];
foreach ($array as $value) {
if (is_array($value)) {
// If value is an array, merge its values recursively
$values = array_merge($values, self::getArrayValuesRecursive($value));
} else {
// If value is not an array, add it to the result
$values[] = $value;
}
}
return $values;
}
/** /**
* @param string $text * @param $array
* @return string * @return array
* Note : This come from jwtToken, as it is completely private - it is cloned here for now. * Note : simply return all values of a multi-dimensional array.
*/ */
public static function base64urlEncode (string $text): string public static function getArrayValuesRecursive ($array)
{ {
return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text)); $values = [];
foreach ($array as $value) {
if (is_array($value)) {
// If value is an array, merge its values recursively
$values = array_merge($values, self::getArrayValuesRecursive($value));
} else {
// If value is not an array, add it to the result
$values[] = $value;
}
} }
return $values;
}
/**
* @param string $text
* @return string
* Note : This come from jwtToken, as it is completely private - it is cloned here for now.
*/
public static function base64urlEncode (string $text): string
{
return str_replace(["+", "/", "="], ["A", "B", ""], base64_encode($text));
}
} }
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment