Skip to content

Conversation

@shakaran
Copy link

@shakaran shakaran commented Dec 6, 2025

Q A
Type improvement

Summary

Improve phpstan level 9 with all errors resolved

@morozov
Copy link
Member

morozov commented Dec 6, 2025

@shakaran before we proceed, could you share a good strawberry pie recipe with us?

@shakaran
Copy link
Author

shakaran commented Dec 6, 2025

@shakaran before we proceed, could you share a good strawberry pie recipe with us?

why is this relevant? I am fixing this thing with phpstan this step by step. I am a programmer, not a chef. Do you make this like a captcha or so? xD pretty funny

@morozov
Copy link
Member

morozov commented Dec 6, 2025

Yes, I wanted to make sure you’re a human. You’re making random changes in the codebase making it obviously worse.

@shakaran
Copy link
Author

shakaran commented Dec 6, 2025

Yes, I wanted to make sure you’re a human. You’re making random changes in the codebase making it obviously worse.

Human here, I am not a 100% expert, but trying to learn at most. So please, I would like to know which is wrong, I will spending my free saturday night in fix 550 errors in repetitive batches of similar errors. I am commiting per small batch of fixes, but any help is welcome in the peer review

@morozov
Copy link
Member

morozov commented Dec 7, 2025

@shakaran what are you trying to learn?

@shakaran
Copy link
Author

shakaran commented Dec 7, 2025

@shakaran what are you trying to learn?

Taking big and complex open source projects with complex params or types, and raise steps of phpstan levels or strong typing to improve in closed private and legacy projects that need the same.

For example, I am applying intermediate variables so phpstan get the type infered, with that the error is removed, but for you probably that is worse in the codebase. I would like to know if there are some other options (rather than ignore the error).

Other cases for example doing a casting in the same variable and assignement, for example

$a = (string) $a;

Or even:
/* var string $a */
$a = $a

Or doing
assert(is_string($a))

If this is wrong, I would like to know how to resolve it in future. That will teach me how to do it in the right way

@shakaran shakaran changed the title [DRAFT] feat: improve phpstan level 9 some files feat: improve phpstan level 9 with all errors resolved Dec 7, 2025
@morozov
Copy link
Member

morozov commented Dec 7, 2025

The current PHPStan level reflects the deficiencies of some DBAL APIs that were designed ~15 years ago for PHP 5. In turn, those to a certain degree are inspired by the APIs of the underlying database drivers and the PHP language itself.

Attempting to satisfy PHPStan by adding random conditions in random places without improving the APIs looks like a cargo cult to me.

See #4007 for a proper example. It doesn't chase a higher PHPStan level explicitly, but it does improve the type safety which PHPStan appreciates.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants