Skip to content

Commit

Permalink
fix: update various operations static analysis annotations.
Browse files Browse the repository at this point in the history
Get rid of a couple of Psalm issues
  • Loading branch information
drupol committed Nov 7, 2022
1 parent 2fb44cf commit c1998e9
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 44 deletions.
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ parameters:
path: src/Collection.php

-
message: "#^Parameter \\#1 \\$ of closure expects callable\\(mixed, mixed, mixed, iterable\\)\\: mixed, callable\\(T\\|V, T, TKey, Iterator\\<TKey, T\\>\\)\\: T\\|V given\\.$#"
count: 4
message: "#^Parameter \\#1 \\$ of closure expects callable\\(mixed, mixed, mixed, iterable\\)\\: mixed, callable\\(T\\|V, T, TKey, Iterator\\<TKey, T\\>\\)\\: V given\\.$#"
count: 1
path: src/Collection.php

-
Expand Down
10 changes: 6 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="src/Collection.php">
<InvalidArgument occurrences="4">
<code>$callback</code>
<code>$callback</code>
<code>$callback</code>
<InvalidArgument occurrences="1">
<code>$callback</code>
</InvalidArgument>
<InvalidReturnStatement occurrences="1">
Expand All @@ -20,6 +17,11 @@
<code>Closure(bool): Closure(iterable&lt;TKey, T&gt;): (Generator&lt;int, T&gt;|Generator&lt;TKey, T&gt;)</code>
</InvalidReturnType>
</file>
<file src="src/Operation/Averages.php">
<InvalidScalarArgument occurrences="1">
<code>static fn (float $acc, float $value, int $key): float =&gt; ($acc * $key + $value) / ($key + 1)</code>
</InvalidScalarArgument>
</file>
<file src="src/Operation/Inits.php">
<InvalidArgument occurrences="2">
<code>[]</code>
Expand Down
7 changes: 2 additions & 5 deletions src/Contract/Operation/FoldLeft1able.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
* @template TKey
* @template T
Expand All @@ -21,9 +18,9 @@ interface FoldLeft1able
*
* @template V
*
* @param callable(T|V, T, TKey, Iterator<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return T|V|null
* @return V
*/
public function foldLeft1(callable $callback);
}
6 changes: 2 additions & 4 deletions src/Contract/Operation/FoldRight1able.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;

