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
Check datetime instantiation #380
Conversation
532cd52
to
8515526
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And finally, please fix the build (Failures on PHP 8 are fine - they're on master already.)
8515526
to
4ddfe40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
|
@b1rdex That's easy: https://3v4l.org/HBq0q |
It tells me that you haven't tested a case where the rule should not report anything :) |
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
Thank you! |
FYI I removed reporting warnings because it's not that useful: https://3v4l.org/TGsaG |
Fixes phpstan/phpstan#4096