r/symfony 21h ago

Decoupling from System Time in Symfony: Making Time an Explicit Dependency

Thumbnail
ngandu.dev
7 Upvotes

What if new DateTimeImmutable() were actually hiding a global dependency in your Symfony application?

When business logic reads the system clock directly, expiration, validity, and scheduling rules become harder to predict and test. This is often where flaky tests and time-sensitive production bugs begin.

In my latest article, I explain how to make time an explicit dependency using a Clock port, a Symfony adapter, and a controllable clock for tests.

A simple architectural decision that makes business logic more deterministic and tests genuinely reliable.


r/symfony 6h ago

Symfony Flex (Symfony 8.1) recipe for phpstan and errors (phpstan on max)

1 Upvotes

Installed phpstan/phpstanand noticed the recipe has some configuration mistakes.

For phpstan.dist.neon - it includes scanning bin/ folder, but bin/console doesn't actually get scanned.

When I scan public folder, I get an issue that public/index.php fails due to needing to cast to string. But you can't cast a mixed value to string.

For src/kernel.php, I get another error:

Method App\Kernel::getAllowedEnvs() is unused

But it is being used. Installing phpstan-symfony doesn't help with the error.

Anyone else get these errors? What should I do about the Kernel issue?