Token导航 LogoToken导航TokenDH.com
开发规范需要联网github未标认证来源可访问许可证需确认审计通过

craft-php-guidelinescraft PHP guidelines 命令行

Agent Skill

craft-php-guidelines 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

294

周安装

12

GitHub Stars

38

下载量

94
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:craft-php-guidelines(craft PHP guidelines 命令行)
来源仓库:https://github.com/michtio/craftcms-claude-skills
仓库路径:skills/craft-php-guidelines
安装命令:
npx skills add https://github.com/michtio/craftcms-claude-skills --skill craft-php-guidelines
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/michtio/craftcms-claude-skills --skill craft-php-guidelines

简介

craft-php-guidelines 提供 Craft CMS 5 PHP 插件开发的编码标准与约定。

  • 强制要求 PHPDoc 注释所有类、方法与属性,遵循 Craft 核心代码规范。
  • 涵盖命名、类型提示、异常处理与事件监听等企业级开发实践。
  • 需配合 ddev 等开发工具链使用,确保本地环境与生产行为一致。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Craft CMS 5 PHP Guidelines

Complete PHP coding standards and conventions for Craft CMS 5 plugin and module development. These extend Craft's official coding guidelines with project-specific conventions.

Core principles: PHPDocs on everything — classes, methods, and properties — regardless of type hints. No declare(strict_types=1) in plugin source files (matching Craft core convention).

Companion Skills — Always Load Together

  • craftcms — Architecture patterns, element lifecycle, controllers, events, migrations. Required for any Craft plugin or module development.
  • ddev — All commands run through DDEV. Required for running ECS, PHPStan, scaffolding, and tests.

Documentation

When unsure about a convention, WebFetch the coding guidelines page for the authoritative answer.

Common Pitfalls

  • addSelect() is the convention in beforePrepare() — safely additive when multiple extensions contribute columns.
  • $_instances is not a Craft convention — private properties use underscore prefix but meaningful names like $_items, $_sections.
  • Records use the same class name as models (namespace distinguishes). Alias when importing both: use...\records\MyEntity as MyEntityRecord;.
  • Queue jobs have no "Job" suffixResaveElements, not ResaveElementsJob.
  • declare(strict_types=1) is NOT used in plugin source files. Only in standalone config files like ecs.php.
  • @author goes on classes and methods only — never on properties.
  • Don't use string|null — use ?string (short nullable notation).
  • Forget parent::defineRules() and you lose all inherited validation.
  • DateTimeHelper in elements/queries, Carbon in services — never mix in the same class.
  • Missing @throws chains — document exceptions from called methods too, not just your own throws.
  • Using magic property access ($plugin->settings, $app->view) instead of explicit getters ($plugin->getSettings(), $app->getView()) — PHPStan can't resolve __get() calls, so magic access passes at runtime but fails static analysis. Always use explicit getters for Yii2 components and Craft plugin properties.

Reference Files

Read the relevant reference file(s) for your task:

TaskRead
Writing PHPDocs, @author, @since, @throws, @var, @param, type referencesreferences/phpdoc-standards.md
Class structure, section headers, ordering, enums, control flow, comments, whitespacereferences/class-organization.md
Naming classes, methods, properties, files, services, events, migrationsreferences/naming-conventions.md
CP Twig templates, form macros, translations, file headers, validationreferences/templates-and-patterns.md
ECS, PHPStan, scaffolding commands, commit messagesreferences/tooling.md

Critical Rules

  1. PHPDocs on everything: classes, methods, properties. No exceptions.
  2. @throws chains: document every exception including uncaught from called methods.
  3. @author and @since at the bottom of class/method docblocks, after a blank line.
  4. Section headers with // ========================================================================= on every class.
  5. declare(strict_types=1) is NOT used in plugin source files — Craft's internal type coercion depends on PHP's default weak typing mode.
  6. Private methods/properties prefixed with underscore: _registerCpUrlRules(), $_items.
  7. addSelect() convention in beforePrepare() — additive across extensions, prevents column conflicts.
  8. DateTimeHelper in elements/queries, Carbon in services — separate concerns prevent mixing date APIs in the same class.
  9. Always scaffold with ddev craft make <type> --with-docblocks, then customize.
  10. ddev composer check-cs and ddev composer phpstan must pass before every commit.

PHP Standards

  • Minimum PHP 8.2 (Craft CMS 5 requirement).
  • PSR-12 baseline with Craft modifications (trailing commas, constant visibility).
  • craftcms/ecs with SetList::CRAFT_CMS_4 preset (covers both Craft 4 and 5).
  • Short nullable notation: ?string not string|null.
  • Always specify void return types.
  • Typed properties everywhere. No untyped public properties.
  • Strict comparison always: $foo === null, in_array($x, $y, true).
  • Casts over functions: (int)$foo not intval($foo).

Section Header Order

// Traits
// Const Properties
// Static Properties
// Public Properties
// Protected Properties
// Private Properties
// Public Methods
// Protected Methods
// Private Methods

Only include sections that have content. Blank line after the separator, before the first item.

Control Flow

  • Happy path last. Handle error conditions first with early returns.
  • Avoid else — use early returns instead.
  • match over switch — always.
  • Always use curly brackets even for single statements.
  • Separate compound conditions into nested if statements for readability.
  • Named arguments when calling methods with 3+ parameters.

Date Handling

  • Elements and element queries: craft\helpers\DateTimeHelper.
  • Services (date arithmetic): Carbon\Carbon.
  • Never mix both in the same class.

Database Conventions

  • [[column]] quoting in Yii2 join conditions.
  • addSelect() in beforePrepare() — safely additive.
  • postDate and expiryDate in addSelect() and indexed on element tables.
  • Db::parseParam() for query parameters. Db::parseDateParam() for dates.
  • Foreign keys with explicit CASCADE / SET NULL behavior.

Naming Quick-Reference

ThingConventionExample
Services (resource)PluralEntries, Volumes, Users
Services (utility)Domain nounAuth, Search, Gc
Queue jobsAction verb, no suffixResaveElements, UpdateSearchIndex
RecordsSame name as modelNamespace distinguishes
EventsThree patternsSectionEvent, RegisterUrlRulesEvent, DefineHtmlEvent
Element actionsAction verb, no suffixDelete, Duplicate, SetStatus
EnumsPascalCase cases, string/int backedPropagationMethod, CmsEdition

For the complete naming reference including file structure conventions, read references/naming-conventions.md.

Verification Checklist

Before every commit:

  1. ddev composer check-cs passes
  2. ddev composer phpstan passes
  3. Tests green
  4. PHPDocs complete on all new/modified code
  5. @throws chains verified
  6. Section headers present and correct
  7. Imports alphabetical and grouped

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.76%
按下载量换算34

Claude

30.44%
按下载量换算29

Cursor

20.56%
按下载量换算19

Gemini CLI

9.25%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills