Skip to content

Commit b9c265b

Browse files
committed
WIP
1 parent 9a86c7f commit b9c265b

Some content is hidden

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

75 files changed

+460
-494
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "~7",
19-
"vimeo/psalm": "^3.7"
19+
"vimeo/psalm": "dev-master"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "~7",

phpunit.xml.dist

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
beStrictAboutOutputDuringTests="true"
3030
verbose="true"
3131
colors="true">
32-
<filter>
33-
<whitelist>
34-
<directory suffix=".php">src/Functional</directory>
35-
</whitelist>
36-
</filter>
3732

3833
<testsuites>
3934
<testsuite name="unit-tests">
@@ -42,8 +37,7 @@
4237
</testsuites>
4338

4439
<logging>
45-
<log type="coverage-html" target="build/coverage"
46-
lowUpperBound="35" highLowerBound="70"/>
40+
<log type="coverage-html" target="build/coverage"/>
4741
<log type="coverage-clover" target="build/logs/clover.xml"/>
4842
<log type="junit" target="build/logs/junit.xml"/>
4943
</logging>
@@ -53,5 +47,4 @@
5347
<ini name="date.timezone" value="UTC"/>
5448
<ini name="display_errors" value="on"/>
5549
</php>
56-
5750
</phpunit>

src/Functional/Average.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
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
18+
* @param iterable<array-key, numeric|mixed> $collection
2019
* @return numeric|null
2120
*/
2221
function average($collection)

src/Functional/ButLast.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
/**
1717
* Returns an array containing the elements of the list without its last element.
1818
*
19-
* @param Traversable|array $collection
20-
* @return array
19+
* @template TKey of array-key
20+
* @template TValue of mixed
21+
* @param iterable<TKey,TValue> $collection
22+
* @return array<TKey, TValue>
2123
*/
2224
function but_last($collection)
2325
{

src/Functional/Capture.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
/**
1414
* Return a new function that captures the return value of $callback in $result and returns the callbacks return value
1515
*
16-
* @param callable $callback
17-
* @param mixed $result
18-
* @return callable
16+
* @template TArg of mixed
17+
* @template TResult of mixed
18+
* @param callable(...TArg): TResult $callback
19+
* @param-out TResult $result
20+
* @return callable(...TArg): TResult
1921
*/
2022
function capture(callable $callback, &$result)
2123
{
22-
return function (...$args) use ($callback, &$result) {
24+
return
25+
/**
26+
* @param TArg $args
27+
* @return TResult
28+
*/
29+
static function (...$args) use ($callback, &$result) {
2330
$result = $callback(...$args);
2431

2532
return $result;

src/Functional/CompareObjectHashOn.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
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 TCompVal of scalar
17+
* @template TObjIn extends object
18+
* @template TObjOut extends object
19+
* @param callable(TCompVal, TCompVal): int $comparison A function that compares the two values. Pick e.g. `strcmp()` or `strnatcasecmp()`
20+
* @param callable(TObjIn): TObjOut $keyFunction A function that takes an argument and returns the value that should be compared
21+
* @return callable(TObjIn, TObjIn): int
1922
*/
2023
function compare_object_hash_on(callable $comparison, callable $keyFunction = null)
2124
{
25+
/** @var callable(TObjIn): scalar $keyFunction */
2226
$keyFunction = $keyFunction ? compose($keyFunction, 'spl_object_hash') : 'spl_object_hash';
2327

28+
/**
29+
* @fixme report issue with psalm
30+
* @var callable(scalar, scalar): int $comparison
31+
*/
32+
2433
return compare_on($comparison, $keyFunction);
2534
}

src/Functional/CompareOn.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,36 @@
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 TCompVal of scalar
17+
* @template TVal
18+
* @param callable(TCompVal, TCompVal): int $comparison A function that compares the two values. Pick e.g. `strcmp()` or `strnatcasecmp()`
19+
* @param callable(TVal): TCompVal $reducer A function that takes an argument and returns the value that should be compared
20+
* @return callable(TVal, TVal): int
21+
* @fixme file psalm issue for "Argument 1 expects empty, … provided" (when not passing a reducer)
1922
*/
20-
function compare_on(callable $comparison, callable $reducer = null)
23+
function compare_on(callable $comparison, callable $reducer = null): callable
2124
{
2225
if ($reducer === null) {
23-
return static function ($left, $right) use ($comparison) {
26+
return
27+
/**
28+
* @param TVal $left
29+
* @param TVal $right
30+
*/
31+
static function ($left, $right) use ($comparison): int {
32+
/**
33+
* @var TCompVal $left
34+
* @var TCompVal $right
35+
*/
2436
return $comparison($left, $right);
2537
};
2638
}
2739

28-
return static function ($left, $right) use ($reducer, $comparison) {
40+
return
41+
/**
42+
* @param TVal $left
43+
* @param TVal $right
44+
*/
45+
static function ($left, $right) use ($reducer, $comparison): int {
2946
return $comparison($reducer($left), $reducer($right));
3047
};
3148
}

src/Functional/Concat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Concatenates zero or more strings
1515
*
16-
* @param array<array-key, string> $strings
16+
* @param string $strings
1717
* @return string
1818
*/
1919
function concat(string ...$strings)

src/Functional/ConstFunction.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
/**
1414
* Wrap value within a function, which will return it, without any modifications.
1515
*
16-
* @param mixed $value
17-
* @return callable
16+
* @template T
17+
* @param T $value
18+
* @return callable(): T
1819
*/
1920
function const_function($value)
2021
{
21-
return function () use ($value) {
22+
return static function () use ($value) {
2223
return $value;
2324
};
2425
}

src/Functional/Contains.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* Returns true if the collection contains the given value. If the third parameter is
1818
* true values will be compared in strict mode
1919
*
20-
* @param Traversable|array $collection
21-
* @param mixed $value
20+
* @template TLookup
21+
* @param iterable<array-key, TLookup> $collection
22+
* @param TLookup $value
2223
* @param bool $strict
2324
* @return bool
2425
*/

0 commit comments

Comments
 (0)