Skip to content
Permalink
Browse files

Warn about unnecessary use of DateTimeImmutable

  • Loading branch information...
muglug committed Sep 3, 2019
1 parent 8601731 commit de5df1e36ab6006ef976c72e1329dbf3a0bb1fed
@@ -1105,6 +1105,27 @@ function (PhpParser\Node\Arg $arg) {
$static_type,
$class_storage->parent_class
);
if ($fq_class_name === 'DateTimeImmutable'
&& !$context->inside_conditional
&& !$context->inside_unset
) {
if (!$context->inside_assignment && !$context->inside_call) {
if (IssueBuffer::accepts(
new \Psalm\Issue\UnusedMethodCall(
'The call to ' . $method_id . ' is not used',
new CodeLocation($statements_analyzer, $stmt->name),
$method_id
),
$statements_analyzer->getSuppressedIssues()
)) {
// fall through
}
} else {
/** @psalm-suppress UndefinedPropertyAssignment */
$stmt->pure = true;
}
}
} else {
$name_code_location = new CodeLocation($source, $stmt->name);
@@ -70,6 +70,8 @@ public function registerClass(\ReflectionClass $reflected_class)
$storage->potential_declaring_method_ids['__construct'][$class_name_lower . '::__construct'] = true;
$storage->mutation_free = $class_name === 'DateTimeImmutable';
if ($reflected_parent_class) {
$parent_class_name = $reflected_parent_class->getName();
$this->registerClass($reflected_parent_class);
@@ -870,7 +870,14 @@ public function getShort() : string {
$a = new A("hello");
$a->getShort();',
'error_message' => 'UnusedMethodCall',
]
],
'dateTimeImmutable' => [
'<?php
function foo(DateTimeImmutable $dt) : void {
$dt->modify("+1 day");
}',
'error_message' => 'UnusedMethodCall',
],
];
}
}

0 comments on commit de5df1e

Please sign in to comment.
You can’t perform that action at this time.