Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] add parameter & return type hints to the Arr class #17786

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Arr
* @param mixed $value
* @return bool
*/
public static function accessible($value)
public static function accessible($value) : bool
{
return is_array($value) || $value instanceof ArrayAccess;
}
Expand All @@ -28,7 +28,7 @@ public static function accessible($value)
* @param mixed $value
* @return array
*/
public static function add($array, $key, $value)
public static function add(array $array, string $key, $value) : array
{
if (is_null(static::get($array, $key))) {
static::set($array, $key, $value);
Expand All @@ -43,7 +43,7 @@ public static function add($array, $key, $value)
* @param array $array
* @return array
*/
public static function collapse($array)
public static function collapse(array $array) : array
{
$results = [];

Expand All @@ -66,7 +66,7 @@ public static function collapse($array)
* @param array $array
* @return array
*/
public static function divide($array)
public static function divide(array $array) : array
{
return [array_keys($array), array_values($array)];
}
Expand All @@ -78,7 +78,7 @@ public static function divide($array)
* @param string $prepend
* @return array
*/
public static function dot($array, $prepend = '')
public static function dot(array $array, string $prepend = '') : array
{
$results = [];

Expand All @@ -100,7 +100,7 @@ public static function dot($array, $prepend = '')
* @param array|string $keys
* @return array
*/
public static function except($array, $keys)
public static function except(array $array, $keys) : array
{
static::forget($array, $keys);

Expand All @@ -114,7 +114,7 @@ public static function except($array, $keys)
* @param string|int $key
* @return bool
*/
public static function exists($array, $key)
public static function exists($array, $key) : bool
{
if ($array instanceof ArrayAccess) {
return $array->offsetExists($key);
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function last($array, callable $callback = null, $default = null)
* @param int $depth
* @return array
*/
public static function flatten($array, $depth = INF)
public static function flatten(array $array, $depth = INF) : array
{
return array_reduce($array, function ($result, $item) use ($depth) {
$item = $item instanceof Collection ? $item->all() : $item;
Expand All @@ -198,7 +198,7 @@ public static function flatten($array, $depth = INF)
* @param array|string $keys
* @return void
*/
public static function forget(&$array, $keys)
public static function forget(array &$array, $keys)
{
$original = &$array;

Expand Down Expand Up @@ -275,7 +275,7 @@ public static function get($array, $key, $default = null)
* @param string|array $keys
* @return bool
*/
public static function has($array, $keys)
public static function has($array, $keys) : bool
{
if (is_null($keys)) {
return false;
Expand Down Expand Up @@ -318,7 +318,7 @@ public static function has($array, $keys)
* @param array $array
* @return bool
*/
public static function isAssoc(array $array)
public static function isAssoc(array $array) : bool
{
$keys = array_keys($array);

Expand All @@ -332,7 +332,7 @@ public static function isAssoc(array $array)
* @param array|string $keys
* @return array
*/
public static function only($array, $keys)
public static function only(array $array, $keys) : array
{
return array_intersect_key($array, array_flip((array) $keys));
}
Expand All @@ -345,7 +345,7 @@ public static function only($array, $keys)
* @param string|array|null $key
* @return array
*/
public static function pluck($array, $value, $key = null)
public static function pluck(array $array, $value, $key = null) : array
{
$results = [];

Expand Down Expand Up @@ -376,7 +376,7 @@ public static function pluck($array, $value, $key = null)
* @param string|array|null $key
* @return array
*/
protected static function explodePluckParameters($value, $key)
protected static function explodePluckParameters($value, $key) : array
{
$value = is_string($value) ? explode('.', $value) : $value;

Expand All @@ -393,7 +393,7 @@ protected static function explodePluckParameters($value, $key)
* @param mixed $key
* @return array
*/
public static function prepend($array, $value, $key = null)
public static function prepend(array $array, $value, $key = null) : array
{
if (is_null($key)) {
array_unshift($array, $value);
Expand All @@ -412,7 +412,7 @@ public static function prepend($array, $value, $key = null)
* @param mixed $default
* @return mixed
*/
public static function pull(&$array, $key, $default = null)
public static function pull(array &$array, string $key, $default = null)
{
$value = static::get($array, $key, $default);

Expand All @@ -431,7 +431,7 @@ public static function pull(&$array, $key, $default = null)
* @param mixed $value
* @return array
*/
public static function set(&$array, $key, $value)
public static function set(array &$array, $key, $value) : array
{
if (is_null($key)) {
return $array = $value;
Expand Down Expand Up @@ -463,7 +463,7 @@ public static function set(&$array, $key, $value)
* @param array $array
* @return array
*/
public static function shuffle($array)
public static function shuffle(array $array) : array
{
shuffle($array);

Expand All @@ -477,7 +477,7 @@ public static function shuffle($array)
* @param callable|string $callback
* @return array
*/
public static function sort($array, $callback)
public static function sort(array $array, $callback) : array
{
return Collection::make($array)->sortBy($callback)->all();
}
Expand All @@ -488,7 +488,7 @@ public static function sort($array, $callback)
* @param array $array
* @return array
*/
public static function sortRecursive($array)
public static function sortRecursive(array $array) : array
{
foreach ($array as &$value) {
if (is_array($value)) {
Expand All @@ -512,7 +512,7 @@ public static function sortRecursive($array)
* @param callable $callback
* @return array
*/
public static function where($array, callable $callback)
public static function where(array $array, callable $callback) : array
{
return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
}
Expand Down