CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

style: Enable `phpdoc_list_type` fixer

Open paulbalandan opened this issue 1 year ago • 5 comments

Description Enables phpdoc_list_type, changing array phpdocs with implicit keys to list, e.g. array<string> => list<string>. Then let phpstan catch incorrect usages.

If approved, don't merge yet so this can be applied in the coding standard repo and minimize updating the overrides here.

Checklist:

  • [x] Securely signed commits
  • [ ] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [ ] Unit testing, with >80% coverage
  • [ ] User guide updated
  • [x] Conforms to style guide

paulbalandan avatar Feb 09 '24 13:02 paulbalandan

:wave: Hi, @paulbalandan!

We detected conflicts in your PR against the base branch :speak_no_evil:
You may want to sync :arrows_counterclockwise: your branch with upstream!

Ref: Syncing Your Branch

github-actions[bot] avatar Feb 10 '24 00:02 github-actions[bot]

@paulbalandan Sorry, I've changed to use @property-read. See #8519. Can you update coding-standard with that?

kenjis avatar Feb 10 '24 00:02 kenjis

phpdoc_list_type is risky. https://cs.symfony.com/doc/rules/phpdoc/phpdoc_list_type.html

I'm not sure we should enable this rule by default.

kenjis avatar Feb 10 '24 00:02 kenjis

Yes, it is risky by the reasoning behind it.

If we make a phpdoc like Foo[], I think we almost always mean the same way when we push to an array, like $a[] = Foo;, so Foo[] here would mean a list of Foo, i.e., array<int, Foo>. If we mean a string key, we should have indicated it like array<string, Foo>, right?

paulbalandan avatar Feb 14 '24 17:02 paulbalandan

If we make a phpdoc like Foo[], I think we almost always mean the same way when we push to an array, like $a[] = Foo;, so Foo[] here would mean a list of Foo, i.e., array<int, Foo>. If we mean a string key, we should have indicated it like array<string, Foo>, right?

I checked all the changes in this PR, and you are right. I agree that most PHP devs think like that.

I agree to enable phpdoc_list_type.

kenjis avatar Feb 14 '24 23:02 kenjis

To be merged once latest coding-standard is out.

paulbalandan avatar Feb 24 '24 13:02 paulbalandan