/craftcms-claude-skills:craft-php-guidelinesfrom craftcms-claude-skills
Enforces Craft CMS 5 PHP coding standards and conventions for plugins and modules. Covers PHPDoc blocks, class organization, naming, ECS/PHPStan config, and Craft-specific patterns like MemoizableArray and DateTimeHelper.
Ships in craftcms-claude-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
!sh ${CLAUDE_SKILL_DIR}/scripts/craft-version.sh
If no Craft version line appears above, establish the version before any version-specific advice: craftcms/cms in composer.lock for a site, the lowest version the craftcms/cms constraint in composer.json allows for a plugin, or ask. Then check it against the version tags in this skill ([5.10+], [changed 5.12], [seomatic 5.1+]).
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).
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.When unsure about a convention, WebFetch the coding guidelines page for the authoritative answer.
Read the relevant reference file(s) for your task:
| Task | Read | ~Tokens |
|---|---|---|
Writing PHPDocs, @author, @since, @throws, @var, @param, type references; console controller docblocks as craft help text | references/phpdoc-standards.md | ~1,150 |
| Class structure, section headers, ordering, shared constants, enums, control flow, comments, whitespace | references/class-organization.md | ~2,050 |
| Naming classes, methods, properties, files, services, events, migrations; quick-reference table; kebab-case permission handles and their constants | references/naming-conventions.md | ~1,500 |
| CP Twig templates, form macros, translations, copy style (no em-dashes), file headers, validation | references/templates-and-patterns.md | ~1,350 |
DateTimeHelper vs Carbon, parsing DB datetimes, App::env()/App::parseEnv(), UrlHelper::absoluteUrl() [5.12.2+], doesEnvVarExist() [5.11+], DB conventions, Db::isSafeOrderBy() [5.12+], component registration scope | references/dates-env-database.md | ~1,250 |
ECS, PHPStan (Craft::$app narrowing, magic property access), scaffolding commands, composer hygiene for plugin repos, commit messages | references/tooling.md | ~2,100 |
| Authorization parity across CP / console / GraphQL / queue surfaces, self-referential guards, one shared gate | references/authorization-parity.md | ~2,900 |
@throws chains: document every exception including uncaught from called methods.@author and @since at the bottom of class/method docblocks, after a blank line. @author goes on classes and methods, never on properties. (Craft core puts @author at the class level only; method-level @author is this project's house convention. Don't "fix" it.)// ========================================================================= on every class. (Craft core itself uses dash separators — // ---- — with functional/domain labels like // Statuses or // Events. The ===== separators and visibility labels below are a deliberate house convention for consistency across this project's plugins, not core style.)declare(strict_types=1) is NOT used in plugin source files — Craft's internal type coercion depends on PHP's default weak typing mode. Only standalone config files like ecs.php use it._registerCpUrlRules(), $_items, $_sections (never $_instances).addSelect() convention in beforePrepare() — additive across extensions, prevents column conflicts.DateTimeHelper in elements/queries, Carbon in services — never mix them in the same class.ddev craft make <type> --with-docblocks, then customize.ddev composer check-cs and ddev composer phpstan must pass before every commit.// 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. Full example: references/class-organization.md.
craftcms/ecs with SetList::CRAFT_CMS_4 preset (covers both Craft 4 and 5).?string not string|null.void return types.$foo === null, in_array($x, $y, true).(int)$foo not intval($foo).else, match over switch for value-mapping, curly brackets always, compound conditions split into nested ifs, named arguments at 3+ parameters. See references/class-organization.md.use ...\records\MyEntity as MyEntityRecord;.ResaveElements, not ResaveElementsJob. Element actions likewise (Delete, SetStatus).parent::defineRules() and you lose all inherited validation.[$this, '_validateFoo'] callable arrays or inline closures in defineRules() — Craft core uses string method names: [['attr'], 'validateAttr']. The validator method is public, no underscore — Yii invokes it by name.strtotime() or new DateTime(): the column is naive UTC and the process timezone is system.timeZone. Use DateTimeHelper::toDateTime($value) or Carbon with 'UTC'. See references/dates-env-database.md.$plugin->settings, $app->view) fails PHPStan; use explicit getters (getSettings(), getView()). See references/tooling.md.Craft::$app — narrow with a typed local: /** @var \craft\web\Application $app */ $app = Craft::$app;. Don't use @phpstan-ignore-line.private const drift silently: one public const on the owner, e.g. SettingsController::PERMISSION_MANAGE_SETTINGS. See references/naming-conventions.md.handle:manage-settings); never camelCase, though Craft core's own are camelCase. The PHP constant stays SCREAMING_SNAKE_CASE. See references/naming-conventions.md.App::env('VAR'), never getenv(), in plugin code and in every config example (with use craft\helpers\App;). App::parseEnv() for settings that may hold a $VAR or alias. See references/dates-env-database.md.references/authorization-parity.md.../* path repositories in a plugin's composer.json resolve only on the author's disk. See references/tooling.md (Composer Hygiene).Db::parseParam() for a literal comparison turns a leading/trailing * into a LIKE wildcard. Use andWhere(['col' => $value]).EVENT_REGISTER_ELEMENT_TYPES / EVENT_REGISTER_FIELD_TYPES inside a getIsCpRequest() branch hides the type from console/queue requests (and Gc stops purging it). Register unconditionally. See references/dates-env-database.md.craft help: the summary is physical docblock line 2, so no ========= rule there, no {@see}/{@link}/{@inheritdoc}, no scaffolded * Class FooController. See references/phpdoc-standards.md.Craft::t() strings, labels, CP notices, console output, README, docs). Code comments and PHPDoc are exempt. See references/templates-and-patterns.md.Before every commit:
ddev composer check-cs passesddev composer phpstan passes@throws chains verifiedCraft::t() strings, labels, CP notices, README, docs)House rules: no AI or tool attribution and no co-author trailers in commits, PRs, comments, code or docs; no em dashes in prose; US spelling; no model or vendor names in pack files.
references/authorization-parity.md (opens in a new tab)references/class-organization.md (opens in a new tab)references/dates-env-database.md (opens in a new tab)references/naming-conventions.md (opens in a new tab)references/phpdoc-standards.md (opens in a new tab)references/templates-and-patterns.md (opens in a new tab)references/tooling.md (opens in a new tab)scripts/craft-version.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Triggers on: writing services, models, controllers, elements, queries, records, queue jobs, migrations, or any Craft PHP class; PHP review, refactoring, or style questions; requireAdmin vs requirePermission, manage-settings, settings permission, kebab-case permission handles, allowAdminChanges, read-only settings, getCpNavItem dead nav item, permission handle constant on owning controller, App::env() never getenv(), App::parseEnv() for $VAR settings, no-em-dash user-facing copy. NOT for front-end Twig (craft-twig-guidelines), template architecture (craft-site), or CP JavaScript (craft-garnish). If you are touching PHP in a Craft context, you need this skill.
Three short reads, in order
npx claudepluginhub michtio/craftcms-claude-skills --plugin craftcms-claude-skills16 skills in this plugin
/craft-cloudCraft Cloud, Pixel & Tonic's serverless hosting platform for Craft CMS. Covers craft-cloud.yaml, the Build → Migrate → Release deploy pipeline, the craftcms/cloud extension, edge transforms and static caching (cache.rules, ESI), the Cloud S3 filesystem, MySQL 8 / Postgres 15 (no MariaDB, no tablePrefix), the Console command runner and scheduled cron, queue jobs, custom domains, preview environments per branch, limits (ephemeral filesystem, no SSH, no .htaccess, no built-in mail), Cloud-compatible plugins, and self-hosted → Cloud migration./craftcmsCraft CMS 5 plugin and module development in PHP. Covers elements, element queries, services, models, records, controllers, migrations, queue jobs, console commands, field types, events, Twig extensions, widgets, permissions, GraphQL, testing, and debugging./craft-content-modelingCraft CMS 5 content modeling: sections, entry types, fields, Matrix, relations, project config, and content architecture strategy. Covers choosing section types, designing entry types and field layouts, selecting field types, Matrix and nested entries, relations and eager loading, and multi-site propagation./craft-fortrabbitfortrabbit (fortrabbit.com): managed PHP hosting with a Craft CMS software template. Covers git push-to-deploy through the fortrabbit GitHub App, the template's build and post-deploy commands, the merge deployment strategy with the /config/project replace pattern, the deploy file (.fortrabbit/deploy.yml) and its replace-by-default trap, CRAFT_* ENV vars mapped from FORTRABBIT_DB_*, production settings (admin changes and updates off), persistent storage for asset volumes and rsync sync, MySQL over an SSH tunnel, the queue and image transforms in a worker job, crons, platform limits (no root, no sendmail), and DDEV local development./craft-garnishGarnish, Craft CMS's built-in JavaScript UI toolkit for the control panel. ALWAYS load when writing, editing, or reviewing JavaScript that runs in the Craft CP: plugin CP assets, custom field type JS, element index JS, CP webpack config, or code importing garnishjs / referencing window.Garnish. Also for CP accessibility, keyboard interactions, drag-sort, and CP JS memory issues./craft-gated-buildBuilds one approved slice with the outside builders listed in .ai/skills-profile.json (local AI, a script) and keeps the pack's gates: craft-gate-writer locks the gate ahead of any builder, each builder gets a brief and returns a handback, the handback is verified, the lock and craft-review-checker cover the result, at most three rounds, and craft-feature-builder takes over when every outside builder fails, is unavailable or passes its timeout setting.Other plugins' skills for the same job