Skip to content

Fix lowercase string usage in template #4122

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

Merged

Conversation

VincentLanglet
Copy link
Contributor

Closes phpstan/phpstan#12739

Seems like the issue is related to the fact that
ScalarType<string> and ScalarType<lowercase-string> had the same cacheKey or something like that.

AccessoryLowercaseStringType and AccessoryUppercaseStringType was lost for level::cache because the check was only isPrecise.

So I added $level->isCache() and updated every $level->isPrecise() checks (with tests).
But I dunno if it's not better to do something like

public function isPrecise(): bool
{
     return $this->value === self::PRECISE || $this->value === self::CACHE;
}

(And eventually rename the method to isAtLeastPrecise ? Your call @ondrejmirtes.

@VincentLanglet VincentLanglet force-pushed the fix/generic-lowercase-string branch 2 times, most recently from d95ae63 to b4eff06 Compare July 19, 2025 18:56
}

/**
* @extends ScalarType<lowercase-string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the fix also affect other string types, which should be tested here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, uppercaseString.
I added a test.

@VincentLanglet VincentLanglet requested a review from staabm July 20, 2025 09:42
@ondrejmirtes
Copy link
Member

There's a conflict, please fix it.

Thank you for the fix. This API is not used often enough for me to be able to come up with a better design, most places use handle function. So this PR is fine, just rebase it 😊 Thank you.

@VincentLanglet VincentLanglet force-pushed the fix/generic-lowercase-string branch from f8edc8c to 7e9cb46 Compare July 21, 2025 13:05
@ondrejmirtes ondrejmirtes merged commit 8e8eca7 into phpstan:2.1.x Jul 21, 2025
414 of 419 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

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.

lowercase-string not correct in templates
3 participants