Skip to content

Add dynamic return type extension for date_create #1413

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
merged 3 commits into from
Jun 13, 2022

Conversation

VincentLanglet
Copy link
Contributor

No description provided.

@VincentLanglet VincentLanglet marked this pull request as ready for review June 11, 2022 13:00
use function in_array;

class DateTimeDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
{

public function isFunctionSupported(FunctionReflection $functionReflection): bool
{
return in_array($functionReflection->getName(), ['date_create_from_format', 'date_create_immutable_from_format'], true);
return in_array($functionReflection->getName(), ['date_create', 'date_create_immutable'], true);
Copy link
Member

Choose a reason for hiding this comment

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

I can't read this diff. Please give a different name to your new extension and don't change an existing file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diff should be better now.

$datetime = $scope->getType($functionCall->getArgs()[0]->value);

if (!$datetime instanceof ConstantStringType) {
return $defaultReturnType;
Copy link
Member

Choose a reason for hiding this comment

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

The code of the extension can be simplified now. Instead of $defaultReturnType, you can simply return null 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.

Is it better now ?

@ondrejmirtes ondrejmirtes merged commit edd5fd1 into phpstan:1.7.x Jun 13, 2022
@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.

2 participants