Skip to content

Commit

Permalink
Update PHPDoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed May 30, 2020
1 parent 402e2de commit 70fb09d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Contract/Transformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Transformation
/**
* @param iterable<mixed> $collection
*
* @return bool|mixed
* @return iterable|mixed
*/
public function __invoke(iterable $collection);
}
15 changes: 10 additions & 5 deletions src/Operation/Explode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
final class Explode implements Operation
{
/**
* @var array<mixed>
* @var array<float|int|string>
*/
private $explodes;

/**
* Explode constructor.
*
* @param mixed ...$explodes
* @param float|int|string ...$explodes
*/
public function __construct(...$explodes)
{
Expand All @@ -33,10 +33,15 @@ public function __construct(...$explodes)
public function __invoke(): Closure
{
$callbacks = array_map(
/**
* @param float|int|string $explode
*/
static function ($explode) {
return static function ($value) use ($explode): bool {
return $value === $explode;
};
return
/** @param mixed $value */
static function ($value) use ($explode): bool {
return $value === $explode;
};
},
$this->explodes
);
Expand Down
33 changes: 21 additions & 12 deletions src/Operation/Scale.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,35 @@ public function __construct(
$wantedUpperBound = $wantedUpperBound ?? $base;
}

$callback = static function ($v) use ($lowerBound, $upperBound, $wantedLowerBound, $wantedUpperBound, $base): float { // phpcs:ignore
if (null !== $base) {
$mx = log($v - $lowerBound, $base) / log($upperBound - $lowerBound, $base);
$this->mapper = new Walk(
/**
* @param float|int $v
*/
static function ($v) use ($lowerBound, $upperBound, $wantedLowerBound, $wantedUpperBound, $base): float { // phpcs:ignore
if (null !== $base) {
$mx = log($v - $lowerBound, $base) / log($upperBound - $lowerBound, $base);

if ($mx === -INF) {
$mx = 0;
if ($mx === -INF) {
$mx = 0;
}
} else {
$mx = ($v - $lowerBound) / ($upperBound - $lowerBound);
}
} else {
$mx = ($v - $lowerBound) / ($upperBound - $lowerBound);
}

return $wantedLowerBound + $mx * ($wantedUpperBound - $wantedLowerBound);
};

$this->mapper = new Walk($callback);
return $wantedLowerBound + $mx * ($wantedUpperBound - $wantedLowerBound);
}
);

$this->filter = new Filter(
/**
* @param float|int $item
*/
static function ($item) use ($lowerBound): bool {
return $item >= $lowerBound;
},
/**
* @param float|int $item
*/
static function ($item) use ($upperBound): bool {
return $item <= $upperBound;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Transformation/First.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __invoke(iterable $collection)
$default = $this->default;

if (null === $callback) {
$callback = static function ($value, $key): bool {
$callback = static function (): bool {
return true;
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/Transformation/Last.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public function __invoke(iterable $collection)
{
return (
new FoldLeft(
/**
* @param mixed $carry
* @param mixed $item
*
* @return mixed
*/
static function ($carry, $item) {
return $item;
}
Expand Down
1 change: 1 addition & 0 deletions src/Transformation/Transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __invoke(iterable $collection)
{
return (
new FoldLeft(
/** @return mixed */
static function (iterable $collection, Transformation $transformer) {
return $transformer($collection);
},
Expand Down

0 comments on commit 70fb09d

Please sign in to comment.