Skip to content

Strict typing: Add native PHP 8.2 type declarations from the existing PHPDoc blocks#172

Open
web-dev-passion wants to merge 1 commit into
dereuromark:masterfrom
web-dev-passion:add-native-types
Open

Strict typing: Add native PHP 8.2 type declarations from the existing PHPDoc blocks#172
web-dev-passion wants to merge 1 commit into
dereuromark:masterfrom
web-dev-passion:add-native-types

Conversation

@web-dev-passion

Copy link
Copy Markdown

Strict typing: Add native PHP 8.2 type declarations from the existing PHPDoc blocks

Preamble

I've been running TinyAuth on a project and noticed most signatures still keep their types in the PHPDoc blocks only. Based on latest effort across CakePHP packages and core, I guess going to improve and leverage PHP's native type system is a welcome change. 😄

What was changed ?

Applies native parameter, return and property type declarations throughout the plugin, derived from the existing @param / @return / @var PHPDoc and confirmed against actual usage.

Left untyped on purpose

A few signatures stay loose, because tightening them would change behaviour. If you take a look into the changes you would see why.

PHP Version matching composer + README

Targets the package's PHP 8.2 minimum. PHPDoc is kept where it carries generics or array (basic) shapes (e.g. array<string, int|string>) that native types (based on PHP 8.2) cannot express.

How it was done

First pass with Rector (type-declaration set pinned to 8.2), the rest by hand.
phpstan level 8 and cs pass, test suite unchanged. Happy to adjust.

And thanks for your great work @dereuromark !

Pull @param/@return/@var down to native PHP 8.2 types across src/.
Signatures and properties only, no behaviour change. Kept the docblocks
where they hold generics native types can't (array<string, int|string>).
Left a few loose on purpose where a strict type would break callers:
persistIdentity, hasRoles, link/_default. phpstan 8 + cs green, tests unchanged.
@dereuromark

Copy link
Copy Markdown
Owner

I like it, but some of the public API changes here need to wait until the next major.
For BC reasons.
I will keep it open for now, if that's OK.

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