Skip to content

PhpStan fixes#364

Open
janbarasek wants to merge 4 commits intodg:masterfrom
janbarasek:phpstan
Open

PhpStan fixes#364
janbarasek wants to merge 4 commits intodg:masterfrom
janbarasek:phpstan

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 3 times, most recently from 45c0839 to 8881eb1 Compare November 29, 2021 12:49
@dg dg force-pushed the master branch 9 times, most recently from 0bdf956 to 96da320 Compare December 12, 2021 17:00
@dg dg force-pushed the master branch 2 times, most recently from cefe754 to ca42569 Compare January 19, 2022 17:39
@dg dg force-pushed the master branch 2 times, most recently from 3a61c9e to b47c9cc Compare September 6, 2022 02:34
@dg dg force-pushed the master branch 2 times, most recently from d77bdd6 to 1585255 Compare October 13, 2022 02:02
@dg dg force-pushed the master branch 2 times, most recently from 16765c4 to cab1c5b Compare November 18, 2022 03:46
@dg dg force-pushed the master branch 2 times, most recently from 0ee3834 to fafa6cb Compare August 5, 2023 18:24
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