Skip to content

Commit

Permalink
Replace Closure type hint with callable
Browse files Browse the repository at this point in the history
  • Loading branch information
bocharsky-bw committed Oct 10, 2015
1 parent c624507 commit 52dcaf0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 39 deletions.
25 changes: 12 additions & 13 deletions src/AbstractArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Arrayzy\Traits\TraversableTrait;
use ArrayAccess;
use ArrayIterator;
use Closure;
use Countable;
use IteratorAggregate;
use Traversable;
Expand Down Expand Up @@ -219,44 +218,44 @@ abstract public function sortKeys($order = SORT_ASC, $strategy = SORT_REGULAR);
/**
* Apply the given function to the array elements
*
* @param Closure $func
* @param callable $func
*
* @return static The instance with modified elements
*/
abstract public function map(Closure $func);
abstract public function map(callable $func);

/**
* Filter array elements with given function
*
* @param Closure $func
* @param callable $func
*
* @return static The instance with filtered elements
*/
abstract public function filter(Closure $func);
abstract public function filter(callable $func);

/**
* Apply the given function to every array element
*
* @param Closure $func
* @param callable $func
* @param bool $recursively Whether array will be walked recursively or no
*
* @return static The instance with modified elements
*/
abstract public function walk(Closure $func, $recursively = false);
abstract public function walk(callable $func, $recursively = false);

/**
* {@inheritdoc}
*
* @link http://php.net/manual/en/function.usort.php
*/
abstract public function customSort(Closure $func);
abstract public function customSort(callable $func);

/**
* {@inheritdoc}
*
* @link http://php.net/manual/en/function.uksort.php
*/
abstract public function customSortKeys(Closure $func);
abstract public function customSortKeys(callable $func);

/**
* Clear array
Expand Down Expand Up @@ -538,12 +537,12 @@ public function getValues()
/**
* Iteratively reduce array to a single value using a function
*
* @param Closure $func
* @param callable $func
* @param mixed|null $initial
*
* @return mixed The resulting value
*/
public function reduce(Closure $func, $initial = null)
public function reduce(callable $func, $initial = null)
{
return array_reduce($this->elements, $func, $initial);
}
Expand Down Expand Up @@ -684,11 +683,11 @@ protected function sortingKeys(array &$elements, $order = SORT_ASC, $strategy =
/**
* Returns the first occurrence of value that matches $func conditions
*
* @param Closure $func
* @param callable $func
*
* @return mixed The first found value occurrence
*/
public function find(Closure $func)
public function find(callable $func)
{
foreach ($this->elements as $key => $value) {
if($func($value, $key)) {
Expand Down
18 changes: 8 additions & 10 deletions src/ImmutableArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Arrayzy;

use Closure;

/**
* Class ImmutableArray
*
Expand Down Expand Up @@ -246,36 +244,36 @@ public function sortKeys($order = SORT_ASC, $strategy = SORT_REGULAR)
/**
* Apply the given function to the array elements
*
* @param Closure $func
* @param callable $func
*
* @return static The new instance with modified elements
*/
public function map(Closure $func)
public function map(callable $func)
{
return new static(array_map($func, $this->elements));
}

/**
* Filter array elements with given function
*
* @param Closure $func
* @param callable $func
*
* @return static The new instance with filtered elements
*/
public function filter(Closure $func)
public function filter(callable $func)
{
return new static(array_filter($this->elements, $func));
}

/**
* Apply the given function to every array element
*
* @param Closure $func
* @param callable $func
* @param bool $recursively Whether array will be walked recursively or no
*
* @return static The new instance with modified elements
*/
public function walk(Closure $func, $recursively = false)
public function walk(callable $func, $recursively = false)
{
$elements = $this->elements;

Expand All @@ -293,7 +291,7 @@ public function walk(Closure $func, $recursively = false)
*
* @link http://php.net/manual/en/function.usort.php
*/
public function customSort(Closure $func)
public function customSort(callable $func)
{
$elements = $this->elements;

Expand All @@ -307,7 +305,7 @@ public function customSort(Closure $func)
*
* @link http://php.net/manual/en/function.uksort.php
*/
public function customSortKeys(Closure $func)
public function customSortKeys(callable $func)
{
$elements = $this->elements;

Expand Down
10 changes: 4 additions & 6 deletions src/Interfaces/SortableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Arrayzy\Interfaces;

use Closure;

/**
* An interface with helpful array sorting methods.
*
Expand Down Expand Up @@ -59,18 +57,18 @@ public function sortKeys($order = SORT_ASC, $strategy = SORT_REGULAR);
/**
* Sorts the array elements with a user-defined comparison function and maintain index association.
*
* @param Closure $func
* @param callable $func
*
* @return SortableInterface The instance with custom sorted elements
*/
public function customSort(Closure $func);
public function customSort(callable $func);

/**
* Sorts the array keys with a user-defined comparison function and maintain index association.
*
* @param Closure $func
* @param callable $func
*
* @return SortableInterface The instance with custom sorted elements
*/
public function customSortKeys(Closure $func);
public function customSortKeys(callable $func);
}
18 changes: 8 additions & 10 deletions src/MutableArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Arrayzy;

use Closure;

/**
* Class MutableArray
*
Expand Down Expand Up @@ -270,11 +268,11 @@ public function sortKeys($order = SORT_ASC, $strategy = SORT_REGULAR)
/**
* Apply the given function to the array elements
*
* @param Closure $func
* @param callable $func
*
* @return $this The same instance with modified elements
*/
public function map(Closure $func)
public function map(callable $func)
{
$this->elements = array_map($func, $this->elements);

Expand All @@ -284,11 +282,11 @@ public function map(Closure $func)
/**
* Filter array elements with given function
*
* @param Closure $func
* @param callable $func
*
* @return $this The same instance with filtered elements
*/
public function filter(Closure $func)
public function filter(callable $func)
{
$this->elements = array_filter($this->elements, $func);

Expand All @@ -298,12 +296,12 @@ public function filter(Closure $func)
/**
* Apply the given function to every array element
*
* @param Closure $func
* @param callable $func
* @param bool $recursively Whether array will be walked recursively or no
*
* @return $this The same instance with modified elements
*/
public function walk(Closure $func, $recursively = false)
public function walk(callable $func, $recursively = false)
{
if (true === $recursively) {
array_walk_recursive($this->elements, $func);
Expand All @@ -319,7 +317,7 @@ public function walk(Closure $func, $recursively = false)
*
* @link http://php.net/manual/en/function.usort.php
*/
public function customSort(Closure $func)
public function customSort(callable $func)
{
usort($this->elements, $func);

Expand All @@ -331,7 +329,7 @@ public function customSort(Closure $func)
*
* @link http://php.net/manual/en/function.uksort.php
*/
public function customSortKeys(Closure $func)
public function customSortKeys(callable $func)
{
uksort($this->elements, $func);

Expand Down

0 comments on commit 52dcaf0

Please sign in to comment.