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

Fix phpstan errors #3824

Merged
merged 1 commit into from
Jan 17, 2020
Merged

Fix phpstan errors #3824

merged 1 commit into from
Jan 17, 2020

Conversation

BenMorel
Copy link
Contributor

@BenMorel BenMorel commented Jan 16, 2020

Q A
Type improvement
BC Break no
Fixed issues none

Summary

Fixes more phpstan errors, as suggested in #3801.

@BenMorel
Copy link
Contributor Author

@morozov I don't know how to best handle the last 3 errors:

  • 2 tests forcibly use a wrong type to ensure that an exception is thrown, but of course this makes phpstan unhappy:

$this->platform->getDropIndexSQL(['index'], 'table');

  • Here array_keys() is called on an array that only has string keys, but phpstan doesn't understand this, and assumes that the result is an array containing int|string:

throw NonUniqueAlias::new($join['joinAlias'], array_keys($knownAliases));

Any advice?

Copy link
Member

@morozov morozov left a comment

Choose a reason for hiding this comment

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

2 tests forcibly use a wrong type to ensure that an exception is thrown, but of course this makes phpstan unhappy

Drop them. This is what PHPStan is for :-)

Here array_keys() is called on an array that only has string keys, but phpstan doesn't understand this, and assumes that the result is an array containing int|string

It should have been fixed as per phpstan/phpstan#1847 but it seems it isn't. It looks like out of the two related suppressions only one is needed (the other is already removed in master, please rebase). Please leave the remaining one for now, file a PHPStan issue that would reproduce our case in their sandbox (same as it was done in phpstan/phpstan#1847) and update the reference to point to the newly created issue in our PHPStan configuration.

lib/Doctrine/DBAL/Logging/SQLLogger.php Show resolved Hide resolved
lib/Doctrine/DBAL/Query/QueryBuilder.php Show resolved Hide resolved
@BenMorel
Copy link
Contributor Author

Drop them. This is what PHPStan is for :-)

Done!

please rebase

Done.

It should have been fixed as per phpstan/phpstan#1847 but it seems it isn't.

Strangely, it doesn't happen in their sandbox:

https://phpstan.org/r/eea2b886-3942-425d-8ecd-b50489599ff5

I've double checked, the fix should be included in the phpstan version we're using, too, so I don't understand. Any idea?

@morozov
Copy link
Member

morozov commented Jan 16, 2020

I've double checked, the fix should be included in the phpstan version we're using, too, so I don't understand. Any idea?

The difference may be in the config. Please put together the simplest possible example that gets flagged with our version and config and then see if it depends on the config. Then report whatever reproducible issue. IIRC, not all issues are reproducible in the sandbox (e.g. phpstan/phpstan#2510).

@BenMorel
Copy link
Contributor Author

Finally reproduced it, and reported as phpstan/phpstan#2857.

I forgot to include the exception class in the sandbox, obviously. But for some reason phpstan didn't complain about the missing class at all.

phpstan.neon.dist Outdated Show resolved Hide resolved
@BenMorel
Copy link
Contributor Author

@morozov All good now! 👍

@morozov
Copy link
Member

morozov commented Jan 17, 2020

@BenMorel, looks good! Please squash.

@morozov
Copy link
Member

morozov commented Jan 17, 2020

To get rid of the remaining PHPStan issue, we may replace the associative array representing a join in the Query Builder with an object similar to DependencyOrderNode used in #3762. This way, we will not only help static analyzers understand which properties and of what types a join has but also may help PHP manage memory more efficiently:

  1. https://steemit.com/php/@crell/php-use-associative-arrays-basically-never
  2. https://youtu.be/JBWgvUrb-q8?t=943

@BenMorel
Copy link
Contributor Author

Please squash.

Just for my information, what's wrong with the "Squash & Merge" button on GitHub?

To get rid of the remaining PHPStan issue, we may replace the associative array representing a join in the Query Builder with an object similar to DependencyOrderNode used in #3762.

I'd love to replace associative arrays with objects. I may try to play with this next.

@morozov
Copy link
Member

morozov commented Jan 17, 2020

Just for my information, what's wrong with the "Squash & Merge" button on GitHub?

  1. There won't be a merge commit, the changes will be squashed and just committed to the target branch (ref). We want to have merge commits in the repo for better attribution.
  2. If a contributor sings their commits, they will also sign the squashed one. Otherwise, if squashed by GitHub, the resulting commit will be signed by GitHub, not by the contributor.

@BenMorel
Copy link
Contributor Author

@morozov Thanks. Squashed!

@morozov morozov merged commit 6e4599d into doctrine:master Jan 17, 2020
@morozov
Copy link
Member

morozov commented Jan 17, 2020

Thanks, @BenMorel!

@morozov morozov self-assigned this Jan 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants