-
Notifications
You must be signed in to change notification settings - Fork 56
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
PDOStatementProxy->setFetchMode() to match that of PDOStatement #109
Conversation
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.
You need to execute composer cs-fix
command is showing error:
maybe you can hint me styling in which line(s) are not conforming, I can do a manually update |
Here is my guess:
probably because 2nd parameter can not be type hinted, if that's case, maybe we have to setup 3+ setup methods to cover the underlying PDOStatement->setFetchMode() PDOStatementProxy
|
How about |
refactored |
Code check is complaining about N-path / Cyclomatic complexity level i see the if condition / logic branching to be necessary for the method. However we can refactor the if-block into a switch or a function mapping, but it is a bit subjective if this is more readable than if-block. |
|
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.
@yespire @twose I'd suggest rewrite it like following:
diff --git a/src/core/Database/PDOStatementProxy.php b/src/core/Database/PDOStatementProxy.php
index 0b2972b..1ec475b 100644
--- a/src/core/Database/PDOStatementProxy.php
+++ b/src/core/Database/PDOStatementProxy.php
@@ -123,13 +123,13 @@ class PDOStatementProxy extends ObjectProxy
return $this->__object->setAttribute($attribute, $value);
}
- public function setFetchMode(int $mode, $classNameObject = null, array $ctorarfg = []): bool
+ /**
+ * @see https://php.net/pdostatement.setfetchmode
+ */
+ public function setFetchMode(int $mode): bool
{
- $this->setFetchModeContext = [$mode, $classNameObject, $ctorarfg];
- if (!isset($classNameObject)) {
- return $this->__object->setFetchMode($mode);
- }
- return $this->__object->setFetchMode($mode, $classNameObject, $ctorarfg);
+ $this->setFetchModeContext = func_get_args();
+ return $this->__object->setFetchMode(...$this->setFetchModeContext);
}
public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = null, $driver_options = null): bool
Feel free to create a new PR instead if it looks good. Thanks
I will move the ignore change to a separate PR
sure |
@deminy Nice! |
The function signature in PHP8 is /** @return bool */
public function setFetchMode(int $mode, mixed ...$args) {} See: https://github.com/php/php-src/blob/master/ext/pdo/pdo_stmt.stub.php#L64 |
Good catch is "mixed" typing hinting a hard requirement ?
|
It's ok to drop |
I agree with @twose . This is better than what I suggested: public function setFetchMode(int $mode, ...$args) : bool; |
The PR has been merged. @yespire thanks for your contribution! |
about this PR
PHP Fatal error: Uncaught ArgumentCountError: PDOStatement::setFetchMode() expects exactly 2 arguments for the fetch mode provided, 3 given in @swoole-src/library/core/Database/PDOStatementProxy.php:132
for anyone encounters the same error message, alternative: