From 6b3247909e037f218cca624c561d8a47ceeed6d2 Mon Sep 17 00:00:00 2001 From: Alexander Prokhorov Date: Wed, 8 May 2013 16:59:02 +0400 Subject: [PATCH] Replaced "callback" with "callable", and "Closure" with "\Closure" (PhpStorm likes them more) --- YaLinqo/Enumerable.php | 133 +++++++++++++++++----------------- YaLinqo/Enumerator.php | 6 +- YaLinqo/Functions.php | 16 ++-- YaLinqo/OrderedEnumerable.php | 20 ++--- YaLinqo/Utils.php | 6 +- 5 files changed, 91 insertions(+), 90 deletions(-) diff --git a/YaLinqo/Enumerable.php b/YaLinqo/Enumerable.php index d682914..365e009 100644 --- a/YaLinqo/Enumerable.php +++ b/YaLinqo/Enumerable.php @@ -34,7 +34,7 @@ class Enumerable implements \IteratorAggregate /** * @internal - * @param Closure $iterator + * @param \Closure $iterator */ private function __construct ($iterator) { @@ -137,9 +137,9 @@ public static function from ($source) *

Syntax: generate (funcValue {{(v, k) ==> value} [, seedValue [, funcKey {{(v, k) ==> key} [, seedKey]]]) *

Generates a sequence by mimicking a for loop. *

If seedValue is null, the first value will be the result of calling funcValue on seedValue and seedKey. The same applies for seedKey. - * @param callback $funcValue {(v, k) ==> value} State update function to run on value after every iteration of the generator loop. Default: value. + * @param callable $funcValue {(v, k) ==> value} State update function to run on value after every iteration of the generator loop. Default: value. * @param mixed $seedValue Initial state of the generator loop for values. Default: null. - * @param callback|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment. + * @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment. * @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0. * @return Enumerable */ @@ -334,7 +334,7 @@ public static function split ($subject, $pattern, $flags = 0) *

Syntax: ofType (type) *

Filters the elements of a sequence based on a specified type. *

The ofType method returns only those elements in source that can be cast to the specified type. To instead receive an exception if an element cannot be cast, use {@link cast}. - * @param string $type The type to filter the elements of the sequence on. Can be either class name or one of the predefined types: array, int (integer, long), callable (callback), float (real, double), null, string, object, numeric, scalar. + * @param string $type The type to filter the elements of the sequence on. Can be either class name or one of the predefined types: array, int (integer, long), callable (callable), float (real, double), null, string, object, numeric, scalar. * @return Enumerable A sequence that contains elements from the input sequence of the specified type. */ public function ofType ($type) @@ -372,8 +372,8 @@ public function ofType ($type) *

Syntax: select (selectorValue {{(v, k) ==> result} [, selectorKey {{(v, k) ==> result}]) *

Projects each element of a sequence into a new form. *

This projection method requires the transform functions, selectorValue and selectorKey, to produce one key-value pair for each value in the source sequence. If selectorValue returns a value that is itself a collection, it is up to the consumer to traverse the subsequences manually. In such a situation, it might be better for your query to return a single coalesced sequence of values. To achieve this, use the {@link selectMany()} method instead of select. Although selectMany works similarly to select, it differs in that the transform function returns a collection that is then expanded by selectMany before it is returned. - * @param callback $selectorValue {(v, k) ==> value} A transform function to apply to each value. - * @param callback|null $selectorKey {(v, k) ==> key} A transform function to apply to each key. Default: key. + * @param callable $selectorValue {(v, k) ==> value} A transform function to apply to each value. + * @param callable|null $selectorKey {(v, k) ==> key} A transform function to apply to each key. Default: key. * @return Enumerable A sequence whose elements are the result of invoking the transform functions on each element of source. */ public function select ($selectorValue, $selectorKey = null) @@ -410,9 +410,9 @@ public function select ($selectorValue, $selectorKey = null) *

Syntax: selectMany (collectionSelector {{(v, k) ==> enum} [, resultSelectorValue {{(v, k1, k2) ==> value} [, resultSelectorKey {{(v, k1, k2) ==> key}]]) *

Projects each element of a sequence to a sequence, flattens the resulting sequences into one sequence, and invokes a result selector functions on each element therein. *

The selectMany method is useful when you have to keep the elements of source in scope for query logic that occurs after the call to selectMany. If there is a bidirectional relationship between objects in the source sequence and objects returned from collectionSelector, that is, if a sequence returned from collectionSelector provides a property to retrieve the object that produced it, you do not need this overload of selectMany. Instead, you can use simpler selectMany overload and navigate back to the source object through the returned sequence. - * @param callback $collectionSelector {(v, k) ==> enum} A transform function to apply to each element. - * @param callback|null $resultSelectorValue {(v, k1, k2) ==> value} A transform function to apply to each value of the intermediate sequence. Default: {(v, k1, k2) ==> v}. - * @param callback|null $resultSelectorKey {(v, k1, k2) ==> key} A transform function to apply to each key of the intermediate sequence. Default: increment. + * @param callable $collectionSelector {(v, k) ==> enum} A transform function to apply to each element. + * @param callable|null $resultSelectorValue {(v, k1, k2) ==> value} A transform function to apply to each value of the intermediate sequence. Default: {(v, k1, k2) ==> v}. + * @param callable|null $resultSelectorKey {(v, k1, k2) ==> key} A transform function to apply to each key of the intermediate sequence. Default: increment. * @return Enumerable A sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. */ public function selectMany ($collectionSelector, $resultSelectorValue = null, $resultSelectorKey = null) @@ -454,7 +454,7 @@ public function selectMany ($collectionSelector, $resultSelectorValue = null, $r /** *

Syntax: where (predicate {{(v, k) ==> result}) *

Filters a sequence of values based on a predicate. - * @param callback $predicate {(v, k) ==> result} A function to test each element for a condition. + * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. * @return Enumerable A sequence that contains elements from the input sequence that satisfy the condition. */ public function where ($predicate) @@ -497,8 +497,8 @@ public function where ($predicate) *

Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. * @param bool $desc A direction in which to order the elements: false for ascending (by increasing value), true for descending (by decreasing value). - * @param callback|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return OrderedEnumerable */ public function orderByDir ($desc, $keySelector = null, $comparer = null) @@ -514,8 +514,8 @@ public function orderByDir ($desc, $keySelector = null, $comparer = null) *

Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. *

Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. - * @param callback|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return OrderedEnumerable */ public function orderBy ($keySelector = null, $comparer = null) @@ -529,8 +529,8 @@ public function orderBy ($keySelector = null, $comparer = null) *

Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. *

Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. - * @param callback|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable|null $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return OrderedEnumerable */ public function orderByDescending ($keySelector = null, $comparer = null) @@ -549,10 +549,10 @@ public function orderByDescending ($keySelector = null, $comparer = null) *

The resultSelectorValue and resultSelectorKey functions are called only one time for each outer element together with a collection of all the inner elements that match the outer element. This differs from the {@link join} method, in which the result selector function is invoked on pairs that contain one element from outer and one element from inner. GroupJoin preserves the order of the elements of outer, and for each element of outer, the order of the matching elements from inner. *

GroupJoin has no direct equivalent in traditional relational database terms. However, this method does implement a superset of inner joins and left outer joins. Both of these operations can be written in terms of a grouped join. * @param array|\Iterator|\IteratorAggregate|Enumerable $inner The second (inner) sequence to join to the first (source, outer) sequence. - * @param callback|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the first sequence. Default: key. - * @param callback|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. - * @param callback|null $resultSelectorValue {(v, e, k) ==> value} A function to create a result value from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> array(v, e)}. - * @param callback|null $resultSelectorKey {(v, e, k) ==> key} A function to create a result key from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). + * @param callable|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the first sequence. Default: key. + * @param callable|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. + * @param callable|null $resultSelectorValue {(v, e, k) ==> value} A function to create a result value from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> array(v, e)}. + * @param callable|null $resultSelectorKey {(v, e, k) ==> key} A function to create a result key from an element from the first sequence and a collection of matching elements from the second sequence. Default: {(v, e, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). * @return Enumerable A sequence that contains elements that are obtained by performing a grouped join on two sequences. */ public function groupJoin ($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null) @@ -596,10 +596,10 @@ public function groupJoin ($inner, $outerKeySelector = null, $innerKeySelector = *

Join preserves the order of the elements of the source, and for each of these elements, the order of the matching elements of inner. *

In relational database terms, the Join method implements an inner equijoin. 'Inner' means that only elements that have a match in the other sequence are included in the results. An 'equijoin' is a join in which the keys are compared for equality. A left outer join operation has no dedicated standard query operator, but can be performed by using the {@link groupJoin} method. * @param array|\Iterator|\IteratorAggregate|Enumerable $inner The sequence to join to the source sequence. - * @param callback|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the source sequence. Default: key. - * @param callback|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. - * @param callback|null $resultSelectorValue {(v1, v2, k) ==> result} A function to create a result value from two matching elements. Default: {(v1, v2, k) ==> array(v1, v2)}. - * @param callback|null $resultSelectorKey {(v1, v2, k) ==> result} A function to create a result key from two matching elements. Default: {(v1, v2, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). + * @param callable|null $outerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the source sequence. Default: key. + * @param callable|null $innerKeySelector {(v, k) ==> key} A function to extract the join key from each element of the second sequence. Default: key. + * @param callable|null $resultSelectorValue {(v1, v2, k) ==> result} A function to create a result value from two matching elements. Default: {(v1, v2, k) ==> array(v1, v2)}. + * @param callable|null $resultSelectorKey {(v1, v2, k) ==> result} A function to create a result key from two matching elements. Default: {(v1, v2, k) ==> k} (keys returned by outerKeySelector and innerKeySelector functions). * @return Enumerable */ public function join ($inner, $outerKeySelector = null, $innerKeySelector = null, $resultSelectorValue = null, $resultSelectorKey = null) @@ -617,6 +617,7 @@ public function join ($inner, $outerKeySelector = null, $innerKeySelector = null { /** @var $self Enumerable */ /** @var $inner Enumerable */ + /** @var $arrIn array */ $itOut = $self->getIterator(); $itOut->rewind(); $lookup = $inner->toLookup($innerKeySelector); @@ -655,10 +656,10 @@ public function join ($inner, $outerKeySelector = null, $innerKeySelector = null *

Syntax: groupBy (keySelector {{(v, k) ==> key}, valueSelector {{(v, k) ==> value}, resultSelectorValue {{(e, k) ==> value} [, resultSelectorKey {{(e, k) ==> key}]) *

Groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. *

For all overloads except the last: the groupBy method returns a sequence of sequences, one inner sequence for each distinct key that was encountered. The outer sequence is yielded in an order based on the order of the elements in source that produced the first key of each inner sequence. Elements in a inner sequence are yielded in the order they appear in source. - * @param callback|null $keySelector {(v, k) ==> key} A function to extract the key for each element. Default: key. - * @param callback|null $valueSelector {(v, k) ==> value} A function to map each source element to a value in the inner sequence. - * @param callback|null $resultSelectorValue {(e, k) ==> value} A function to create a result value from each group. - * @param callback|null $resultSelectorKey {(e, k) ==> key} A function to create a result key from each group. + * @param callable|null $keySelector {(v, k) ==> key} A function to extract the key for each element. Default: key. + * @param callable|null $valueSelector {(v, k) ==> value} A function to map each source element to a value in the inner sequence. + * @param callable|null $resultSelectorValue {(e, k) ==> value} A function to create a result value from each group. + * @param callable|null $resultSelectorKey {(e, k) ==> key} A function to create a result key from each group. * @return Enumerable A sequence of sequences indexed by a key. */ public function groupBy ($keySelector = null, $valueSelector = null, $resultSelectorValue = null, $resultSelectorKey = null) @@ -681,7 +682,7 @@ public function groupBy ($keySelector = null, $valueSelector = null, $resultSele *

Applies an accumulator function over a sequence. If seed is not null, its value is used as the initial accumulator value. *

Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). If seed is null, the first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func. *

To simplify common aggregation operations, the standard query operators also include a general purpose count method, {@link count}, and four numeric aggregation methods, namely {@link min}, {@link max}, {@link sum}, and {@link average}. - * @param callback $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. + * @param callable $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. * @param mixed $seed If seed is not null, the first element is used as seed. Default: null. * @throws \UnexpectedValueException If seed is null and sequence contains no elements. * @return mixed The final accumulator value. @@ -718,7 +719,7 @@ public function aggregate ($func, $seed = null) *

Applies an accumulator function over a sequence. If seed is not null, its value is used as the initial accumulator value. *

Aggregate method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, aggregate passes both the element from the sequence and an aggregated value (as the first argument to func). If seed is null, the first element of source is used as the initial aggregate value. The result of func replaces the previous aggregated value. Aggregate returns the final result of func. If source sequence is empty, default is returned. *

To simplify common aggregation operations, the standard query operators also include a general purpose count method, {@link count}, and four numeric aggregation methods, namely {@link min}, {@link max}, {@link sum}, and {@link average}. - * @param callback $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. + * @param callable $func {(a, v, k) ==> accum} An accumulator function to be invoked on each element. * @param mixed $seed If seed is not null, the first element is used as seed. Default: null. * @param mixed $default Value to return if sequence is empty. Default: null. * @return mixed The final accumulator value, or default if sequence is empty. @@ -754,7 +755,7 @@ public function aggregateOrDefault ($func, $seed = null, $default = null) *

Computes the average of a sequence of numeric values. *

Syntax: average (selector {{(v, k) ==> result}) *

Computes the average of a sequence of numeric values that are obtained by invoking a transform function on each element of the input sequence. - * @param callback|null $selector {(v, k) ==> result} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> result} A transform function to apply to each element. Default: value. * @throws \UnexpectedValueException If sequence contains no elements. * @return number The average of the sequence of values. */ @@ -778,7 +779,7 @@ public function average ($selector = null) *

If source iterator implements {@link Countable}, that implementation is used to obtain the count of elements. Otherwise, this method determines the count. *

Syntax: count (predicate {{(v, k) ==> result}) *

Returns a number that represents how many elements in the specified sequence satisfy a condition. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. * @return int The number of elements in the input sequence. */ public function count ($predicate = null) @@ -802,7 +803,7 @@ public function count ($predicate = null) *

Returns the maximum value in a sequence of values. *

Syntax: max (selector {{(v, k) ==> value}) *

Invokes a transform function on each element of a sequence and returns the maximum value. - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @throws \UnexpectedValueException If sequence contains no elements. * @return number The maximum value in the sequence. */ @@ -819,8 +820,8 @@ public function max ($selector = null) *

Returns the maximum value in a sequence of values, using specified comparer. *

Syntax: maxBy (comparer {{(a, b) ==> diff}, selector {{(v, k) ==> value}) *

Invokes a transform function on each element of a sequence and returns the maximum value, using specified comparer. - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @throws \UnexpectedValueException If sequence contains no elements. * @return number The maximum value in the sequence. */ @@ -840,7 +841,7 @@ public function maxBy ($comparer, $selector = null) *

Returns the minimum value in a sequence of values. *

Syntax: min (selector {{(v, k) ==> value}) *

Invokes a transform function on each element of a sequence and returns the minimum value. - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @throws \UnexpectedValueException If sequence contains no elements. * @return number The minimum value in the sequence. */ @@ -857,8 +858,8 @@ public function min ($selector = null) *

Returns the minimum value in a sequence of values, using specified comparer. *

Syntax: minBy (comparer {{(a, b) ==> diff}, selector {{(v, k) ==> value}) *

Invokes a transform function on each element of a sequence and returns the minimum value, using specified comparer. - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @throws \UnexpectedValueException If sequence contains no elements. * @return number The minimum value in the sequence. */ @@ -879,7 +880,7 @@ public function minBy ($comparer, $selector = null) *

Syntax: sum (selector {{(v, k) ==> result}) *

Computes the sum of the sequence of values that are obtained by invoking a transform function on each element of the input sequence. *

This method returns zero if source contains no elements. - * @param callback|null $selector {(v, k) ==> result} A transform function to apply to each element. + * @param callable|null $selector {(v, k) ==> result} A transform function to apply to each element. * @return number The sum of the values in the sequence. */ public function sum ($selector = null) @@ -897,7 +898,7 @@ public function sum ($selector = null) /** *

Syntax: all (predicate {{(v, k) ==> result}) *

Determines whether all elements of a sequence satisfy a condition. The enumeration of source is stopped as soon as the result can be determined. - * @param callback $predicate {(v, k) ==> result} A function to test each element for a condition. + * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. * @return bool true if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false. */ public function all ($predicate) @@ -916,7 +917,7 @@ public function all ($predicate) *

Determines whether a sequence contains any elements. The enumeration of source is stopped as soon as the result can be determined. *

Syntax: any (predicate {{(v, k) ==> result}) *

Determines whether any element of a sequence exists or satisfies a condition. The enumeration of source is stopped as soon as the result can be determined. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: null. * @return bool If predicate is null: true if the source sequence contains any elements; otherwise, false. If predicate is not null: true if any elements in the source sequence pass the test in the specified predicate; otherwise, false. */ public function any ($predicate = null) @@ -959,7 +960,7 @@ public function contains ($value) *

Returns distinct elements from a sequence. *

Syntax: distinct (selector {{(v, k) ==> value}) *

Invokes a transform function on each element of a sequence and returns distinct elements. - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @return Enumerable A sequence that contains distinct elements of the input sequence. */ public function distinct ($selector = null) @@ -1037,7 +1038,7 @@ public function elementAtOrDefault ($key, $default = null) *

Syntax: first (predicate {{(v, k) ==> result}) *

Returns the first element in a sequence that satisfies a specified condition. *

The first method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the {@link firstOrDefault} method. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @throws \UnexpectedValueException If source contains no matching elements. * @return mixed If predicate is null: the first element in the specified sequence. If predicate is not null: The first element in the sequence that passes the test in the specified predicate function. */ @@ -1059,7 +1060,7 @@ public function first ($predicate = null) *

Returns the first element of the sequence that satisfies a condition or a default value if no such element is found. *

If obtaining the default value is a costly operation, use {@link firstOrFallback} method to avoid overhead. * @param mixed $default A default value. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @return mixed If predicate is null: default value if source is empty; otherwise, the first element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. */ public function firstOrDefault ($default = null, $predicate = null) @@ -1080,7 +1081,7 @@ public function firstOrDefault ($default = null, $predicate = null) *

Returns the first element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found. *

The fallback function is not executed if a matching element is found. Use the firstOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use {@link firstOrDefault}. * @param mixed $fallback A fallback function to return the default element. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the first element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate. */ public function firstOrFallback ($fallback, $predicate = null) @@ -1101,7 +1102,7 @@ public function firstOrFallback ($fallback, $predicate = null) *

Syntax: last (predicate {{(v, k) ==> result}) *

Returns the last element in a sequence that satisfies a specified condition. *

The last method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the {@link lastOrDefault} method. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @throws \UnexpectedValueException If source contains no matching elements. * @return mixed If predicate is null: the last element in the specified sequence. If predicate is not null: The last element in the sequence that passes the test in the specified predicate function. */ @@ -1129,7 +1130,7 @@ public function last ($predicate = null) *

Returns the last element of the sequence that satisfies a condition or a default value if no such element is found. *

If obtaining the default value is a costly operation, use {@link lastOrFallback} method to avoid overhead. * @param mixed $default A default value. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @return mixed If predicate is null: default value if source is empty; otherwise, the last element in source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate. */ public function lastOrDefault ($default = null, $predicate = null) @@ -1154,7 +1155,7 @@ public function lastOrDefault ($default = null, $predicate = null) *

Returns the last element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found. *

The fallback function is not executed if a matching element is found. Use the lastOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use {@link lastOrDefault}. * @param mixed $fallback A fallback function to return the default element. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the last element in source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate. */ public function lastOrFallback ($fallback, $predicate = null) @@ -1179,7 +1180,7 @@ public function lastOrFallback ($fallback, $predicate = null) *

Syntax: single (predicate {{(v, k) ==> result}) *

Returns the only element of a sequence that satisfies a specified condition. *

The single method throws an exception if no matching element is found in source. To instead return a default value when no matching element is found, use the {@link singleOrDefault} method. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @throws \UnexpectedValueException If source contains no matching elements or more than one matching element. * @return mixed If predicate is null: the single element of the input sequence. If predicate is not null: The single element of the sequence that passes the test in the specified predicate function. */ @@ -1209,7 +1210,7 @@ public function single ($predicate = null) *

Returns the only element of the sequence that satisfies a condition or a default value if no such element is found. *

If obtaining the default value is a costly operation, use {@link singleOrFallback} method to avoid overhead. * @param mixed $default A default value. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @throws \UnexpectedValueException If source contains more than one matching element. * @return mixed If predicate is null: default value if source is empty; otherwise, the single element of the source. If predicate is not null: default value if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate. */ @@ -1237,7 +1238,7 @@ public function singleOrDefault ($default = null, $predicate = null) *

Returns the only element of the sequence that satisfies a condition or the result of calling a fallback function if no such element is found. *

The fallback function is not executed if a matching element is found. Use the singleOrFallback method if obtaining the default value is a costly operation to avoid overhead. Otherwise, use {@link singleOrDefault}. * @param mixed $fallback A fallback function to return the default element. - * @param callback|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. + * @param callable|null $predicate {(v, k) ==> result} A function to test each element for a condition. Default: true. * @throws \UnexpectedValueException If source contains more than one matching element. * @return mixed If predicate is null: the result of calling a fallback function if source is empty; otherwise, the single element of the source. If predicate is not null: the result of calling a fallback function if source is empty or if no element passes the test specified by predicate; otherwise, the single element of the source that passes the test specified by predicate. */ @@ -1295,7 +1296,7 @@ public function lastIndexOf ($value) *

Syntax: findIndex (predicate {{(v, k) ==> result}) *

Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the first occurrence. *

To search for the zero-based index of the first occurence, call {@link toValues} method first. - * @param callback $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. + * @param callable $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. * @return mixed The key of the first occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. */ public function findIndex ($predicate) @@ -1313,7 +1314,7 @@ public function findIndex ($predicate) *

Syntax: findLastIndex (predicate {{(v, k) ==> result}) *

Searches for an element that matches the conditions defined by the specified predicate, and returns the key of the last occurrence. *

To search for the zero-based index of the last occurence, call {@link toValues} method first. - * @param callback $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. + * @param callable $predicate {(v, k) ==> result} A function that defines the conditions of the element to search for. * @return mixed The key of the last occurrence of an element that matches the conditions defined by predicate, if found; otherwise, null. */ public function findLastIndex ($predicate) @@ -1365,7 +1366,7 @@ public function skip ($count) *

Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. *

This method tests each element of source by using predicate and skips the element if the result is true. After the predicate function returns false for an element, that element and the remaining elements in source are yielded and there are no more invocations of predicate. If predicate returns true for all elements in the sequence, an empty sequence is returned. *

The {@link takeWhile} and skipWhile methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll. - * @param callback $predicate {(v, k) ==> result} A function to test each element for a condition. + * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. * @return Enumerable A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate. */ public function skipWhile ($predicate) @@ -1432,7 +1433,7 @@ public function take ($count) *

Returns elements from a sequence as long as a specified condition is true. *

The takeWhile method tests each element of source by using predicate and yields the element if the result is true. Enumeration stops when the predicate function returns false for an element or when source contains no more elements. *

The takeWhile and {@link skipWhile} methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll. - * @param callback $predicate {(v, k) ==> result} A function to test each element for a condition. + * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition. * @return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes. */ public function takeWhile ($predicate) @@ -1550,8 +1551,8 @@ protected function toListDeepProc ($enum) *

Syntax: toDictionary ([keySelector {{(v, k) ==> key} [, valueSelector {{(v, k) ==> value}]]) *

Creates a {@link Dictionary} from a sequence according to specified key selector and value selector functions. *

The toDictionary method returns a Dictionary, a one-to-one dictionary that maps keys to values. If the source sequence contains multiple values with the same key, the result dictionary will only contain the latter value. - * @param callback|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. - * @param callback|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. + * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. + * @param callable|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. * @return collections\Dictionary A Dictionary that contains values selected from the input sequence. */ public function toDictionary ($keySelector = null, $valueSelector = null) @@ -1582,8 +1583,8 @@ public function toJSON ($options = 0) *

Syntax: toLookup ([keySelector {{(v, k) ==> key} [, valueSelector {{(v, k) ==> value}]]) *

Creates a {@link Lookup} from a sequence according to specified key selector and value selector functions. *

The toLookup method returns a Lookup, a one-to-many dictionary that maps keys to collections of values. - * @param callback|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. - * @param callback|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. + * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from each element. Default: key. + * @param callable|null $valueSelector {(v, k) ==> value} A transform function to produce a result value from each element. Default: value. * @return collections\Lookup A Lookup that contains values selected from the input sequence. */ public function toLookup ($keySelector = null, $valueSelector = null) @@ -1622,8 +1623,8 @@ public function toValues () /** *

Syntax: toObject ([propertySelector {{(v, k) ==> name} [, valueSelector {{(v, k) ==> value}]]) *

Transform the sequence to an object. - * @param callback|null $propertySelector {(v, k) ==> name} A function to extract a property name from an element. Must return a valid PHP identifier. Default: key. - * @param callback|null $valueSelector {(v, k) ==> value} A function to extract a property value from an element. Default: value. + * @param callable|null $propertySelector {(v, k) ==> name} A function to extract a property name from an element. Must return a valid PHP identifier. Default: key. + * @param callable|null $valueSelector {(v, k) ==> value} A function to extract a property value from an element. Default: value. * @return \stdClass */ public function toObject ($propertySelector = null, $valueSelector = null) @@ -1641,7 +1642,7 @@ public function toObject ($propertySelector = null, $valueSelector = null) *

Syntax: toString ([separator [, selector]]) *

Returns a string containing a string representation of all the sequence values, with the separator string between each element. * @param string $separator A string separating values in the result string. Default: ''. - * @param callback|null $valueSelector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $valueSelector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @return string * @see implode */ @@ -1661,7 +1662,7 @@ public function toString ($separator = '', $valueSelector = null) *

Invokes an action for each element in the sequence. *

Process method does not start enumeration itself. To force enumeration, you can use {@link each} method. *

Original LINQ method name: do. - * @param callback $action The action to invoke for each element in the sequence. + * @param callable $action The action to invoke for each element in the sequence. * @return Enumerable The source sequence with the side-effecting behavior applied. */ public function call ($action) @@ -1693,7 +1694,7 @@ public function call ($action) *

Invokes an action for each element in the sequence. *

Each method forces enumeration. To just add side-effect without enumerating, you can use {@link process} method. *

Original LINQ method name: foreach. - * @param callback $action The action to invoke for each element in the sequence. + * @param callable $action The action to invoke for each element in the sequence. */ public function each ($action = null) { @@ -1707,7 +1708,7 @@ public function each ($action = null) *

Syntax: write ([separator [, selector]]) *

Output the result of calling {@link toString} method. * @param string $separator A string separating values in the result string. Default: ''. - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @see implode, echo */ public function write ($separator = '', $selector = null) @@ -1718,7 +1719,7 @@ public function write ($separator = '', $selector = null) /** *

Syntax: writeLine ([selector]) *

Output all the sequence values, with a new line after each element. - * @param callback|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. + * @param callable|null $selector {(v, k) ==> value} A transform function to apply to each element. Default: value. * @return string * @see echo, PHP_EOL */ diff --git a/YaLinqo/Enumerator.php b/YaLinqo/Enumerator.php index ce3f864..b88bb0a 100644 --- a/YaLinqo/Enumerator.php +++ b/YaLinqo/Enumerator.php @@ -9,9 +9,9 @@ class Enumerator implements \Iterator const STATE_RUNNING = 1; const STATE_AFTER = 2; - /** @var Closure */ + /** @var \Closure */ private $funNext; - /** @var Closure */ + /** @var \Closure */ private $funYield; private $state = self::STATE_RUNNING; private $valid = true; @@ -19,7 +19,7 @@ class Enumerator implements \Iterator public $currentKey = null; /** - * @param Closure $funNext + * @param \Closure $funNext */ public function __construct ($funNext) { diff --git a/YaLinqo/Functions.php b/YaLinqo/Functions.php index 4012299..7647aac 100644 --- a/YaLinqo/Functions.php +++ b/YaLinqo/Functions.php @@ -5,21 +5,21 @@ class Functions { - /** @var callback {(x) ==> x} */ + /** @var callable {(x) ==> x} */ public static $identity; - /** @var callback {(v, k) ==> k} */ + /** @var callable {(v, k) ==> k} */ public static $key; - /** @var callback {(v, k) ==> v} */ + /** @var callable {(v, k) ==> v} */ public static $value; - /** @var callback {() ==> true} */ + /** @var callable {() ==> true} */ public static $true; - /** @var callback {() ==> false} */ + /** @var callable {() ==> false} */ public static $false; - /** @var callback {() ==> {}} */ + /** @var callable {() ==> {}} */ public static $blank; - /** @var callback */ + /** @var callable */ public static $compareStrict; - /** @var callback */ + /** @var callable */ public static $compareLoose; public static function init () diff --git a/YaLinqo/OrderedEnumerable.php b/YaLinqo/OrderedEnumerable.php index f6f5725..702ffc2 100644 --- a/YaLinqo/OrderedEnumerable.php +++ b/YaLinqo/OrderedEnumerable.php @@ -11,17 +11,17 @@ class OrderedEnumerable extends Enumerable private $parent; /** @var bool */ private $desc; - /** @var callback {(v, k) ==> key} */ + /** @var callable {(v, k) ==> key} */ private $keySelector; - /** @var callback {(a, b) ==> diff} */ + /** @var callable {(a, b) ==> diff} */ private $comparer; /** * @internal * @param Enumerable $source - * @param callback $keySelector {(v, k) ==> key} A function to extract a key from an element. + * @param callable $keySelector {(v, k) ==> key} A function to extract a key from an element. * @param bool $desc A direction in which to order the elements: false for ascending (by increasing value), true for descending (by decreasing value). - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @param \YaLinqo\OrderedEnumerable $parent */ public function __construct ($source, $desc, $keySelector, $comparer, $parent = null) @@ -40,8 +40,8 @@ public function __construct ($source, $desc, $keySelector, $comparer, $parent = *

Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. * @param bool $desc A direction in which to order the elements: false for ascending (by increasing value), true for descending (by decreasing value). - * @param callback $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return \YaLinqo\OrderedEnumerable */ public function thenByDir ($desc, $keySelector = null, $comparer = null) @@ -57,8 +57,8 @@ public function thenByDir ($desc, $keySelector = null, $comparer = null) *

Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. *

Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. - * @param callback $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return \YaLinqo\OrderedEnumerable */ public function thenBy ($keySelector = null, $comparer = null) @@ -72,8 +72,8 @@ public function thenBy ($keySelector = null, $comparer = null) *

Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made. *

Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering. *

This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used. - * @param callback $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. - * @param callback $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b + * @param callable $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value. + * @param callable $comparer {(a, b) ==> diff} Difference between a and b: <0 if a<b; 0 if a==b; >0 if a>b * @return \YaLinqo\OrderedEnumerable */ public function thenByDescending ($keySelector = null, $comparer = null) diff --git a/YaLinqo/Utils.php b/YaLinqo/Utils.php index fbaf21f..89a67ed 100644 --- a/YaLinqo/Utils.php +++ b/YaLinqo/Utils.php @@ -9,12 +9,12 @@ class Utils const ERROR_CLOSURE_NOT_CALLABLE = 'closure must be callable'; const ERROR_CANNOT_PARSE_LAMBDA = 'Failed to parse closure as lambda.'; /** - * @param callback|null $closure + * @param callable|null $closure * @param string $closureArgs - * @param Closure|boolean|null $default + * @param \Closure|boolean|null $default * @throws \InvalidArgumentException Both closure and default are null. * @throws \InvalidArgumentException Incorrect lambda syntax. - * @return callback|null + * @return callable|null */ public static function createLambda ($closure, $closureArgs, $default = null) {