Skip to content

Commit

Permalink
Documentation improvements (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabbanaesteban authored Oct 10, 2019
1 parent 4877ac9 commit 0e9e41a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
44 changes: 25 additions & 19 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class Arr
*Returns true if the provided function returns true for all elements of an array, false otherwise.
*
* @param array $items
* @param callable $func
* @param mixed $func
*/
public static function all(array $items, callable $func): bool
public static function all(array $items, $func): bool
{
return \count(array_filter($items, $func)) === \count($items);
}
Expand All @@ -19,9 +19,9 @@ public static function all(array $items, callable $func): bool
* Returns true if the provided function returns true for at least one element of an array, false otherwise.
*
* @param array $items
* @param callable $func
* @param mixed $func
*/
public static function any(array $items, callable $func): bool
public static function any(array $items, $func): bool
{
return \count(array_filter($items, $func)) > 0;
}
Expand Down Expand Up @@ -71,9 +71,11 @@ public static function drop(array $items, int $n = 1): array
* Returns the last element for which the provided function returns a truthy value.
*
* @param array $items
* @param callable $func
* @param mixed $func
*
* @return mixed
*/
public static function findLast(array $items, callable $func)
public static function findLast(array $items, $func)
{
$filteredItems = array_filter($items, $func);

Expand All @@ -84,9 +86,9 @@ public static function findLast(array $items, callable $func)
* Returns the index of the last element for which the provided function returns a truthy value.
*
* @param array $items
* @param callable $func
* @param mixed $func
*/
public static function findLastIndex(array $items, callable $func)
public static function findLastIndex(array $items, $func)
{
$keys = array_keys(array_filter($items, $func));

Expand Down Expand Up @@ -116,7 +118,7 @@ public static function flatten(array $items): array
* Groups the elements of an array based on the given function.
*
* @param array $items
* @param [type] $func
* @param mixed $func
*/
public static function groupBy(array $items, $func): array
{
Expand All @@ -139,12 +141,12 @@ public static function groupBy(array $items, $func): array
* Sorts a collection of arrays or objects by key
*
* @param array $items
* @param [type] $attr
* @param [type] $order
* @param mixed $attr
* @param string $order
*
* @return array
*/
public static function orderBy(array $items, $attr, $order): array
public static function orderBy(array $items, $attr, string $order): array
{
$sortedItems = [];
foreach ($items as $item) {
Expand Down Expand Up @@ -176,6 +178,8 @@ public static function hasDuplicates(array $items): bool
* Returns the head of a list.
*
* @param array $items
*
* @return mixed
*/
public static function head(array $items)
{
Expand All @@ -186,6 +190,8 @@ public static function head(array $items)
* Returns the last element in an array.
*
* @param array $items
*
* @return mixed
*/
public static function last(array $items)
{
Expand All @@ -196,7 +202,7 @@ public static function last(array $items)
* Retrieves all of the values for a given key:
*
* @param array $items
* @param [type] $key
* @param mixed $key
*/
public static function pluck(array $items, $key)
{
Expand All @@ -209,7 +215,7 @@ public static function pluck(array $items, $key)
* Mutates the original array to filter out the values specified.
*
* @param array $items
* @param [type] ...$params
* @param mixed ...$params
*/
public static function pull(&$items, ...$params)
{
Expand All @@ -222,9 +228,9 @@ public static function pull(&$items, ...$params)
* Filters the collection using the given callback.
*
* @param array $items
* @param callable $func
* @param mixed $func
*/
public static function reject(array $items, callable $func)
public static function reject(array $items, $func)
{
return array_values(array_diff($items, array_filter($items, $func)));
}
Expand All @@ -233,9 +239,9 @@ public static function reject(array $items, callable $func)
* Removes elements from an array for which the given function returns false.
*
* @param array $items
* @param callable $func
* @param mixed $func
*/
public static function remove(array $items, callable $func)
public static function remove(array $items, $func)
{
$filtered = array_filter($items, $func);

Expand Down Expand Up @@ -267,7 +273,7 @@ public static function take(array $items, int $n = 1): array
* Filters out the elements of an array, that have one of the specified values.
*
* @param array $items
* @param [type] ...$params
* @param mixed ...$params
*/
public static function without(array $items, ...$params)
{
Expand Down
18 changes: 9 additions & 9 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function isAnagram(string $string1, string $string2): bool
/**
* Returns true if the given string is lower case, false otherwise.
*
* @param [type] $string
* @param string $string
*
* @return bool
*/
Expand All @@ -94,23 +94,23 @@ public static function isLowerCase(string $string): bool
/**
* Returns true if the given string is upper case, false otherwise.
*
* @param [type] $string
* @param string $string
*
* @return bool
*/
public static function isUpperCase($string): bool
public static function isUpperCase(string $string): bool
{
return $string === mb_strtoupper($string);
}

/**
* Returns true if the given string is a palindrome, false otherwise.
*
* @param [type] $string
* @param string $string
*
* @return bool
*/
public static function palindrome($string): bool
public static function palindrome(string $string): bool
{
return strrev($string) === $string;
}
Expand Down Expand Up @@ -147,12 +147,12 @@ public static function countVowels(string $string): int
* Decapitalizes the first letter of the sring and then adds it with rest of the string. Omit the upperRest parameter to keep the
* rest of the string intact, or set it to true to convert to uppercase.
*
* @param [type] $string
* @param string $string
* @param bool $upperRest
*
* @return string
*/
public static function decapitalize($string, $upperRest = false): string
public static function decapitalize(string $string, bool $upperRest = false): string
{
return mb_strtolower(mb_substr($string, 0, 1)) . ($upperRest ? mb_strtoupper(mb_substr($string, 1)) : mb_substr($string, 1));
}
Expand All @@ -161,7 +161,7 @@ public static function decapitalize($string, $upperRest = false): string
* Substring a string to specific lenght, but removing whole words
*
* @param string $string
* @param string $to
* @param int $to
*
* @return string
*/
Expand Down Expand Up @@ -189,6 +189,6 @@ public static function letterPlusNumber(string $letter, int $number): string
++$letter;
}

return $letter;
return (string) $letter;
}
}

0 comments on commit 0e9e41a

Please sign in to comment.