moodle-standards

astoeffer's avatarfrom astoeffer

Apply Moodle coding standards (PSR-12 with exceptions) to PHP code. Validates style, naming conventions, PHPDoc, and type hints.

⭐0stars🔀1forks📁View on GitHub🕐Updated Dec 19, 2025

When & Why to Use This Skill

This Claude skill automates the enforcement of Moodle-specific coding standards (a specialized PSR-12 variant) for PHP development. It streamlines the development workflow by automatically validating and correcting code style, naming conventions, mandatory PHPDoc documentation, and PHP type hints, ensuring high-quality, compliant code for Moodle plugins and core contributions.

Use Cases

  • Automated Style Compliance: Quickly reformat PHP files to meet Moodle's strict requirements, such as 4-space indentation, specific 'else if' syntax, and modern array brackets.
  • Frankenstyle Naming Validation: Ensure all functions, classes, and variables follow Moodle's unique naming conventions to prevent component conflicts and maintain consistency.
  • Documentation & Boilerplate Generation: Automatically generate mandatory PHPDoc headers, including GPL licenses and required @package tags for Moodle plugin directories.
  • Type Hinting & Modernization: Identify and add missing parameter and return type declarations to legacy PHP code to improve code reliability and IDE support.
  • Pre-submission Quality Check: Use the skill as a virtual reviewer to catch style violations before running official CI/CD tools like phpcs, speeding up the approval process.
namemoodle-standards
descriptionApply Moodle coding standards (PSR-12 with exceptions) to PHP code. Validates style, naming conventions, PHPDoc, and type hints.

Moodle Standards Skill

Apply Moodle coding standards (PSR-12 + exceptions) to PHP code.

Trigger

  • PHP files in Moodle plugin directories
  • User requests code review or formatting
  • New file creation in Moodle context

Actions

1. Validate Code Style

Check code against Moodle standards:

  • Line length (132 ideal, 180 max)
  • Array syntax ([] only)
  • else if not elseif
  • No closing ?> tag
  • 4-space indentation

2. Fix Naming

Ensure proper naming:

  • Variables: $lowercase (no underscores between words)
  • Functions: component_function_name() (Frankenstyle)
  • Classes: lowercase_with_underscores
  • Constants: COMPONENT_CONSTANT_NAME

3. Add PHPDoc

Generate required documentation:

  • File header with GPL
  • @package tag (MANDATORY)
  • @param with types
  • @return description

4. Type Hints

Add mandatory type declarations:

  • Parameter types
  • Return types
  • Nullable types (?type)

Validation Command

vendor/bin/phpcs --standard=moodle path/to/file.php

Quick Fixes

Missing Package Tag

/**
 * @package    mod_myplugin
 */

Wrong Array Syntax

// Before
$arr = array('a', 'b');
// After
$arr = ['a', 'b'];

Wrong Else If

// Before
} elseif ($x) {
// After
} else if ($x) {