= 8_03_00) { $this->expectException(Exception::class); $this->expectExceptionMessage('DateTime::modify(): Failed to parse time string (foo) at position 0 (f)'); } $this->addFile( 'somefile.php', 'modify(getString()); $b = $dateTimeImmutable->modify(getString());', ); $this->analyzeFile('somefile.php', $context); $this->assertSame('false', $context->vars_in_scope['$a']->getId(true)); $this->assertSame('false', $context->vars_in_scope['$b']->getId(true)); } public function testModifyWithBothConstant(): void { $context = new Context(); if (PHP_VERSION_ID >= 8_03_00) { $this->expectException(Exception::class); $this->expectExceptionMessage('DateTime::modify(): Failed to parse time string (bar) at position 0 (b)'); } $this->addFile( 'somefile.php', 'modify(getString()); $b = $dateTimeImmutable->modify(getString());', ); $this->analyzeFile('somefile.php', $context); $this->assertSame('DateTime|false', $context->vars_in_scope['$a']->getId(false)); $this->assertSame('DateTimeImmutable|false', $context->vars_in_scope['$b']->getId(false)); } public function providerValidCodeParse(): iterable { return [ 'modify' => [ 'code' => 'modify(getString()); $b = $dateTimeImmutable->modify(getString()); ', 'assertions' => [ '$a' => 'DateTime|false', '$b' => 'DateTimeImmutable|false', ], ], 'modifyWithValidConstant' => [ 'code' => 'modify(getString()); $b = $dateTimeImmutable->modify(getString()); ', 'assertions' => [ '$a' => 'DateTime', '$b' => 'DateTimeImmutable', ], ], 'otherMethodAfterModify' => [ 'code' => 'modify("+1 day")->setTime(0, 0); $b = $dateTimeImmutable->modify("+1 day")->setTime(0, 0); ', 'assertions' => [ '$a' => 'DateTime', '$b' => 'DateTimeImmutable', ], ], 'modifyStaticReturn' => [ 'code' => 'modify("+7 days"); ', 'assertions' => [ '$mod' => 'Subclass', ], ], 'otherMethodAfterModifyStaticReturn' => [ 'code' => 'modify("+1 day")->setTime(0, 0); ', 'assertions' => [ '$mod' => 'Subclass', ], ], 'formatAfterModify' => [ 'code' => 'modify("+1 day")->format("Y-m-d"); $b = $dateTimeImmutable->modify("+1 day")->format("Y-m-d"); ', 'assertions' => [ '$a' => 'false|string', '$b' => 'string', ], ], 'formatAfterModifyStaticReturn' => [ 'code' => 'modify("+1 day")->format("Y-m-d"); ', 'assertions' => [ '$format' => 'string', ], ], ]; } }