Skip to content

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.

{
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.

@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 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
@dg dg force-pushed the master branch 2 times, most recently from 60c2108 to 514bd23 Compare March 30, 2025 17:41
@dg dg force-pushed the master branch 5 times, most recently from 8157984 to 4ea907a Compare August 6, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants