Check datetime instantiation#380
Merged
ondrejmirtes merged 2 commits intophpstan:masterfrom Nov 24, 2020
Merged
Conversation
532cd52 to
8515526
Compare
ondrejmirtes
requested changes
Nov 23, 2020
Member
ondrejmirtes
left a comment
There was a problem hiding this comment.
And finally, please fix the build (Failures on PHP 8 are fine - they're on master already.)
8515526 to
4ddfe40
Compare
ondrejmirtes
requested changes
Nov 23, 2020
Member
ondrejmirtes
left a comment
There was a problem hiding this comment.
This actually needs fixing:
Cannot access offset 'warnings' on array('warning_count' => int,
'warnings' => array<int, string>, 'error_count' => int, 'errors' =>
array<int, string>)|false.
Contributor
Author
|
Where that false comes from? I can’t reproduce returning false by that method.
Отправлено с iPhone
… 24 нояб. 2020 г., в 01:23, Ondřej Mirtes ***@***.***> написал(а):
@ondrejmirtes requested changes on this pull request.
This actually needs fixing:
Cannot access offset 'warnings' on array('warning_count' => int,
'warnings' => array<int, string>, 'error_count' => int, 'errors' =>
array<int, string>)|false.
In src/Rules/DateTimeInstantiationRule.php:
> + public function getNodeType(): string
+ {
+ return New_::class;
+ }
+
+ /**
+ * @param New_ $node
+ */
+ public function processNode(Node $node, Scope $scope): array
+ {
+ if (
+ !($node->class instanceof \PhpParser\Node\Name)
+ || \count($node->args) === 0
+ || (
+ strtolower((string) $node->class) !== strtolower(DateTime::class)
+ && strtolower((string) $node->class) !== strtolower(DateTimeImmutable::class)
This unnecessarily calls strtolower((string) $node->class) twice.
You can hardcode datetime instead.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Member
|
@b1rdex That's easy: https://3v4l.org/HBq0q |
Member
|
It tells me that you haven't tested a case where the rule should not report anything :) |
Contributor
Author
|
Actually there are tests with no errors. I haven’t tried calling it without constructing a date. Ok, will fix it tomorrow.
Отправлено с iPhone
… 24 нояб. 2020 г., в 01:39, Anatoly Pashin ***@***.***> написал(а):
Where that false comes from? I can’t reproduce returning false by that method.
Отправлено с iPhone
>> 24 нояб. 2020 г., в 01:23, Ondřej Mirtes ***@***.***> написал(а):
>>
>
> @ondrejmirtes requested changes on this pull request.
>
> This actually needs fixing:
>
> Cannot access offset 'warnings' on array('warning_count' => int,
> 'warnings' => array<int, string>, 'error_count' => int, 'errors' =>
> array<int, string>)|false.
> In src/Rules/DateTimeInstantiationRule.php:
>
> > + public function getNodeType(): string
> + {
> + return New_::class;
> + }
> +
> + /**
> + * @param New_ $node
> + */
> + public function processNode(Node $node, Scope $scope): array
> + {
> + if (
> + !($node->class instanceof \PhpParser\Node\Name)
> + || \count($node->args) === 0
> + || (
> + strtolower((string) $node->class) !== strtolower(DateTime::class)
> + && strtolower((string) $node->class) !== strtolower(DateTimeImmutable::class)
> This unnecessarily calls strtolower((string) $node->class) twice.
> You can hardcode datetime instead.
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub, or unsubscribe.
|
4ddfe40 to
db4aba0
Compare
ondrejmirtes
requested changes
Nov 24, 2020
Member
|
Thank you! |
Member
|
FYI I removed reporting warnings because it's not that useful: https://3v4l.org/TGsaG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes phpstan/phpstan#4096