Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Apr 30, 2022

Closes phpstan/phpstan#4927

I think it also closes phpstan/phpstan#1934. There is a lot more method listed:

  • diff
  • format
  • getOffset
  • getTimezone
  • setTime

But I never succeed to get false with those method, except when I passed a parameter with a wrong type.

$dateTime->diff('foo') // false in php 7.4, exception in 8.0

This is reported by phpstan as an error, so I don't think a returnType extension might be needed to say it's return false in php 7.4.

@VincentLanglet VincentLanglet force-pushed the dateTimeModify branch 2 times, most recently from d22c593 to 6b57ce2 Compare April 30, 2022 15:10
@VincentLanglet VincentLanglet marked this pull request as ready for review April 30, 2022 15:24
Copy link
Member

Choose a reason for hiding this comment

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

This code can cause PHPStan to report warnings: https://3v4l.org/9eHGQ The @ operator should be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

This will crash if someone calls ->modify() without args.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

I don't like the usage of inheritance here. Instead, the class name should be asked for in the constructor and the class should be registered two times with different arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

What's the scenario for this if? I'd rather have you to check count($constantStrings) === 0 first and return $defaultReturnType then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's similar too DateTimeConstructorThrowTypeExtension.

I would say it's to handle a phpdoc like 'foo'|'bar'|somethingElseWhichIsNotAConstantString or a situation

if ($foo) {
     $arg = 'foo';
} else {
    $arg = ... ;
}
$dt->modify($arg);

@VincentLanglet
Copy link
Contributor Author

I don't think the failure are related to my PR @ondrejmirtes

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Coding standard failed, otherwise it looks good to merge.

@ondrejmirtes
Copy link
Member

Also please note I changed the configuration: c2e3f22 (no backslash needed)

@VincentLanglet
Copy link
Contributor Author

Coding standard failed, otherwise it looks good to merge.

Fixed.

Also, should it target the 1.7.x branch or 1.6.x one ?

@ondrejmirtes
Copy link
Member

1.6.x would be better, thanks.

@VincentLanglet VincentLanglet changed the base branch from 1.7.x to 1.6.x May 4, 2022 14:36
@VincentLanglet
Copy link
Contributor Author

1.6.x would be better, thanks.

Done :)

@ondrejmirtes ondrejmirtes merged commit a8a37ed into phpstan:1.6.x May 4, 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.

Missing potential false on DateTime::modify DateTime and DateTimeImmutable can return FALSE on failure, comparison issue

2 participants