Skip to content

Commit

Permalink
Fix PHPStan warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 18, 2019
1 parent 07f4859 commit c1df8d3
Show file tree
Hide file tree
Showing 60 changed files with 99 additions and 83 deletions.
1 change: 0 additions & 1 deletion phpspec.yml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
formatter.name: pretty
extensions:
drupol\PhpspecAnnotation\PhpspecAnnotation: ~
LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension:
format:
- html
Expand Down
11 changes: 6 additions & 5 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use drupol\collection\Iterator\ClosureIterator;
use drupol\collection\Transformation\Run;
use drupol\collection\Transformation\Transform;
use Generator;

use function is_string;

Expand All @@ -30,15 +31,15 @@ abstract class Base implements BaseInterface
* @param Closure|iterable|mixed $data
* @param mixed ...$parameters
*/
public function __construct($data = [], ...$parameters)
final public function __construct($data = [], ...$parameters)
{
switch (true) {
case $data instanceof Closure:
$this->source = $data;

break;
case is_iterable($data):
$this->source = static function () use ($data) {
$this->source = static function () use ($data): Generator {
foreach ($data as $key => $value) {
yield $key => $value;
}
Expand All @@ -49,7 +50,7 @@ public function __construct($data = [], ...$parameters)
$parameters += [0 => null];
$separator = (string) $parameters[0];

$this->source = static function () use ($data, $separator) {
$this->source = static function () use ($data, $separator): Generator {
$offset = 0;

$nextOffset = '' !== $separator ?
Expand All @@ -73,7 +74,7 @@ public function __construct($data = [], ...$parameters)
break;

default:
$this->source = static function () use ($data) {
$this->source = static function () use ($data): Generator {
foreach ((array) $data as $key => $value) {
yield $key => $value;
}
Expand All @@ -82,7 +83,7 @@ public function __construct($data = [], ...$parameters)
}

/**
* {@inheritdoc}
* @return ClosureIterator<mixed>
*/
public function getIterator(): ClosureIterator
{
Expand Down
11 changes: 6 additions & 5 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use drupol\collection\Transformation\Implode;
use drupol\collection\Transformation\Last;
use drupol\collection\Transformation\Reduce;
use Generator;

use const INF;
use const PHP_INT_MAX;
Expand Down Expand Up @@ -251,7 +252,7 @@ public function intersperse($element, int $every = 1, int $startAt = 0): BaseInt
public static function iterate(callable $callback, ...$parameters): CollectionInterface
{
return new Collection(
static function () use ($parameters, $callback) {
static function () use ($parameters, $callback): Generator {
while (true) {
$parameters = $callback(...$parameters);

Expand Down Expand Up @@ -416,7 +417,7 @@ public function reduction(callable $callback, $initial = null): BaseInterface
*/
public function rsample($probability): BaseInterface
{
$callback = static function ($item) use ($probability) {
$callback = static function ($item) use ($probability): bool {
return (mt_rand() / mt_getrandmax()) < $probability;
};

Expand Down Expand Up @@ -488,7 +489,7 @@ public static function times($number, ?callable $callback = null): CollectionInt
}

$instance = new Collection(
static function () use ($number) {
static function () use ($number): Generator {
for ($current = 1; $current <= $number; ++$current) {
yield $current;
}
Expand Down Expand Up @@ -519,10 +520,10 @@ public function walk(callable ...$callbacks): BaseInterface
}

/**
* @param array $data
* @param array<mixed> $data
* @param mixed ...$parameters
*
* @return \drupol\collection\Contract\Base
* @return \drupol\collection\Contract\Base<mixed>
*/
public static function with($data = [], ...$parameters): BaseInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Allable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Allable
/**
* Get all items from the collection.
*
* @return array
* @return array<mixed>
* An array containing all the elements of the collection.
*/
public function all(): array;
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Appendable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Appendable
*
* @param mixed ...$items
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function append(...$items): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Applyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Applyable
*
* @param callable ...$callables
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function apply(callable ...$callables): Base;
}
2 changes: 2 additions & 0 deletions src/Contract/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Interface Base.
*
* @template-extends IteratorAggregate<mixed>
*/
interface Base extends IteratorAggregate, Runable, Transformable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Chunkable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Chunkable
*
* @param int $size
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function chunk(int $size): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Collapseable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Collapseable
/**
* Collapse the collection of items into a single array.
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function collapse(): Base;
}
8 changes: 5 additions & 3 deletions src/Contract/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ interface Collection extends
{
/**
* Create a new instance with no items.
*
* @return \drupol\collection\Contract\Collection<mixed>
*/
public static function empty(): Collection;

/**
* @param callable $callback
* @param mixed ...$parameters
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public static function iterate(callable $callback, ...$parameters): Collection;

Expand All @@ -73,7 +75,7 @@ public static function iterate(callable $callback, ...$parameters): Collection;
* @param float|int $end
* @param int $step
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public static function range(int $start = 0, $end = INF, $step = 1): Collection;

Expand All @@ -83,7 +85,7 @@ public static function range(int $start = 0, $end = INF, $step = 1): Collection;
* @param int $number
* @param callable $callback
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public static function times($number, ?callable $callback = null): Collection;
}
2 changes: 1 addition & 1 deletion src/Contract/Combineable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Combineable
/**
* @param mixed $keys
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function combine($keys): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Cycleable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Cycleable
/**
* @param int $count
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function cycle(int $count = 0): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Distinctable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface Distinctable
{
/**
* @return \drupol\collection\Contract\Base
* @return \drupol\collection\Contract\Base<mixed>
*/
public function distinct(): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Explodeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Explodeable
/**
* @param string ...$explodes
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function explode(string ...$explodes): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Filterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Filterable
*
* @param callable ...$callbacks
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function filter(callable ...$callbacks): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Flattenable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface Flattenable
*
* @param int $depth
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function flatten(int $depth = PHP_INT_MAX): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Flipable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Flipable
/**
* Flip the items in the collection.
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function flip(): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Forgetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Forgetable
*
* @param string ...$keys
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function forget(...$keys): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Intersperseable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface Intersperseable
* @param int $every
* @param int $startAt
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function intersperse($element, int $every = 1, int $startAt = 0): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Keysable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Keysable
/**
* Get the keys of the items.
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function keys(): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Limitable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Limitable
*
* @param int $limit
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function limit(int $limit): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Mapable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Mapable
*
* @param callable ...$callbacks
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function map(callable ...$callbacks): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Mergeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Mergeable
*
* @param iterable ...$sources
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function merge(...$sources): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Normalizeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Normalizeable
/**
* Reset the keys on the underlying array.
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function normalize(): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Nthable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Nthable
* @param int $step
* @param int $offset
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function nth(int $step, int $offset = 0): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Onlyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Onlyable
*
* @param mixed ...$keys
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function only(...$keys): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface Operation extends Transformation
{
/**
* @param iterable $collection
* @param iterable<mixed> $collection
*
* @return Closure
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Contract/Padable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Padable
* @param int $size
* @param mixed $value
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function pad(int $size, $value): Base;
}
4 changes: 2 additions & 2 deletions src/Contract/Pluckable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
interface Pluckable
{
/**
* @param array|string $pluck
* @param array<int, string>|string $pluck
* @param mixed|null $default
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function pluck($pluck, $default = null): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Prependable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Prependable
*
* @param mixed ...$items
*
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function prepend(...$items): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/RSampleable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface RSampleable
/**
* @param float $probability
*
* @return \drupol\collection\Contract\Base
* @return \drupol\collection\Contract\Base<mixed>
*/
public function rsample($probability): Base;
}
2 changes: 1 addition & 1 deletion src/Contract/Rebaseable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
interface Rebaseable
{
/**
* @return \drupol\collection\Contract\Collection
* @return \drupol\collection\Contract\Collection<mixed>
*/
public function rebase(): Base;
}

0 comments on commit c1df8d3

Please sign in to comment.