Skip to content

Add dynamic return type extension for date_create#1413

Merged
ondrejmirtes merged 3 commits intophpstan:1.7.xfrom
VincentLanglet:dateCreate
Jun 13, 2022
Merged

Add dynamic return type extension for date_create#1413
ondrejmirtes merged 3 commits intophpstan:1.7.xfrom
VincentLanglet:dateCreate

Conversation

@VincentLanglet
Copy link
Copy Markdown
Contributor

No description provided.

@VincentLanglet VincentLanglet marked this pull request as ready for review June 11, 2022 13:00
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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