Code-checker

Local plugins ::: local_codechecker
Maintained by One poor developer...Eloy Lafuente (stronk7), TimTim Hunt, Víctor Déniz Falcón, Sara Arjona Téllez
Part of set Moodle development.
A tool for developers that helps them follow Moodle's coding style.

Code-checker 3.0.2 - Summer break

Moodle 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11
Released: Friday, 16 July 2021, 6:53 AM

Moodle Code Checker

Build Status

Changes in version 3.0.2 (20210716) - Summer break

  • Various internal changes and improvements:
    • Removed some legacy code (33_STABLE) and out of support 7.1 tests.
    • Disable coverage reporting in Travis own builds.
    • Added PHP 8.0 support in own tests.
    • Fulfill Moodle 4.0 requirements.
    • Make mariadb own tests sticky to 10.5 until MDL-72131 is fixed.
  • PR#146: Suggest debugging() as alternative to error_log() (Ruslan Kabalin).
  • PR#148: Verify that there is one and only one EOL @ EOF (stronk7).

Information

This Moodle plugin uses the PHP CodeSniffer tool to check that code follows the Moodle coding style. It implements and reuses a set of 'sniffs' that check many aspects of the code, including the awesome PHPCompatibility ones.

It was created by developers at the Open University, including Sam Marshall, Tim Hunt and Jenny Gray. It is now maintained by Moodle HQ.

Available releases can be downloaded and installed from https://moodle.org/plugins/view.php?plugin=local_codechecker.

To install it using git, type this command in the root of your Moodle install:

git clone git://github.com/moodlehq/moodle-local_codechecker.git local/codechecker

Then add /local/codechecker to your git ignore.

Additionally, remember to only use the version of PHPCS located in phpcs/bin/phpcs rather than installing PHPCS directly. Add the location of the PHPCS executable to your system path, tell PHPCS about the Moodle coding standard with phpcs --config-set installed_paths /path/to/moodle-local_codechecker and set the default coding standard to Moodle with phpcs --config-set default_standard moodle. You can now test a file (or folder) with: phpcs /path/to/file.php.

Alternatively, download the zip from https://github.com/moodlehq/moodle-local_codechecker/zipball/master, unzip it into the local folder, and then rename the new folder to "codechecker".

After you have installed this local plugin, you should see a new option in the settings block:

Site administration -> Development -> Code checker

We hope you find this tool useful. Please feel free to enhance it. Report any idea or bug in the Tracker, thanks!

IDE Integration

Eclipse:

  1. Outdated!: If if you use Eclipse for development, you might want to install the PHP CodeSniffer plugin (http://www.phpsrc.org/).
  2. Create a new "CodeSniffer standard" in the preferences page.
  3. Point it at the moodle directory inside the codechecker folder.
  4. Thank Michael Aherne from University of Strathclyde who worked this out!

PhpStorm

  1. Install the phpcs cli tool
  2. Open PhpStorm preferences
  3. Go to PHP > CodeSniffer and supply the path to the phpcs executable
  4. Go to Inspections > PHP > PHP Code Sniffer Validation
  5. In the 'coding standard' dropdown select 'custom' and press the [...] button next to the path to the coding standard. Point is at the moodle directory inside the this plugin directory.

Sublime Text

Find documentation here.

  1. Install PHP CS following steps described in this moodle docs page.
  2. Go in your Sublime Text to Preferences -> Package Control -> Package Control: Install Package
  3. Write 'phpcs' in the search field, if you see Phpcs and SublimeLinter-phpcs, click on them to install them.
  4. If not, check if they are already installed Preferences -> Package Control -> Package Control: Remove Package.
  5. To set your codecheck to moodle standards go to Preferences -> Package Settings -> PHP Code Sniffer -> Settings-User and write:

    { "phpcs_additional_args": {
            "--standard": "moodle",
            "-n": "
        },
    }
    
  6. If you don’t have the auto-save plugin turned on, YOU’RE DONE!

  7. 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:

    "phpcs_show_quick_panel": false,
    

    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.

VSCode

Find documentation here.

  1. Install PHP CS following steps described in this moodle docs page.
  2. Install PHPSniffer.
  3. 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):

    "phpSniffer.standard": "moodle",
    

Version information

Version build number
2021071600
Version release name
3.0.2 - Summer break
Can be updated to
4.0.2 - Comp-at-ibility (2023012000), 4.0.3 - Valentine's D (2023021400), 5.0.3 - Bumping bumps (2023121900), 5.0.4 - Depend-a-bot (2024012600), 5.0.5 - Fools plus 9 (2024041000), 5.0.6 - Bye, May! (2024053100), 5.0.7 - It's a small world (2024061400), 5.0.8 - Refreshing summer (2024070500)
Maturity
Stable version
MD5 Sum
eadc6a8ab9ea4b4c20af5cc8c56f6061
Supported software
Moodle 3.4, Moodle 3.5, Moodle 3.6, Moodle 3.7, Moodle 3.8, Moodle 3.9, Moodle 3.10, Moodle 3.11

Version control information

Version control system (VCS)
GIT
VCS repository URL
VCS branch
master
VCS tag
v3.0.2

Default installation instructions for plugins of the type Local plugins

  1. Make sure you have all the required versions.
  2. Download and unpack the module.
  3. Place the folder in the "local" subdirectory.
  4. Visit http://yoursite.com/admin to finish the installation.