Skip to content

Commit

Permalink
Merge pull request #6 from loophp/update-type-declarations-everywhere
Browse files Browse the repository at this point in the history
Update type declarations in src/
  • Loading branch information
drupol committed Feb 6, 2020
2 parents 9a4b71f + 2a87f46 commit 55b8cc1
Show file tree
Hide file tree
Showing 35 changed files with 664 additions and 224 deletions.
1 change: 1 addition & 0 deletions psalm.xml
Expand Up @@ -7,6 +7,7 @@
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src"/>
<directory name="tests/static-analysis"/>
<ignoreFiles>
<directory name="vendor" />
Expand Down
8 changes: 5 additions & 3 deletions src/Combinator.php
Expand Up @@ -6,14 +6,16 @@

use Closure;
use InvalidArgumentException;
use loophp\combinator\Contract\Combinator as CombinatorInterface;

use function get_called_class;
use function is_callable;

/**
* Class Combinator.
*
* @psalm-immutable
*/
abstract class Combinator implements \loophp\combinator\Contract\Combinator
abstract class Combinator implements CombinatorInterface
{
/**
* @return Closure
Expand All @@ -26,6 +28,6 @@ public static function with(): Closure
return Closure::fromCallable($possibleCallable);
}

throw new InvalidArgumentException('Implement on() method in ' . get_called_class() . '.');
throw new InvalidArgumentException('Implement on() method in ' . static::class . '.');
}
}
23 changes: 16 additions & 7 deletions src/Combinator/A.php
Expand Up @@ -12,15 +12,21 @@
*
* @psalm-template AType
* @psalm-template BType
*
* @psalm-immutable
*/
final class A extends Combinator
{
/**
* @psalm-var callable(AType): BType
*
* @var callable
*/
private $f;

/**
* @psalm-var AType
*
* @var mixed
*/
private $x;
Expand All @@ -29,7 +35,7 @@ final class A extends Combinator
* A constructor.
*
* @psalm-param callable(AType): BType $f
* @psalm-param BType $x
* @psalm-param AType $x
*
* @param callable $f
* @param mixed $x
Expand All @@ -49,16 +55,19 @@ public function __invoke()
}

/**
* @psalm-param callable(AType): BType $f
* @template NewAType
* @template NewBType
*
* @param callable $f
* @param callable(NewAType): NewBType $f
*
* @return Closure
* @return Closure(NewAType): NewBType
*/
public static function on(callable $f): Closure
{
return static function ($x) use ($f) {
return (new self($f, $x))();
};
return
/** @param NewAType $x */
static function ($x) use ($f) {
return (new self($f, $x))();
};
}
}
29 changes: 22 additions & 7 deletions src/Combinator/B.php
Expand Up @@ -13,20 +13,28 @@
* @psalm-template AType
* @psalm-template BType
* @psalm-template CType
*
* @psalm-immutable
*/
final class B extends Combinator
{
/**
* @psalm-var callable(AType): BType
*
* @var callable
*/
private $f;

/**
* @psalm-var callable(CType): AType
*
* @var callable
*/
private $g;

/**
* @psalm-var CType
*
* @var mixed
*/
private $x;
Expand Down Expand Up @@ -58,16 +66,23 @@ public function __invoke()
}

/**
* @param callable $a
* @template AParam
* @template AReturn
*
* @param callable(AParam): AReturn $f
*
* @return Closure
* @return Closure(callable(mixed): AParam): Closure(mixed): AReturn
*/
public static function on(callable $a): Closure
public static function on(callable $f): Closure
{
return static function (callable $b) use ($a): Closure {
return static function ($c) use ($a, $b) {
return (new self($a, $b, $c))();
return
/** @param callable(mixed): AParam $g */
static function (callable $g) use ($f): Closure {
return
/** @param mixed $x */
static function ($x) use ($f, $g) {
return (new self($f, $g, $x))();
};
};
};
}
}
34 changes: 27 additions & 7 deletions src/Combinator/C.php
Expand Up @@ -13,20 +13,28 @@
* @psalm-template AType
* @psalm-template BType
* @psalm-template CType
*
* @psalm-immutable
*/
final class C extends Combinator
{
/**
* @psalm-var callable(AType): callable(BType): CType
*
* @var callable
*/
private $f;

/**
* @psalm-var BType
*
* @var mixed
*/
private $x;

/**
* @psalm-var AType
*
* @var mixed
*/
private $y;
Expand All @@ -51,23 +59,35 @@ public function __construct(callable $f, $x, $y)

/**
* @psalm-return CType
*
* @return mixed
*/
public function __invoke()
{
return ($this->f)($this->y)($this->x);
}

/**
* @param callable $a
* @template NewAType
* @template NewBType
* @template NewCType
*
* @psalm-param callable(NewAType): callable(NewBType): NewCType $f
*
* @param callable(NewAType): NewCType $f
*
* @return Closure
* @return Closure(NewBType): Closure(NewAType): NewCType
*/
public static function on(callable $a): Closure
public static function on(callable $f): Closure
{
return static function ($b) use ($a): Closure {
return static function ($c) use ($a, $b) {
return (new self($a, $b, $c))();
return
/** @param NewBType $x */
static function ($x) use ($f): Closure {
return
/** @param NewAType $y */
static function ($y) use ($f, $x) {
return (new self($f, $x, $y))();
};
};
};
}
}
81 changes: 52 additions & 29 deletions src/Combinator/D.php
Expand Up @@ -14,71 +14,94 @@
* @psalm-template BType
* @psalm-template CType
* @psalm-template DType
*
* @psalm-immutable
*/
final class D extends Combinator
{
/**
* @psalm-var callable(AType): callable(CType): DType
*
* @var callable
*/
private $f;
private $a;

/**
* @var callable
* @psalm-var AType
*
* @var mixed
*/
private $g;
private $b;

/**
* @var mixed
* @psalm-var callable(BType): CType
*
* @var callable
*/
private $x;
private $c;

/**
* @psalm-var BType
*
* @var mixed
*/
private $y;
private $d;

/**
* D constructor.
*
* @psalm-param callable(AType): callable(CType): DType $f
* @psalm-param AType $x
* @psalm-param callable(BType): CType $g
* @psalm-param BType $y
* @psalm-param callable(AType): callable(CType): DType $a
* @psalm-param AType $b
* @psalm-param callable(BType): CType $c
* @psalm-param BType $d
*
* @param callable $f
* @param callable $g
* @param mixed $x
* @param mixed $y
* @param callable $a
* @param mixed $b
* @param callable $c
* @param mixed $d
*/
public function __construct(callable $f, $x, callable $g, $y)
public function __construct(callable $a, $b, callable $c, $d)
{
$this->f = $f;
$this->x = $x;
$this->g = $g;
$this->y = $y;
$this->a = $a;
$this->b = $b;
$this->c = $c;
$this->d = $d;
}

/**
* @psalm-return DType
*/
public function __invoke()
{
return (($this->f)($this->x))(($this->g)($this->y));
return (($this->a)($this->b))(($this->c)($this->d));
}

/**
* @param callable $a
* @template NewAType
* @template NewBType
* @template NewCType
* @template NewDType
*
* @psalm-param callable(NewAType): callable(NewCType): NewDType $f
*
* @param callable(NewCType): NewDType $f
*
* @return Closure
* @return Closure(NewAType): Closure(Closure(NewBType): NewCType): Closure(NewBType): NewDType
*/
public static function on(callable $a): Closure
public static function on(callable $f): Closure
{
return static function ($b) use ($a): Closure {
return static function (callable $c) use ($a, $b): Closure {
return static function ($d) use ($a, $b, $c) {
return (new self($a, $b, $c, $d))();
};
return
/** @param NewAType $x */
static function ($x) use ($f): Closure {
return
/** @param callable(NewBType): NewCType $g */
static function (callable $g) use ($f, $x): Closure {
return
/** @param NewBType $y */
static function ($y) use ($f, $x, $g) {
return (new self($f, $x, $g, $y))();
};
};
};
};
}
}

0 comments on commit 55b8cc1

Please sign in to comment.