diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7669e46..5e9e644 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ The format of this change log follows the advice given at [Keep a CHANGELOG](htt
## [Unreleased]
+### Added
+
+- A new moodle-extra coding standard which moves towards a more PSR-12 compliant coding style
+
## [v3.3.5] - 2023-08-28
### Changed
- Update composer dependencies to current versions, notably PHPCompatibility (0a17f9ed).
diff --git a/README.md b/README.md
index 0b17747..2ed5b36 100644
--- a/README.md
+++ b/README.md
@@ -16,81 +16,73 @@
## Information
-This repository contains the Moodle Coding Style configuration.
+This repository contains the Moodle Coding Style configuration, written to support [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
+
+Two coding styles are included:
+
+- The standard `moodle` style, with support for a wider range of accepted Moodle standards; and
+- The more opinionated `moodle-extra` style, which extends the standard style and applies additional rules.
Currently this only includes the configuration for PHP Coding style, but this
may be extended to include custom rules for JavaScript, and any other supported
languages or syntaxes.
-
## Installation
-### Using Composer
+### Using Composer (recommended)
-You can include these coding style rules using Composer to make them available
-globally across your system.
+You can install these coding style rules using Composer to make them available globally across your system.
-This will install the correct version of phpcs, with the Moodle rules, and their
-dependencies.
+This will install the correct version of phpcs, with the Moodle rules, and their dependencies.
-```
+```shell
composer global require moodlehq/moodle-cs
```
-### As a part of moodle-local_codechecker
-
-This plugin is included as part of the [moodle-local_codechecker
-plugin](https://github.com/moodlehq/moodle-local_codechecker).
-
-
## Configuration
-You can set the Moodle standard as the system default:
-```
-phpcs --config-set default_standard moodle
-```
-
-This will inform most IDEs automatically.
-Alternatively you can configuration your IDE to use phpcs with the Moodle
-ruleset as required.
-
-
-### IDE Integration
+Typically configuration is not required. Recent versions of Moodle (3.11 onwards) include a configuration file for the PHP CodeSniffer, which will set the standard when run within a Moodle directory.
-#### PhpStorm
+Additional configuration can be generated automatically to have PHP CodeSniffer ignore any third-party library code. This can be generated by running:
-1. Open PhpStorm preferences
-2. Go to Inspections > PHP > PHP Code Sniffer Validation
-3. In the 'coding standard' dropdown, select 'moodle'
+```shell
+npx grunt ignorefiles
+```
-#### Sublime Text
+### Using the `moodle-extra` coding style
-Find documentation [here](https://docs.moodle.org/dev/Setting_up_Sublime2#Sublime_PHP_CS).
+The recommended way of configuring PHP CodeSniffer to use the `moodle-extra` coding style is to provide an additional configuration file.
-1. Go in your Sublime Text to Preferences -> Package Control -> Package Control: Install Package
-2. Write 'phpcs' in the search field, if you see Phpcs and SublimeLinter-phpcs, click on them to install them.
-3. If not, check if they are already installed Preferences -> Package Control -> Package Control: Remove Package.
-4. To set your codecheck to moodle standards go to Preferences -> Package Settings -> PHP Code Sniffer -> Settings-User and write:
+For Moodle 3.11 onwards you can create a file named `.phpcs.xml` with the following contents:
- { "phpcs_additional_args": {
- "--standard": "moodle",
- "-n": "
- },
- }
+```xml
+
+
+
+
+
+```
-5. If you don’t have the auto-save plugin turned on, YOU’RE DONE!
-6. If you have the auto-save plugin turned on, because the codecheck gets triggered on save, the quick panel will keep popping making it impossible to type.
- To stop quick panel from showing go to Settings-User file and add:
+This will load the `phpcs.xml` file (generated by `npx grunt ignorefiles`), and apply the `moodle-extra` configuration on top.
- "phpcs_show_quick_panel": false,
+### Moodle 3.10 and earlier
- The line with the error will still get marked and if you’ll click on it you’ll see the error text in the status bar.
+The easiset way to have PHP CodeSniffer pick up your preferred style, you can create a file named `phpcs.xml` with the following contents:
-#### VSCode
+```xml
+
+
+
+
+```
-Find documentation [here](https://docs.moodle.org/dev/Setting_up_VSCode#PHP_CS).
+If you wish to use the `moodle-extra` coding style, then you can use the following content:
-1. Install [PHPSniffer](https://marketplace.visualstudio.com/items?itemName=wongjn.php-sniffer).
-2. Open VSCode settings.json and add the following setting to define standard PHP CS (if you haven't set it as default in your system):
+```xml
+
+
+
+
+```
- "phpSniffer.standard": "moodle",
+Note: Third-party library code will not be ignored with these versions of Moodle.
diff --git a/composer.json b/composer.json
index cfbd24a..3ec2e09 100644
--- a/composer.json
+++ b/composer.json
@@ -12,11 +12,16 @@
{
"name": "Andrew Lyons",
"email": "andrew@nicols.co.uk"
+ },
+ {
+ "name": "Eloy Lafuente",
+ "email": "stronk7@moodle.com"
}
],
"require": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"squizlabs/php_codesniffer": "^3.7.2",
+ "phpcsstandards/phpcsextra": "^1.1.0",
"phpcompatibility/php-compatibility": "dev-develop#0a17f9ed"
},
"config": {
diff --git a/moodle-extra/ruleset.xml b/moodle-extra/ruleset.xml
new file mode 100644
index 0000000..90efcfe
--- /dev/null
+++ b/moodle-extra/ruleset.xml
@@ -0,0 +1,82 @@
+
+
+
+ Best Practices for Moodle development beyond the core Coding Standards
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+