Skip to content

Commit

Permalink
Merge pull request #72 from MortalFlesh/fix/sortBy
Browse files Browse the repository at this point in the history
Fix return type of sortBy and sortByDescending methods
  • Loading branch information
MortalFlesh authored Nov 25, 2023
2 parents 8bbbb9f + 9c7f2e2 commit d360601
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<!-- There is always Unreleased section on the top. Subsections (Add, Changed, Fix, Removed) should be Add as needed. -->
## Unreleased
- Fix return type of `sortBy` and `sortByDescending` methods

## 8.1.0 - 2023-05-19
- Add `Immutable\Generic\IList::choose` method
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"allow-plugins": {
"composer/package-versions-deprecated": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand Down
1 change: 0 additions & 1 deletion phpstan-tests.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ parameters:
ignoreErrors:
# unit tests
- '#You should use assertCount.* instead of assertSame.*#'
- '#Call to method PHPUnit\\Framework\\Assert::assertArrayHasKey\(\) with .*? will always evaluate to false.#'
- '#Parameter \#1 \$callback of function array_map expects .*? given.#'
- '#Call to method PHPUnit\\Framework\\Assert::assertTrue\(\) with false will always evaluate to false.#'
31 changes: 13 additions & 18 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,42 @@ parameters:
path: src/Immutable/Generic/ListCollection.php

-
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ISeq\\<mixed\\>\\:\\:reduce\\(\\) expects callable\\(array, mixed, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\ISeq\\<mixed\\>\\=\\)\\: array, Closure\\(array, string\\)\\: array given\\.$#"
count: 1
path: src/Immutable/Tuple.php

-
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Mutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, TValue, int\\=, MF\\\\Collection\\\\Mutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, Closure\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap, mixed, int\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\> given\\.$#"
message: "#^Method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\:\\:groupBy\\(\\) should return MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\KVPair\\<TGroup of int\\|string, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\>\\> but returns MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\KVPair\\<TGroup of int\\|string, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\>\\>\\>\\.$#"
count: 1
path: src/Mutable/Generic/ListCollection.php
path: src/Immutable/Generic/ListCollection.php

-
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Mutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(float\\|int, TValue, int\\=, MF\\\\Collection\\\\Mutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: float\\|int, Closure\\(float\\|int, mixed, int\\)\\: float\\|int given\\.$#"
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, TValue, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, Closure\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap, mixed, int\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\> given\\.$#"
count: 1
path: src/Mutable/Generic/ListCollection.php
path: src/Immutable/Generic/ListCollection.php

-
message: "#^Method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\:\\:groupBy\\(\\) should return MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\KVPair\\<TGroup of int\\|string, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\>\\> but returns MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\KVPair\\<TGroup of int\\|string, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\>\\>\\>\\.$#"
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(float\\|int, TValue, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: \\(float\\|int\\), Closure\\(float\\|int, mixed, int\\)\\: \\(float\\|int\\) given\\.$#"
count: 1
path: src/Immutable/Generic/ListCollection.php

-
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, TValue, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, Closure\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap, mixed, int\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\> given\\.$#"
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Mutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, TValue, int\\=, MF\\\\Collection\\\\Mutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\>, Closure\\(MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap, mixed, int\\)\\: MF\\\\Collection\\\\Immutable\\\\Generic\\\\IMap\\<int\\|string, mixed\\> given\\.$#"
count: 1
path: src/Immutable/Generic/ListCollection.php
path: src/Mutable/Generic/ListCollection.php

-
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(float\\|int, TValue, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: float\\|int, Closure\\(float\\|int, mixed, int\\)\\: float\\|int given\\.$#"
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Mutable\\\\Generic\\\\ListCollection\\<TValue\\>\\:\\:reduce\\(\\) expects callable\\(float\\|int, TValue, int\\=, MF\\\\Collection\\\\Mutable\\\\Generic\\\\IList\\<TValue\\>\\=\\)\\: \\(float\\|int\\), Closure\\(float\\|int, mixed, int\\)\\: \\(float\\|int\\) given\\.$#"
count: 1
path: src/Immutable/Generic/ListCollection.php

path: src/Mutable/Generic/ListCollection.php

# Tuple
-
message: '#Parameter \#1 \$callback of method MF\\Collection\\Immutable\\Generic\\ISeq<mixed>::map\(\) expects callable\(mixed\): string, Closure\(string\): string given.#'
count: 3
path: src/Immutable/Tuple.php

# Seq
-
message: '#Argument of an invalid type mixed supplied for foreach, only iterables are supported.#'
message: "#^Parameter \\#1 \\$reducer of method MF\\\\Collection\\\\Immutable\\\\Generic\\\\ISeq\\<mixed\\>\\:\\:reduce\\(\\) expects callable\\(array, mixed, int\\=, MF\\\\Collection\\\\Immutable\\\\Generic\\\\ISeq\\<mixed\\>\\=\\)\\: array, Closure\\(array, string\\)\\: array given\\.$#"
count: 1
path: src/Immutable/Generic/Seq.php
path: src/Immutable/Tuple.php

# Seq

-
message: '#Parameter \#1 \$modifier of method MF\\Collection\\Immutable\\Generic\\Seq<TValue>::.*?\(\) expects .*?: .*? given.#'
Expand Down
4 changes: 2 additions & 2 deletions src/Immutable/Generic/IList.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ public function sort(): IList;
public function sortDescending(): IList;

/**
* @phpstan-param callable(TValue, TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue, TValue): (string|int|float) $callback
* @phpstan-return IList<TValue>
*/
public function sortBy(callable $callback): IList;

/**
* @phpstan-param callable(TValue, TIndex=): int<-1, 1> $callback
* @phpstan-param callable(TValue, TIndex=): (string|int|float) $callback
* @phpstan-return IList<TValue>
*/
public function sortByDescending(callable $callback): IList;
Expand Down
4 changes: 2 additions & 2 deletions src/Immutable/Generic/ISeq.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ public function sort(): ISeq;
public function sortDescending(): ISeq;

/**
* @phpstan-param callable(TValue, TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue, TValue): (string|int|float) $callback
* @phpstan-return ISeq<TValue>
*
* @throws OutOfBoundsException
*/
public function sortBy(callable $callback): ISeq;

/**
* @phpstan-param callable(TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue): (string|int|float) $callback
* @phpstan-return ISeq<TValue>
*
* @throws OutOfBoundsException
Expand Down
4 changes: 2 additions & 2 deletions src/Immutable/Generic/ListCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function sortDescending(): IList
}

/**
* @phpstan-param callable(TValue, TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue, TValue): (string|int|float) $callback
* @phpstan-return IList<TValue>
*/
public function sortBy(callable $callback): IList
Expand All @@ -381,7 +381,7 @@ public function sortBy(callable $callback): IList
}

/**
* @phpstan-param callable(TValue, TIndex=): int<-1, 1> $callback
* @phpstan-param callable(TValue, TIndex=): (string|int|float) $callback
* @phpstan-return IList<TValue>
*/
public function sortByDescending(callable $callback): IList
Expand Down
4 changes: 2 additions & 2 deletions src/Immutable/Generic/Seq.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ public function sortDescending(): ISeq
}

/**
* @phpstan-param callable(TValue, TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue, TValue): (string|int|float) $callback
* @phpstan-return ISeq<TValue>
*
* @throws OutOfBoundsException
Expand All @@ -695,7 +695,7 @@ public function sortBy(callable $callback): ISeq
}

/**
* @phpstan-param callable(TValue): int<-1, 1> $callback
* @phpstan-param callable(TValue): (string|int|float) $callback
* @phpstan-return ISeq<TValue>
*
* @throws OutOfBoundsException
Expand Down
4 changes: 2 additions & 2 deletions src/Mutable/Generic/IList.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ public function sort(): void;

public function sortDescending(): void;

/** @phpstan-param callable(TValue, TValue): int<-1, 1> $callback */
/** @phpstan-param callable(TValue, TValue): (string|int|float) $callback */
public function sortBy(callable $callback): void;

/** @phpstan-param callable(TValue, TIndex=): int<-1, 1> $callback */
/** @phpstan-param callable(TValue, TIndex=): (string|int|float) $callback */
public function sortByDescending(callable $callback): void;

/** Keeps only unique values inside the list. */
Expand Down
4 changes: 2 additions & 2 deletions src/Mutable/Generic/ListCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function sortDescending(): void
rsort($this->listArray);
}

/** @phpstan-param callable(TValue, TValue): int<-1, 1> $callback */
/** @phpstan-param callable(TValue, TValue): (string|int|float) $callback */
public function sortBy(callable $callback): void
{
$callback = Callback::curry($callback);
Expand All @@ -328,7 +328,7 @@ public function sortBy(callable $callback): void
);
}

/** @phpstan-param callable(TValue, TIndex=): int<-1, 1> $callback */
/** @phpstan-param callable(TValue, TIndex=): (string|int|float) $callback */
public function sortByDescending(callable $callback): void
{
$callback = Callback::curry($callback);
Expand Down

0 comments on commit d360601

Please sign in to comment.