Skip to content

Commit 98a23c8

Browse files
committed
Add PhpStan type annotations
1 parent 68ad0fd commit 98a23c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+679
-329
lines changed

src/Functional/Ary.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@
1111
namespace Functional;
1212

1313
use Functional\Exceptions\InvalidArgumentException;
14-
use Traversable;
1514

1615
/**
1716
* Call $func with only abs($count) arguments, taken either from the
1817
* left or right depending on the sign
18+
*
19+
* @template V
20+
* @template T
21+
*
22+
* @param callable(T...):V $func
23+
* @param non-zero-int $count
24+
*
25+
* @return callable(T...):V
26+
*
1927
* @no-named-arguments
2028
*/
2129
function ary(callable $func, int $count): callable

src/Functional/Average.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
namespace Functional;
1212

1313
use Functional\Exceptions\InvalidArgumentException;
14-
use Traversable;
1514

1615
/**
1716
* Returns the average of all numeric values in the array or null if no numeric value was found
1817
*
19-
* @param Traversable|array $collection
20-
* @return null|float|int
18+
* @param iterable<mixed> $collection
19+
*
20+
* @return ($collection is iterable<int> ? float|int : (
21+
* $collection is iterable<float> ? float : (
22+
* $collection is iterable<int|float|numeric-string> ? float|int : null
23+
* )
24+
* ))
25+
*
2126
* @no-named-arguments
2227
*/
2328
function average($collection)

src/Functional/ButLast.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
namespace Functional;
1212

1313
use Functional\Exceptions\InvalidArgumentException;
14-
use Traversable;
1514

1615
/**
1716
* Returns an array containing the elements of the list without its last element.
1817
*
19-
* @param Traversable|array $collection
20-
* @return array
18+
* @template T
19+
*
20+
* @param iterable<T> $collection
21+
*
22+
* @return iterable<T>
23+
*
2124
* @no-named-arguments
2225
*/
2326
function but_last($collection)

src/Functional/Capture.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
namespace Functional;
1212

1313
/**
14-
* Return a new function that captures the return value of $callback in $result and returns the callbacks return value
14+
* Return a new function that captures the return value of $callback in $result and returns the callback's return value
15+
*
16+
* @template T
17+
*
18+
* @param callable():T $callback
19+
* @param T $result
20+
*
21+
* @return callable():T
1522
*
16-
* @param callable $callback
17-
* @param mixed $result
18-
* @return callable
1923
* @no-named-arguments
2024
*/
2125
function capture(callable $callback, &$result)

src/Functional/CompareObjectHashOn.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
/**
1414
* Returns a comparison function that can be used with e.g. `usort()`
1515
*
16-
* @param callable $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
17-
* @param callable $keyFunction A function that takes an argument and returns the value that should be compared
18-
* @return callable
16+
* @template V
17+
* @template R of int
18+
*
19+
* @param callable(string,string):R $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
20+
* @param null|callable(V):string $keyFunction A function that takes an argument and returns the value that should be compared
21+
*
22+
* @return callable(object,object):R
23+
*
1924
* @no-named-arguments
2025
*/
2126
function compare_object_hash_on(callable $comparison, callable $keyFunction = null)

src/Functional/CompareOn.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@
1313
/**
1414
* Returns a comparison function that can be used with e.g. `usort()`
1515
*
16-
* @param callable $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
17-
* @param callable $reducer A function that takes an argument and returns the value that should be compared
18-
* @return callable
16+
* @template V
17+
* @template V2
18+
* @template R of int
19+
*
20+
* @param callable(V,V):R $comparison A function that compares the two values. Pick e.g. strcmp() or strnatcasecmp()
21+
* @param null|callable(V2):V $reducer A function that takes an argument and returns the value that should be compared
22+
*
23+
* @return ($reducer is null ? callable(V,V):R : callable(V2,V2):R)
24+
*
1925
* @no-named-arguments
2026
*/
2127
function compare_on(callable $comparison, callable $reducer = null)

src/Functional/Concat.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
/**
1414
* Concatenates zero or more strings
1515
*
16-
* @param string[] ...$strings
16+
* @param string ...$strings
17+
*
1718
* @return string
19+
*
1820
* @no-named-arguments
1921
*/
20-
function concat(string ...$strings)
22+
function concat(...$strings)
2123
{
2224
return \implode('', $strings);
2325
}

src/Functional/ConstFunction.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
/**
1414
* Wrap value within a function, which will return it, without any modifications.
1515
*
16-
* @param mixed $value
17-
* @return callable
16+
* @template V
17+
*
18+
* @param V $value
19+
*
20+
* @return callable():V
21+
*
1822
* @no-named-arguments
1923
*/
2024
function const_function($value)

src/Functional/Contains.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@
1111
namespace Functional;
1212

1313
use Functional\Exceptions\InvalidArgumentException;
14-
use Traversable;
1514

1615
/**
1716
* Returns true if the collection contains the given value. If the third parameter is
1817
* true values will be compared in strict mode
1918
*
20-
* @param Traversable|array $collection
21-
* @param mixed $value
19+
* @template V
20+
* @template V2 of V
21+
*
22+
* @param iterable<V> $collection
23+
* @param V2 $value
2224
* @param bool $strict
25+
*
2326
* @return bool
27+
*
2428
* @no-named-arguments
2529
*/
2630
function contains($collection, $value, $strict = true)

src/Functional/Converge.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
* The results of each branching function are passed as arguments
1717
* to the converging function to produce the return value.
1818
*
19-
* @param callable $convergingFunction Will be invoked with the return values of all branching functions as its arguments
20-
* @param callable[] $branchingFunctions A list of functions
21-
* @return callable A flipped version of the given function
19+
* @template V
20+
* @template R
21+
* @template R2
22+
*
23+
* @param callable(R...):R2 $convergingFunction Will be invoked with the return values of all branching functions as its arguments
24+
* @param array<callable(V):R> $branchingFunctions A list of functions
25+
*
26+
* @return callable(V...):R2 A flipped version of the given function
27+
*
2228
* @no-named-arguments
2329
*/
2430
function converge($convergingFunction, array $branchingFunctions)

0 commit comments

Comments
 (0)