-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add doc blocks, type hinting. Make stricter. #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,24 @@ class Curried | |
*/ | ||
private $func; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $args = []; | ||
|
||
/** | ||
span class="pl-s1"> * @var integer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you may have slipped on your keyboard here 😆 🤣 |
||
*/ | ||
private $arity; | ||
|
||
public function __construct($callable, $arity = null) | ||
/** | ||
* Curried constructor. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The @param s I like but I'd remove 'Curried constructor.' as it doesn't add any extra information, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHPStorm default - don't even notice them any more. Can remove 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it's a pet peeve of mine comments that say things like "add one to x". I probably spend more time than is sensible editing phpstorm's defaults. |
||
* | ||
* @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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmmm strict 👍 |
||
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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,31 @@ | |
|
||
class CurryWrapper | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $object; | ||
|
||
/** | ||
* CurryWrapper constructor. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove the string "CurryWrapper" constructor as it doesn't add any extra information. |
||
* | ||
* @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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I'm going to veto this bit of the change. It doesn't seem to add any additional information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
mixed[]
- it would indicate an Array of variable types 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. I think I like mixed[] better as it's more explicit that we expect a mix rather than just didn't bother specifying the type.