Closed matthewhilton closed 8 months ago
Hi @matthewhilton ,
As it happens I'm in the process of trying to fix this and related issues.
This particular issue comes from the sister project we're trying to wind down - https://github.com/moodlehq/moodle-local_moodlecheck
Over the next few weeks/months we're trying to move all sniffs from there to this project at which point this issue should go away.
I have also struggled to find an official way to document these, but the consensus I've come across seems to be:
class example {
/**
* Constructor.
*
* @param string $example The constructor argument
*/
public function __construct(
/** @var string The property description */
public readonly string $example,
) {
}
}
Oh, and the {{@property-read}} class tag is for magic properties.
And see https://github.com/moodlehq/moodle-local_moodlecheck/pull/129 where there's a PR there too.
Some references:
Note: This syntax does also work with the latest versions of phpdoc.
I think that this can be safely closed now, as far as both the legacy tool (local_moodlecheck) and this (moodle-cs) are working ok with the readonly
keyword.
Plus we already have the @var
phpdocs to work with those promoted properties (read only or no) in moodle-cs.
So, proceeding. If there is anything else pending, don't hesitate to ping me here.
Ciao :-)
Apologies if this is not the correct place to raise this; It's related to moodlecheck/phpdoc but I can see there is an effort to migrate the moodlecheck/phpdoc checks to this plugin, so i'm logging it here.
I've recently added a class using constructor promotion https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor.promotion and have set the param/property to
protected readonly
But this spits out the error
Phpdocs for function test::__construct has incomplete parameters list (error)
. If you remove thereadonly
(but leaveprotected
), it passes.Example class:
It looks as though phpdoc says nothing about this either https://docs.phpdoc.org/latest/guide/references/phpdoc/tags/param.html
I tried various combinations e.g.
@param-readonly
,@property-read
but no luck