diff --git a/src/Curried.php b/src/Curried.php index 1e5c6fc..4aeffc5 100644 --- a/src/Curried.php +++ b/src/Curried.php @@ -9,10 +9,24 @@ class Curried */ private $func; + /** + * @var array + */ private $args = []; + + /** +span class="pl-s1"> * @var integer + */ private $arity; - public function __construct($callable, $arity = null) + /** + * Curried constructor. + * + * @param callable $callable + * @param int|null $arity + * @throws \ReflectionException + */ + public function __construct(callable $callable, $arity = null) { if (!is_callable($callable)) { throw new \InvalidArgumentException("Curried can only wrap a callable"); @@ -24,18 +38,26 @@ public function __construct($callable, $arity = null) public function __invoke() { $arguments = func_get_args(); - if (count($this->args) == $this->arity - count($arguments)) { + if (count($this->args) === $this->arity - count($arguments)) { return call_user_func_array($this->func, array_merge($this->args, $arguments)); - } else { - $curried = new Curried($this->func, $this->arity); - foreach($arguments as $argument) { - $curried->args[] = $argument; - } - return $curried; } + + $curried = new Curried($this->func, $this->arity); + + foreach($arguments as $argument) { + $curried->args[] = $argument; + } + + return $curried; } - private function setArity($callable, $arity = null) + /** + * @param callable $callable + * @param int|null $arity + * @return void + * @throws \ReflectionException + */ + private function setArity(callable $callable, $arity = null) { if ($arity !== null) { $this->arity = $arity; diff --git a/src/CurryWrapper.php b/src/CurryWrapper.php index 900cfb4..72e008e 100644 --- a/src/CurryWrapper.php +++ b/src/CurryWrapper.php @@ -4,16 +4,31 @@ class CurryWrapper { + /** + * @var mixed + */ private $object; + /** + * CurryWrapper constructor. + * + * @param mixed $object + */ public function __construct($object) { $this->object = $object; } + /** + * @param string $functionName + * @param array $arguments + * @return mixed + * @throws \ReflectionException + */ public function __call($functionName, array $arguments) { $curried = new Curried([$this->object, $functionName]); + return call_user_func_array($curried, $arguments); } } diff --git a/src/helpers.php b/src/helpers.php index c0a7d9e..5ddbe4c 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -5,7 +5,7 @@ function curry($thing) { if (is_object($thing) && !($thing instanceof \Closure)) { return new CurryWrapper($thing); - } else { - return new Curried($thing); } -} \ No newline at end of file + + return new Curried($thing); +}