/**
* @template TKey
* @template T
Expand All @@ -15,9 +13,9 @@ interface FoldRight1able
/**
* @template V
*
* @param callable(T|V, T, TKey, Iterator<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return T|V|null
* @return V
*/
public function foldRight1(callable $callback);
}
5 changes: 2 additions & 3 deletions src/Contract/Operation/ScanLeft1able.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -22,9 +21,9 @@ interface ScanLeft1able
*
* @template V
*
* @param callable(T|V, T, TKey, Iterator<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return Collection<int|TKey, T|V>
* @return Collection<int|TKey, V>
*/
public function scanLeft1(callable $callback): Collection;
}
4 changes: 2 additions & 2 deletions src/Contract/Operation/ScanRight1able.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ interface ScanRight1able
*
* @template V
*
* @param callable(T|V, T, TKey, Iterator<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, Iterator<TKey, T>): V $callback
*
* @return Collection<int|TKey, T|V>
* @return Collection<int|TKey, V>
*/
public function scanRight1(callable $callback): Collection;
}
8 changes: 4 additions & 4 deletions src/Operation/FoldLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ final class FoldLeft1 extends AbstractOperation
/**
* @template V
*
* @return Closure(callable(T|V, T, TKey, iterable<TKey, T>): (T|V)): Closure(iterable<TKey, T>): Generator<int|TKey, T|V|null>
* @return Closure(callable((T|V), T, TKey, iterable<TKey, T>): V): Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
public function __invoke(): Closure
{
return
/**
* @param callable(T|V, T, TKey, iterable<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return Closure(iterable<TKey, T>): Generator<int|TKey, T|V|null>
* @return Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
static function (callable $callback): Closure {
/** @var Closure(iterable<TKey, T>):(Generator<int|TKey, T|V|null>) $pipe */
/** @var Closure(iterable<TKey, T>):(Generator<int|TKey, V>) $pipe */
$pipe = (new Pipe())()(
(new ScanLeft1())()($callback),
(new Last())()
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/FoldRight1.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ final class FoldRight1 extends AbstractOperation
/**
* @template V
*
* @return Closure(callable(T|V, T, TKey, iterable<TKey, T>): (T|V)): Closure(iterable<TKey, T>): Generator<int|TKey, T|V|null>
* @return Closure(callable((T|V), T, TKey, iterable<TKey, T>): V): Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
public function __invoke(): Closure
{
return
/**
* @param callable(T|V, T, TKey, iterable<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return Closure(iterable<TKey, T>): Generator<int|TKey, T|V|null>
* @return Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
static function (callable $callback): Closure {
/** @var Closure(iterable<TKey, T>):(Generator<int|TKey, T|V|null>) $pipe */
/** @var Closure(iterable<TKey, T>):(Generator<int|TKey, V>) $pipe */
$pipe = (new Pipe())()(
(new ScanRight1())()($callback),
(new Head())()
Expand Down
10 changes: 5 additions & 5 deletions src/Operation/ScanLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ final class ScanLeft1 extends AbstractOperation
/**
* @template V
*
* @return Closure(callable(T|V, T, TKey, iterable<TKey, T>): (T|V)): Closure(iterable<TKey, T>): Generator<int|TKey, T|V>
* @return Closure(callable((T|V), T, TKey, iterable<TKey, T>): V): Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
public function __invoke(): Closure
{
return
/**
* @param callable(T|V, T, TKey, iterable<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return Closure(iterable<TKey, T>): Generator<int|TKey, T|V>
* @return Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
static fn (callable $callback): Closure =>
/**
* @param iterable<TKey, T> $iterable
*
* @return Generator<int|TKey, T|V>
* @return Generator<int|TKey, V>
*/
static function (iterable $iterable) use ($callback): Generator {
$iteratorAggregate = new IterableIteratorAggregate($iterable);
Expand All @@ -46,7 +46,7 @@ static function (iterable $iterable) use ($callback): Generator {

$initial = $iteratorInitial->current();

/** @var Closure(iterable<TKey, T>): Generator<int|TKey, T|V> $pipe */
/** @var Closure(iterable<TKey, T>): Generator<int|TKey, V> $pipe */
$pipe = (new Pipe())()(
(new Tail())(),
(new Reduction())()($callback)($initial),
Expand Down
8 changes: 4 additions & 4 deletions src/Operation/ScanRight1.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ final class ScanRight1 extends AbstractOperation
/**
* @template V
*
* @return Closure(callable(T|V, T, TKey, iterable<TKey, T>): (T|V)): Closure(iterable<TKey, T>): Generator<int|TKey, T|V>
* @return Closure(callable((T|V), T, TKey, iterable<TKey, T>): V): Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
public function __invoke(): Closure
{
return
/**
* @param callable(T|V, T, TKey, iterable<TKey, T>): (T|V) $callback
* @param callable((T|V), T, TKey, iterable<TKey, T>): V $callback
*
* @return Closure(iterable<TKey, T>): Generator<int|TKey, T|V>
* @return Closure(iterable<TKey, T>): Generator<int|TKey, V>
*/
static function (callable $callback): Closure {
/** @var Closure(iterable<TKey, T>): Generator<int|TKey, T|V> $pipe */
/** @var Closure(iterable<TKey, T>): Generator<int|TKey, V> $pipe */
$pipe = (new Pipe())()(
(new Reverse())(),
(new ScanLeft1())()($callback),
Expand Down
8 changes: 2 additions & 6 deletions tests/static-analysis/scanLeft1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
use loophp\collection\Contract\Collection as CollectionInterface;

$concat = static fn (string $carry, string $string): string => sprintf('%s%s', $carry, $string);
$toString =
/**
* @param int|string $carry
*/
static fn ($carry, int $value): string => sprintf('%s', $value);
$toString = static fn (int|string $carry, int $value): string => sprintf('%s', $value);

/**
* @param CollectionInterface<int, string> $collection
Expand All @@ -22,7 +18,7 @@ function scanLeft1_checkListString(CollectionInterface $collection): void
}

/**
* @param CollectionInterface<int, int|string> $collection
* @param CollectionInterface<int, string> $collection
*/
function scanLeft1_checkListOfSize1String(CollectionInterface $collection): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/static-analysis/scanRight1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function scanRight1_checkListString(CollectionInterface $collection): void
}

/**
* @param CollectionInterface<int, int|string> $collection
* @param CollectionInterface<int, string> $collection
*/
function scanRight1_checkListOfSize1String(CollectionInterface $collection): void
{
Expand Down

0 comments on commit c1998e9

Please sign in to comment.