moodlehq/moodle-cs
Moodle Coding Sniffer rules
v3.7.0
3.5M downloads/mo
#1883 most downloaded on Packagist
moodlehq/moodle-cs
What this package is like to depend on
Last release 8 months ago
02 Dec 2025
Ships unpredictably
gaps range from 9 days to 12 months
Most releases are documented
notes for 34 of 39 stable releases
Nothing withdrawn
no release was ever pulled
4 years old
40 releases · first in 2022
2 releases in the last 12 months
see the full history below
Release timeline
40 releases · Feb 2022 to Dec 2025Releases
latest 40-
v3.7.002 Dec 2025Release notes
Open source →Removed
- Support for PHPCompatibility until moodle-cs is upgraded to support PHP_CodeSniffer version 4.
Take a look at the CHANGELOG for details about other releases.
-
v3.6.009 Sep 2025Release notes
Open source →Removed
- Automated fixes for the following sniffs were removed as they can cause unwanted changes:
moodle.NamingConventions.ValidFunctionNamemoodle.NamingConventions.ValidVariableName
Changed
- Dropped the following deprecated sniffs:
Squiz.Classes.DuplicateProperty- JS onlyGeneric.Functions.CallTimePassByReference- PHP support dropped in PHP 5.4
Fixed
- Update incorrect use of legacy ruleset format.
- Automated fixes for the following sniffs were removed as they can cause unwanted changes:
-
v3.5.214 Aug 2025Release notes
Open source →Fixed
- The branch detector was not able to detect the Moodle version following MDL-83424.
- The
moodle.PHPUnit.TestCaseProvidersniff can now detect fully-qualified class names.
Added
- A new
NamespaceScopeUtilhelper was added with methods to help qualify names within a file.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Fixed
- The branch detector was not able to detect the Moodle version following MDL-83424.
- The
moodle.PHPUnit.TestCaseProvidersniff can now detect fully-qualified class names.
Added
- A new
NamespaceScopeUtilhelper was added with methods to help qualify names within a file.
-
v3.5.130 Jul 2025Release notes
Open source →Fixed
- The
moodle.Commenting.VariableCommentsniff now accepts the following tags as valid on a@var:@since@link@deprecated
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Fixed
- The
moodle.Commenting.VariableCommentsniff now accepts the following tags as valid on a@var:@since@link@deprecated
- The
-
v3.5.017 Jul 2025Release notes
Open source →Changed
- Bumped dependencies for:
squizlabs/php_codesnifferto 3.13.2phpcsstandards/phpcsextrato 1.4.0dealerdirect/phpcodesniffer-composer-installerto 1.1.1
- A number of legacy Moodle rules have been removed. See MDLSITE-7597 for further information.
- The
Generic.Arrays.DisallowLongArraySyntaxrule has been changed to an error as planned in #58. - The list of global variables has been updated to reflect the complete list of globals used in Moodle #182.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Changed
- Bumped dependencies for:
squizlabs/php_codesnifferto 3.13.2phpcsstandards/phpcsextrato 1.4.0dealerdirect/phpcodesniffer-composer-installerto 1.1.1
- A number of legacy Moodle rules have been removed. See MDLSITE-7597 for further information.
- The
Generic.Arrays.DisallowLongArraySyntaxrule has been changed to an error as planned in #58. - The list of global variables has been updated to reflect the complete list of globals used in Moodle #182.
- Bumped dependencies for:
-
v3.4.1126 Jun 2025Release notes
Open source →Fixed
- The
moodle.Commenting.InlineCommentsniff will now accept a full-stop inside a closing parentheses as valid English. - The
@Transformtag is now an accepted tag for Behat tests - The
moodle.Commenting.InlineCommentsniff is now aware of PHPenumtypes.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Fixed
- The
moodle.Commenting.InlineCommentsniff will now accept a full-stop inside a closing parentheses as valid English. - The
@Transformtag is now an accepted tag for Behat tests - The
moodle.Commenting.InlineCommentsniff is now aware of PHPenumtypes.
- The
-
v3.4.1004 Jul 2024Release notes
Open source →Changed
- The
moodle.NamingConventions.ValidFunctionNamesniff will now ignore errors on methods employing the#[\Override]attribute. - The
moodle.Commenting.MissingDocblocksniff no longer warns about missing docs on non-global anonymous classes, for example those written as an instance class in a unit test.
Fixed
- Fixed an edge case leading to the file phpdoc block being incorrectly detected by various sniffs.
- Fixed a couple of problems with the
moodle.Files.BoilerplateCommentrelated to empty comment lines and to comments in the<?phpopen tag line.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Changed
- The
moodle.NamingConventions.ValidFunctionNamesniff will now ignore errors on methods employing the#[\Override]attribute. - The
moodle.Commenting.MissingDocblocksniff no longer warns about missing docs on non-global anonymous classes, for example those written as an instance class in a unit test.
Fixed
- Fixed an edge case leading to the file phpdoc block being incorrectly detected by various sniffs.
- Fixed a couple of problems with the
moodle.Files.BoilerplateCommentrelated to empty comment lines and to comments in the<?phpopen tag line.
- The
-
v3.4.919 Jun 2024Release notes
Open source →Fixed
- Fixed a recent regression by allowing to the
moodle.Files.BoilerplateCommentsniff to contain "extra" consecutive comment lines immediately after the official boilerplate ends.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Fixed
- Fixed a recent regression by allowing to the
moodle.Files.BoilerplateCommentsniff to contain "extra" consecutive comment lines immediately after the official boilerplate ends.
- Fixed a recent regression by allowing to the
-
v3.4.814 Jun 2024Release notes
Open source →Added
- The existing
moodle.PHPUnit.TestCaseCoverssniff now detects multiple uses of the@coversDefaultClassannotation. Only one is allowed by class. - The existing
moodle.Files.BoilerplateCommentsniff now performs more checks (spacing, placement, blank lines, ...) and is able to fix many of them.
Changed
- Made codes for
moodle.Commenting.MissingDocblockmore specific to the scenario (Fixes #154).
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Added
- The existing
moodle.PHPUnit.TestCaseCoverssniff now detects multiple uses of the@coversDefaultClassannotation. Only one is allowed by class. - The existing
moodle.Files.BoilerplateCommentsniff now performs more checks (spacing, placement, blank lines, ...) and is able to fix many of them.
Changed
- Made codes for
moodle.Commenting.MissingDocblockmore specific to the scenario (Fixes #154).
- The existing
-
v3.4.731 May 2024Release notes
Open source →Added
- Add new
moodle.PHPUnit.ParentSetUpTearDownsniff to verify, among other things, that all thesetUp(),tearDown(),setUpBeforeClass()andtearDownAfterClass()methods in unit tests are properly calling to their parent counterparts. Applies to Moodle 4.5 and up. - Add new
moodle.Commenting.ConstructorReturnsniff to check that constructors do not document a return value.
Changed
- Update composer dependencies to current versions, notably
PHP_CodeSniffer(3.10.1) andPHPCompatibility(96072c30). - The
moodle.Commenting.MissingDocblocksniff will now detect use of the Override attribute (Fixes #155).
Fixed
- Various fixes to own (GH workflow) integration tests.
Take a look at the CHANGELOG for details about other releases.
Release notes
Open source →Added
- Add new
moodle.PHPUnit.ParentSetUpTearDownsniff to verify, among other things, that all thesetUp(),tearDown(),setUpBeforeClass()andtearDownAfterClass()methods in unit tests are properly calling to their parent counterparts. Applies to Moodle 4.5 and up. - Add new
moodle.Commenting.ConstructorReturnsniff to check that constructors do not document a return value.
Changed
- Update composer dependencies to current versions, notably
PHP_CodeSniffer(3.10.1) andPHPCompatibility(96072c30). - The
moodle.Commenting.MissingDocblocksniff will now detect use of the Override attribute (Fixes #155).
Fixed
- Various fixes to own (GH workflow) integration tests.
- Add new
-
v3.4.603 Apr 2024Release notes
Open source →Fixed
- Solved a problem where Windows file paths were not normalised leading to false positive results on some path-based sniffs.
- Solved a problem with fetching the name of an anonymous class, or closure.
-
v3.4.531 Mar 2024Release notes
Open source →Fixed
- Solved a problem when checking constructor's promoted properties that was leading to some false positives.
-
v3.4.429 Mar 2024Release notes
Open source →Changed
- Improved some internal
moodle.Util.Docblockshelpers and uses.
Fixed
- The
@deprecatedtag is allowed to be alone within PHPDoc blocks.
- Improved some internal
-
v3.4.327 Mar 2024Release notes
Open source →Added
- Add new
moodle.Commenting.DocblockDescriptionsniff to check that all the artifacts (classes, interfaces, traits, ...) and functions PHPDoc blocks have some description.
Changed
- The
moodle.Commenting.MissingDocBlocksniff now also checks that constants are documented.
Fixed
- Solved a problem with file-level PHPDoc blocks not controlling the required blank lines after it.
- Fixed the PHPDoc block detection when multi-line PHP 8 attributes are used in the middle.
- Add new
-
v3.4.221 Mar 2024Release notes
Open source →Added
-
Add new
moodle.Files.LangFilesOrderingsniff to check that lang files are sorted by key. -
Add new
moodle.Commenting.MissingDocBlocksniff to check that all the artifacts (classes, interfaces, traits, ...) and functions are documented. -
Add new
moodle.Commenting.VariableCommentsniff to check that the@vartag and its types are used correctly. -
Add new
moodle.Commenting.ValidTagsniff to check that only allowed tags are used. -
Add new
moodle.Commenting.FileExpectedTagssniff to check that files or classes have the correct PHPDoc block with both@copyrightand@licenseinformation.The expected contents of the
@licensetag can be controlled both by thepreferredLicenseRegexproperty in ruleset files or by themoodleLicenseRegexconfiguration option inphpcs.xmlfiles and CLI invocations. Setting them to empty string disables the Sniff completely. By default, the "https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later" content is checked.
Note that all the
moodle.Commentingsniffs above are part of the migration frommoodle-local_moodlechecktomoodle-cs. You can find more information about the deprecation of the former and links to track the progress in the announcement in General developer forum.Changed
- Various reorganisations of tests, fixtures and utils affecting a number of sniffs.
-
-
v3.4.108 Mar 2024Release notes
Open source →Fixed
- Solved a problem with the
moodle.Commenting.Packagesniff when running against arbitrary (not Moodle based) directories.
- Solved a problem with the
-
v3.4.007 Mar 2024Release notes
Open source →Added
- Add new
moodle.PHPUnit.TestCasesAbstractsniff to check that testcase classes are declared abstract. - Add new
moodle.PHPUnit.TestClassesFinalsniff to check that test classes are declared final. - Add new
moodle.Commenting.Packagesniff to replace those present in moodle-local_moodlecheck. - Add new
moodle.Commenting.Categorysniffs to replace those present in moodle-local_moodlecheck. - New
phpcs.xml.distto enforce the coding style to follow bymoodle-csitself. Basically, PSR12 ruled. CI verified from now on.
Changed
- Modified own CI scripts, updating various GH actions.
- Reallocated own tests structure, to better organise them and fixture files.
- Update composer dependencies to current versions, notably
PHP_CodeSniffer(3.9.0) andPHPCompatibility(e5cd2e24). - As part of the move to be PSR12 compliant, all the methods used for testing have been converted, without deprecation, to camel case (
setStandard(),setSniff(), ...). - ACTION REQUIRED: Any clone/fork using
moodle-csand having own tests will need to adapt them to the new method names.
Fixed
- The moodle.Files.MoodleInternal sniff no longer treats Attributes as side-effects.
- Add new
-
v3.3.1515 Feb 2024Release notes
Open source →Added
- Function declaration lines are verified to have correct whitespace separation (1 space or 0 spaces) between all their parts.
Changed
- Modified own CI scripts, bumping them from NodeJS 16 to NodeJS 20 actions.
Fixed
- PHP
enumuses are not considered side-effects by some sniffs. - PHPDoc blocks are allowed before PHP attributes, that are immediately followed by the PHP structure.
- The PHPUnit
dataProvidersniff now reports the problematic lines properly. - The valid variable names sniff now detects properly escaped (
\$) contents within double quoted strings and they aren't considered - for validation - anymore. - Avoided PHP error when checking empty PHP files.
-
v3.3.1426 Jan 2024Release notes
Open source →Changed
- Modified internal CI scripts towards better Codecov future support.
Fixed
- Solved a problem with some
moodle.PHPUnitSniffs running an endless loop when processing abstract test methods.
-
v3.3.1319 Jan 2024Release notes
Open source →Changed
- Applied various internal, coding and CI improvements:
- Modified own CI tests to behave better.
- Locked
nikic/php-parsertov4to avoid jumping tov5yet (PHP compatibility).
- Updated composer dependencies to current versions, notably
PHP_CodeSniffer(3.8.1).
Added
-
New
moodle.Commenting.TodoCommentSniff will be in charge to control that all the todo comments in core (both// TODOand@todoones) always come with a link to the MDL project in the Tracker.Its behaviour can be controlled both by the
commentRequiredRegexproperty in ruleset files or by themoodleTodoCommentRegexconfiguration option inphpcs.xmlfiles and CLI invocations. Setting them to empty string disables the Sniff completely.
- Applied various internal, coding and CI improvements:
-
v3.3.1219 Dec 2023Release notes
Open source →Changed
- Moved
PHP_CodeSnifferfromsquizlabs(being abandoned) toPHPCSStandars(new repository). Everybody is welcome to contribute or help sponsoring the project! - Update composer dependencies to current versions, notably
PHP_CodeSniffer(3.8.0) andPHPCompatibility(306cd263). - Applied various internal, coding and CI improvements:
- Ruleset fixes.
- PHP 8.3 compliance achieved.
- PHP 8.3 GitHub workflows support.
- Moved
-
v3.3.1129 Nov 2023Release notes
Open source →Changed
- Amended the installation instructions to be able to use some dev dependencies.
- Moved all links to "master" branches to their new "main" counterparts.
Fixed
- Solved a problem with the
CommaAfterLastSniff that was causing some valid multi-line arrays to be identified as invalid, missing commas.
-
v3.3.1020 Oct 2023Release notes
Open source →Added
- Detected various duplicate array keys cases (code smell).
- Enforced, for Moodle 4.4dev and up, that all the test methods have a return type specified (normally
: void).
-
v3.3.926 Sep 2023Release notes
Open source →Added
- Defined (via
.gitattributes) which files must not be part of distribution (generated .zip & .gz in GitHub,--prefer-distin Composer, ...) packages. This includes docs, ci files, tests... Note that it's still possible to download the complete packages (usinggit clone,--prefer-sourcewith Composer, ...).
Fixed
- Removed the
PSR1.Classes.ClassDeclaration.MissingNamespacesniff from themoodle-extrastandard because it was reporting some (for Moodle) false positives.
- Defined (via
-
v3.3.822 Sep 2023Release notes
Open source →Added
- Detect PHPUnit data provider (
@dataProvider) declarations using()after the function name.
Fixed
- Fixed a problem with some non test files (
coverage.php, ...) being managed as such.
- Detect PHPUnit data provider (
-
v3.3.722 Sep 2023Release notes
Open source →Added
- Require trailing commas in multi-line arrays.
- Verify that both
namespaceanduse(class import) declarations don't use leading slashes (\). - Verify various aspects/common mistakes related with PHPUnit data providers:
- Private providers.
- Missing providers.
- Providers with incorrect names.
- Providers with wrong return types.
- Non-static providers.
Fixed
- Fixed incorrect handling of abstract methods within PHPUnit sniffs.
-
v3.3.615 Sep 2023Release notes
Open source →Added
- A new
moodle-extracoding standard which moves towards a more PSR-12 compliant coding style. - Enforce the use of the short array syntax (
[]), warning about the long alternative (array()):Generic.Arrays.DisallowLongArraySyntax. This will be raised fromwarningtoerrorin 1 year.
- A new
-
v3.3.528 Aug 2023Release notes
Open source →Changed
- Update composer dependencies to current versions, notably PHPCompatibility (0a17f9ed).
- Enforce the use of
&&and||logical operators, now erroring (after a grace period of 1 year) withandandoruses:Squiz.Operators.ValidLogicalOperators
-
v3.3.428 May 2023Release notes
Open source →Changed
- Update composer dependencies to current versions, notably PHPCompatibility (70e4ca24).
Added
- Various internal, code coverage related, improvements.
- Add GHA PHP 8.2 support.
- Upload and integrate the repository with Codecov, for better tracking of changes.
- Completely cover the MoodleUtil class, in charge of providing important information about Moodle (versions, branches, components...)
-
v3.3.314 Mar 2023Release notes
Open source →Removed
- Revert the check for the only one-space rule before the assignment operator @
Squiz.WhiteSpace.OperatorSpacingas an interim solution while we revisit MDLSITE-6594.
- Revert the check for the only one-space rule before the assignment operator @
-
v3.3.213 Feb 2023Release notes
Open source →Added
- Check for one (and only one) space before assignment operator @
Squiz.WhiteSpace.OperatorSpacing
- Check for one (and only one) space before assignment operator @
-
v3.3.119 Jan 2023 -
v3.3.013 Jan 2023Release notes
Open source →Added
- Enforce the use of
&&and||logical operators, warning aboutandandor:Squiz.Operators.ValidLogicalOperators
Changed
- Many internal changes towards better self-testing and integration with other tools (GH workflows, codechecker, core, phpunit...).
- Upgraded the PHPCompatibility standard from 3 years old version 9.3.5 (no releases since then) to current development version.
Fixed
- Stop considering
class_aliaslike a side effect. - Add back the
Squiz.Arrays.ArrayBracketSpacingsniff.
- Enforce the use of
-
v3.2.518 Oct 2022Nothing published for this version
-
v3.2.424 Jul 2022Nothing published for this version
-
v3.2.317 Apr 2022Nothing published for this version
-
v3.2.217 Apr 2022Nothing published for this version
-
v3.2.128 Feb 2022Nothing published for this version
-
v3.2.028 Feb 2022Release notes
Open source →This release is the first release of the new moodlehq/moodle-cs packages.
These rules, in an identical form, were previously available as a part of the local_codechecker Moodle plugin but are being moved to their own repository to make installation friendlier for developers.
All features are maintained and no new features have been introduced to either the rules, or the sniffs.
All the details about previous releases can be found in local_codechecker own change log.
-
v3.2.0-beta28 Feb 2022 pre-releaseNothing published for this version