Skip to content

Port MoodlePHPdoc check function types check - #227

Open
james-cnz wants to merge 1 commit into
moodlehq:mainfrom
james-cnz:phpdoc_types_test_2
Open

Port MoodlePHPdoc check function types check#227
james-cnz wants to merge 1 commit into
moodlehq:mainfrom
james-cnz:phpdoc_types_test_2

Conversation

@james-cnz

@james-cnz james-cnz commented Jun 19, 2026

Copy link
Copy Markdown

This is a PHPDoc types check intended to be similar in scope to the MoodlePHPdoc check one.

It is a bit more permissive in a few respects:

  • It makes some basic effort to allow PHPDoc types to be subtypes of the native type. (I believe this is standard to PHPDoc types.)
  • It allows mixed type arrays, e.g. (a|b)[] . (This is supported by PHP-FIG PSR-5.)
  • It allows PHPDoc param annotations to contain pass by reference or splat.

But, AFAIK, it is only stricter in one way:

  • If the native type contains null, the PHPDoc type must too. [EDIT: Sorry, I mean the other way round. If the Doc type contains null, the native type must too.]
    [EDIT: It looks like the existing checks fail to check PHPDocs that are separated from the function by an attribute, so it's also stricter in that way.]

As with the existing test, it makes no effort to syntax check types, check namespaces, match return types, or do any checking on variables.
And it passes existing tests.
So I don't think it should cause too much disruption.

@james-cnz
james-cnz force-pushed the phpdoc_types_test_2 branch 2 times, most recently from e778e57 to ce11489 Compare June 20, 2026 04:38
@james-cnz

Copy link
Copy Markdown
Author

I forgot about parentheses in types.

@james-cnz

Copy link
Copy Markdown
Author

I've made the type simplification aware of well-formedness of types. It doesn't make much difference now, but would make it easier to include a check that types are well-formed in the future, if desired.

@james-cnz

Copy link
Copy Markdown
Author

I forgot about the type "$this".

@james-cnz
james-cnz force-pushed the phpdoc_types_test_2 branch 2 times, most recently from c99bc21 to 001b846 Compare July 16, 2026 04:18
@james-cnz

Copy link
Copy Markdown
Author

I've improved subtype recognition a bit, to support, e.g. MDL-83375.

@james-cnz
james-cnz force-pushed the phpdoc_types_test_2 branch 2 times, most recently from 5470dc1 to 0ca7701 Compare July 22, 2026 01:05
@james-cnz

Copy link
Copy Markdown
Author

Improved error messages a bit, to help address MDLSITE-3694.

@james-cnz
james-cnz force-pushed the phpdoc_types_test_2 branch from 0ca7701 to 2d25bd6 Compare August 4, 2026 00:43
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.

1 participant