moodle-standards
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMoodle Standards Skill
Moodle编码标准技能
Apply Moodle coding standards (PSR-12 + exceptions) to PHP code.
将Moodle编码标准(PSR-12+例外规则)应用于PHP代码。
Trigger
触发场景
- PHP files in Moodle plugin directories
- User requests code review or formatting
- New file creation in Moodle context
- Moodle插件目录中的PHP文件
- 用户请求代码审查或格式化
- 在Moodle环境中创建新文件
Actions
执行操作
1. Validate Code Style
1. 验证代码风格
Check code against Moodle standards:
- Line length (132 ideal, 180 max)
- Array syntax (only)
[] - not
else ifelseif - No closing tag
?> - 4-space indentation
对照Moodle标准检查代码:
- 行长度(理想值132,最大值180)
- 数组语法(仅允许)
[] - 使用而非
else ifelseif - 不添加闭合标签
?> - 4空格缩进
2. Fix Naming
2. 修正命名规范
Ensure proper naming:
- Variables: (no underscores between words)
$lowercase - Functions: (Frankenstyle)
component_function_name() - Classes:
lowercase_with_underscores - Constants:
COMPONENT_CONSTANT_NAME
确保命名合规:
- 变量:(单词间无下划线)
$lowercase - 函数:(Frankenstyle命名法)
component_function_name() - 类:(小写加下划线)
lowercase_with_underscores - 常量:(全大写加下划线)
COMPONENT_CONSTANT_NAME
3. Add PHPDoc
3. 添加PHPDoc注释
Generate required documentation:
- File header with GPL
- tag (MANDATORY)
@package - with types
@param - description
@return
生成必要的文档注释:
- 包含GPL协议的文件头
- 标签(必填)
@package - 带类型的注释
@param - 描述信息
@return
4. Type Hints
4. 添加类型提示
Add mandatory type declarations:
- Parameter types
- Return types
- Nullable types ()
?type
添加必填的类型声明:
- 参数类型
- 返回值类型
- 可空类型()
?type
Validation Command
验证命令
bash
vendor/bin/phpcs --standard=moodle path/to/file.phpbash
vendor/bin/phpcs --standard=moodle path/to/file.phpQuick Fixes
快速修复方案
Missing Package Tag
缺失@package标签
php
/**
* @package mod_myplugin
*/php
/**
* @package mod_myplugin
*/Wrong Array Syntax
错误的数组语法
php
// Before
$arr = array('a', 'b');
// After
$arr = ['a', 'b'];php
// 修复前
$arr = array('a', 'b');
// 修复后
$arr = ['a', 'b'];Wrong Else If
错误的else if写法
php
// Before
} elseif ($x) {
// After
} else if ($x) {php
// 修复前
} elseif ($x) {
// 修复后
} else if ($x) {