Moodle has some very specific styling that should be followed, check out the coding style guide at:
The linter recommended for moodle development is PHP Sniffer. PHP Sniffer is a tool used to analyse PHP code using a set of rules. In many cases these rules can be used to automatically fix the errors they identify.
-
Start by installing composer, the steps are provided in the link below:
-
Install composer dependencies:
composer global require "squizlabs/php_codesniffer=*" composer global require moodlehq/moodle-cs
-
Add composer's path to your bashrc:
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
-
Install PHP Sniffer in VS Code:
-
Press Ctrl+P on Linux/Windows or Cmd+P on Mac to open the Quick Open dialog.
-
Type
ext install wongjn.php-sniffer
to find the extension. -
Press Enter or click the cloud icon to install it.
-
Restart Visual Studio Code when prompted.
-
-
Test that PHP Sniffer is working:
-
Open any php file.
-
Add a variable in camel case.
-
Save changes and check that an error pops up for the incorrect case used.
-
To upgrade your plugin, certain files must be updated for moodle to detect that there is a new version of your plugin, please see the following links below: