craft-php-guidelines

Solid

Craft CMS 5 PHP coding standards and conventions. Triggers: writing PHP classes, PHPDoc blocks, @author, @since, @throws, section headers (=========), defineRules(), beforePrepare(), addSelect(), MemoizableArray, DateTimeHelper, Carbon, ECS check-cs, PHPStan, ddev craft make, Twig templates, form macros, translations Craft::t(), enum definitions, commit messages. Always load when writing, editing, or reviewing any PHP or Twig code in a Craft CMS plugin or module.

Code & Development 45 stars 3 forks Updated 4 days ago MIT

Install

View on GitHub

Quality Score: 83/100

Stars 20%
55
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Craft CMS 5 PHP Guidelines Complete PHP coding standards and conventions for active coding sessions. ## Common Pitfalls - `addSelect()` is the convention in `beforePrepare()` — safely additive when multiple extensions contribute columns. Craft's `**` placeholder merges defaults regardless, but `addSelect()` prevents conflicts. - `$_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" suffix** — `ResaveElements`, 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. ## Documentation - Official coding guidelines: https://craftcms.com/docs/5.x/extend/coding-guidelines.html - Class reference: https://docs.craftcms.com/api/v5/ - Generator reference: https://craftcms.com/docs/5.x/extend/generator.html When unsure about a convention, `web_fetch` the...

Details

Author
michtio
Repository
michtio/craftcms-claude-skills
Created
1 months ago
Last Updated
4 days ago
Language
Shell
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category

Code & Development Solid

coding-standards

Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.

116 Updated 6 days ago
cloudnative-co
AI & Automation Solid

craft-content-modeling

Craft CMS 5 content modeling — sections, entry types, fields, Matrix, relations, project config, and content architecture strategy. Covers everything editors and developers need to structure content in Craft. Triggers on: section types (single, channel, structure), entry types, field types, field layout, Matrix configuration, nested entries, relatedTo, eager loading, .with(), .eagerly(), categories, tags, globals, global sets, preloadSingles, propagation, multi-site content, URI format, project config, YAML, content architecture, content strategy, taxonomy, asset volumes, filesystems, image transforms, user groups, permissions, entries-as-taxonomy, entrify. Always use when planning content architecture, creating sections/fields, configuring Matrix, setting up relations, or making content modeling decisions.

45 Updated 4 days ago
michtio
Code & Development Listed

coding-standards

Universal coding standards, best practices, and patterns for TypeScript, JavaScript, React, and Node.js development.

10 Updated 1 months ago
GiorgioBertolotti
Code & Development Solid

juniors-best-practice

Juniors-focused React and TypeScript best practices. Use this skill when writing or reviewing code to enforce clear, consistent, and maintainable patterns across common scopes like React, TypeScript, styling, devtools, assets, and Git.

14 Updated 1 months ago
siberiacancode
Web & Frontend Featured

common-api-design

Apply REST API conventions — HTTP semantics, status codes, versioning, pagination, and OpenAPI standards for any framework. Use when designing endpoints, choosing HTTP methods, implementing pagination, or writing OpenAPI specs. (triggers: **/*.controller.ts, **/*.router.ts, **/*.routes.ts, **/routes/**, **/controllers/**, **/handlers/**, rest api, endpoint, http method, status code, versioning, pagination, openapi, api design, api contract)

498 Updated today
HoangNguyen0403