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

Make the code easier to statically analyse #10231

Merged
merged 1 commit into from Nov 16, 2022

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented Nov 14, 2022

While working on migrating the codebase to PHP 8, I noticed that a rule (NullToStrictStringFuncCallArgRector) often triggered that consists in adding casts to string, because internal functions have become more strict in PHP 8.1 (they no longer accept anything than a string).

I tried finding why those arguments were not considered already strings, and tried to fix some of that with this PR.

@@ -1631,7 +1631,7 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
/**
* Validates & completes the basic mapping information based on typed property.
*
* @param mixed[] $mapping The mapping.
* @param array{type: self::ONE_TO_ONE|self::MANY_TO_ONE|self::ONE_TO_MANY|self::MANY_TO_MANY, fieldName: string, targetEntity?: class-string} $mapping The mapping.
Copy link
Member Author

@greg0ire greg0ire Nov 14, 2022

Choose a reason for hiding this comment

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

I couldn't find a way to make this multiline and have phpcs be happy with it… it's probably the pipes.

*/
private function quoteLiteral($literal): string
{
if (is_numeric($literal) && ! is_string($literal)) {
if (is_int($literal) || is_float($literal)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

About this, see vimeo/psalm#8703

@greg0ire greg0ire added this to the 2.14.0 milestone Nov 16, 2022
@greg0ire greg0ire merged commit 1ce806f into doctrine:2.14.x Nov 16, 2022
@greg0ire greg0ire deleted the static-analysis-improvements branch November 16, 2022 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants