moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 16 forks source link

"Missing member variable doc comment" in the constructor arguments that are class properties #150

Closed marinaglancy closed 7 months ago

marinaglancy commented 7 months ago
~/repositories/moodle-plugin-ci/vendor/bin/phpcs mod/lti/classes/output/course_tools_page_header.php

FILE: /.../mod/lti/classes/output/course_tools_page_header.php
----------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------
 38 | ERROR | Missing member variable doc comment
 38 | ERROR | Missing member variable doc comment
 38 | ERROR | Missing member variable doc comment
----------------------------------------------------------------------------------------------------------------

This is the code of the respective file: https://github.com/moodle/moodle/blob/v4.3.3/mod/lti/classes/output/course_tools_page_header.php#L31-L39

    /**
     * Constructor.
     *
     * @param int $courseid the course id.
     * @param int $toolcount the number of tools available in the course.
     * @param bool $canadd whether the user can add tools to the course or not.
     */
    public function __construct(protected int $courseid, protected int $toolcount, protected bool $canadd) {
    }

This is different from https://github.com/moodlehq/moodle-cs/issues/142 because the arguments have the word "protected" in front of them, which makes them class properties

andrewnicols commented 7 months ago

The Sniff is correct -- the variables are not documented.

 /**
     * Constructor.
     *
     * @param int $courseid the course id.
     * @param int $toolcount the number of tools available in the course.
     * @param bool $canadd whether the user can add tools to the course or not.
     */
    public function __construct(
        /** @var int ID of the course */
        protected int $courseid,
        /** @var int The number of tools */
        protected int $toolcount,
        /** @var  bool Whether the user can add tools to the course */
        protected bool $canadd.
    ) {
    }
marinaglancy commented 7 months ago

Thanks Andrew,

btw this syntax fails in the previous version (using local_moodlecheck) which is quite annoying but we can't really change it