Skip to content
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

PhpStan fixes #364

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

PhpStan fixes #364

wants to merge 4 commits into from

Conversation

janbarasek
Copy link
Contributor

  • new feature
  • BC break? yes

I fixed some PhpStan errors.

Resend #363.

@janbarasek janbarasek mentioned this pull request May 7, 2020
if ($this->errors) {
throw new Exception('SQL translate error: ' . trim(reset($this->errors), '*'), 0, $sql);
if ($this->errors !== []) {
throw new Exception('SQL translate error: ' . trim((string) reset($this->errors), '*'), 0, $sql);
Copy link
Owner

@dg dg May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it changes behavior, can be null or empty array. And original code is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted original condition but kept (string) for PhpStan because function reset() can return mixed value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For nonempty string[]? I think it must be always string.

if (in_array($code, [1216, 1217, 1451, 1452, 1701], true)) {
return new Dibi\ForeignKeyConstraintViolationException($message, $code, $sql);
if (is_int($code) === true) {
if (in_array($code, [1216, 1217, 1451, 1452, 1701], true)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no reason for this change, in_array checks type

Copy link
Contributor Author

@janbarasek janbarasek May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter $code can be int or string. In the case of string the if statements can be skipped (better performance and code readability).

Snímek obrazovky 2020-05-07 v 22 35 17

What do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in mysql driver it is always int.

@@ -41,7 +41,8 @@ public function __construct(\mysqli_result $resultSet, bool $buffered)
*/
public function __destruct()
{
if ($this->autoFree && $this->getResultResource()) {
if ($this->autoFree) {
$this->getResultResource();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested all combinations and I think not. The result of getResultResource() is always true, so it should be called in if statement.

Snímek obrazovky 2020-05-07 v 22 39 54

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is right.

src/Dibi/Drivers/OdbcDriver.php Outdated Show resolved Hide resolved
src/Dibi/Drivers/OdbcDriver.php Outdated Show resolved Hide resolved
src/Dibi/Fluent.php Show resolved Hide resolved
src/Dibi/Helpers.php Outdated Show resolved Hide resolved
src/Dibi/Result.php Outdated Show resolved Hide resolved
src/Dibi/Result.php Show resolved Hide resolved
@dg dg force-pushed the master branch 8 times, most recently from 138139d to 81a66da Compare October 8, 2020 16:24
@dg dg force-pushed the master branch 3 times, most recently from 8db0534 to cc3b09e Compare October 15, 2020 15:19
@dg dg force-pushed the master branch 5 times, most recently from 17866e0 to 82c45c3 Compare August 9, 2023 14:38
@dg dg force-pushed the master branch 3 times, most recently from dd46ea7 to 9e71132 Compare September 29, 2023 14:07
@dg dg force-pushed the master branch 2 times, most recently from f739394 to 86a71dd Compare November 25, 2023 13:09
@dg dg force-pushed the master branch 2 times, most recently from ebee17f to 9908f6f Compare May 7, 2024 15:35
@dg dg force-pushed the master branch 2 times, most recently from b6a770f to ab68077 Compare June 18, 2024 22:28
@dg dg force-pushed the master branch 14 times, most recently from 4947fa5 to 04f006a Compare September 3, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants