Skip to content

Commit

Permalink
Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter committed Nov 13, 2024
1 parent 20ed4de commit 8b5ab31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions app/Helpers/arrayHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Searches an array for an item where `$field` equals `$value` and returns the first match.
* Example: $found = array_find([['name' => 'Alice'], ['name' => 'Bob']], 'name', 'Alice'); // Returns ['name' => 'Alice']
*
* @param array $array The array to search through.
* @param mixed $field The field to search for.
* @param mixed $value The value to search for.
* @param array $array The array to search through.
* @param mixed $field The field to search for.
* @param mixed $value The value to search for.
* @return mixed|null The found item or null.
*/
function array_find(array $array, mixed $field, mixed $value): mixed
Expand All @@ -25,7 +25,7 @@ function array_find(array $array, mixed $field, mixed $value): mixed
* Flattens a multidimensional array into a single level array.
* Example: $flat = array_flatten([[1, 2], [3, 4]]); // Returns [1, 2, 3, 4]
*
* @param array $array The array to flatten.
* @param array $array The array to flatten.
* @return array The flattened array.
*/
function array_flatten(array $array): array
Expand All @@ -44,8 +44,8 @@ function array_flatten(array $array): array
* Retrieves the value associated with `$key` from a multidimensional array.
* Example: $name = array_key_map(['user' => ['name' => 'Alice', 'age' => 30]], 'name'); // Returns 'Alice'
*
* @param array $array The array to search through.
* @param mixed $key The key to search for.
* @param array $array The array to search through.
* @param mixed $key The key to search for.
* @return mixed The value associated with `$key` or the mapped array.
*/
function array_key_map(array $array, mixed $key): mixed
Expand All @@ -63,8 +63,8 @@ function array_key_map(array $array, mixed $key): mixed
* Adds a prefix to each key in an array.
* Example: $prefixed = array_key_prefix(['name' => 'Alice'], 'user_'); // Returns ['user_name' => 'Alice']
*
* @param array $array The array whose keys are to be prefixed.
* @param string $prefix The prefix to add to each key.
* @param array $array The array whose keys are to be prefixed.
* @param string $prefix The prefix to add to each key.
* @return array The array with prefixed keys.
*/
function array_key_prefix(array $array, string $prefix): array
Expand All @@ -85,8 +85,8 @@ function array_key_prefix(array $array, string $prefix): array
* Removes an item from an array by key and returns its value.
* Example: $age = array_remove(['name' => 'Alice', 'age' => 30], 'age'); // $data is now ['name' => 'Alice']
*
* @param array $array The array to modify.
* @param mixed $key The key of the item to remove.
* @param array $array The array to modify.
* @param mixed $key The key of the item to remove.
* @return mixed|null The value of the removed item or null.
*/
function array_remove(array &$array, mixed $key): mixed
Expand All @@ -103,7 +103,7 @@ function array_remove(array &$array, mixed $key): mixed
* Wraps a given value in an array if it is not already one.
* Example: $wrapped = array_wrap('Alice'); // Returns ['Alice']
*
* @param mixed $value The value to wrap.
* @param mixed $value The value to wrap.
* @return array The wrapped value.
*/
function array_wrap(mixed $value): array
Expand All @@ -117,7 +117,7 @@ function array_wrap(mixed $value): array
* Pops and returns the last value of the array, reducing the array by one element.
* Example: $last = pop([1, 2, 3]); // Returns 3, $numbers is now [1, 2]
*
* @param array $array The array to pop the value from.
* @param array $array The array to pop the value from.
* @return mixed The popped value.
*/
function pop(array $array): mixed
Expand All @@ -131,7 +131,7 @@ function pop(array $array): mixed
* Shifts and returns the first value of the array after reversing it.
* Example: $first = shift([1, 2, 3]); // Returns 1
*
* @param array $array The array to shift the value from.
* @param array $array The array to shift the value from.
* @return mixed The shifted value.
*/
function shift(array $array): mixed
Expand Down
8 changes: 4 additions & 4 deletions app/Helpers/generalHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Attempts to execute a callback and returns its result or null on failure. Optionally logs errors.
* Example: $result = attempt(function () { return 2 * 3; }); // Returns 6
*
* @param callable $callback The callback to execute.
* @param bool $log Whether to log errors or not.
* @param callable $callback The callback to execute.
* @param bool $log Whether to log errors or not.
* @return mixed|null The result of the callback or null on failure.
*/
function attempt(callable $callback, bool $log = true): mixed
Expand Down Expand Up @@ -50,8 +50,8 @@ function get_type_and_class(mixed $value): array
* Checks if `$haystack` starts with any of the `$needles`.
* Example: $check = starts_with('hello world', ['he', 'wo']); // Returns true
*
* @param string $haystack The string to search in.
* @param array $needles The strings to search for.
* @param string $haystack The string to search in.
* @param array $needles The strings to search for.
* @return bool True if `$haystack` starts with any of the `$needles`, false otherwise.
*/
function starts_with(string $haystack, array $needles): bool
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/stringHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Checks if `$haystack` starts with any of the `$needles`.
* Example: $check = starts_with('hello world', ['he', 'wo']); // Returns true
*
* @param string $haystack The string to search in.
* @param array $needles The strings to search for.
* @param string $haystack The string to search in.
* @param array $needles The strings to search for.
* @return bool True if `$haystack` starts with any of the `$needles`, false otherwise.
*/
function starts_with(string $haystack, array $needles): bool
Expand Down

0 comments on commit 8b5ab31

Please sign in to comment.