Skip to content

Generated code for required timestamp fields does not work for static analysis for json-rpc #2128

Description

@stof

The generated code tries to use a @var annotation to override the type:

$body = '/** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat(\'U.u\', \sprintf(\'%.6F\', INPUT))';

But this does not actually work in Psalm or phpstan.
For Psalm, we have some baseline entries for it:

aws/psalm.baseline.xml

Lines 65 to 74 in 77164a2

<file src="src/Service/StepFunctions/src/Result/StartExecutionOutput.php">
<PossiblyFalsePropertyAssignmentValue>
<code><![CDATA[$d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['startDate']))]]></code>
</PossiblyFalsePropertyAssignmentValue>
</file>
<file src="src/Service/StepFunctions/src/Result/StopExecutionOutput.php">
<PossiblyFalsePropertyAssignmentValue>
<code><![CDATA[$d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['stopDate']))]]></code>
</PossiblyFalsePropertyAssignmentValue>
</file>

For phpstan, it is not reported because we run it at level 6 while it is a level 7 error. But phpstan also reports it when enabling the rule:
https://phpstan.org/r/703f04fc-5f50-490b-a3c1-7707275aed22 (this includes variants of the comment to see whether they would have worked).
We should find a better way to generate this code so that generated code does not require updating the baseline when such usage appears.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions