All skills
michtio avatar

/craft-php-guidelines

@614a89e

Craft CMS 5 PHP coding standards and conventions. ALWAYS load when writing, editing, reviewing, or discussing any PHP in a Craft plugin or module — even small edits. Also when running ECS, PHPStan, or scaffolding with ddev craft make. Covers: PHPDoc blocks (@author, @since, @throws chains), section headers (=========), class organization, naming conventions (services, queue jobs, records, events, enums), defineRules() and validation, beforePrepare() and addSelect(), MemoizableArray, DateTimeHelper vs Carbon, strict_types/declare(strict_types=1), short nullable notation (?string), typed properties, void returns, control flow (early returns, match over switch), CP Twig template conventions, form macros, translations (Craft::t), ECS/PHPStan config, scaffolding commands, and the verification checklist. Triggers on: writing service classes, models, controllers, elements, element queries, records, queue jobs, migrations, or any PHP class in a Craft context; PHP code review, refactoring, or style questions; requireAdmin vs requirePermission, manage-settings, settings permission, kebab-case permission handles never camelCase, 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/Garnish (craft-garnish). If you are touching PHP in a Craft context, you need this skill.

Use this Skill: https://skilld.dev/gh/michtio/craftcms-claude-skills/craft-php-guidelines

This session only. Nothing lands on disk.

referencesphpdoc-standards.md

≈617 tokens on demand. Your agent reads this file only when SKILL.md points to it.

PHPDoc Standards

PHPDocs on every class, method, and property. No exceptions.

Class Docblocks

/**
 * The Items service provides APIs for managing plugin entities.
 *
 * An instance of the service is available via `MyPlugin::$plugin->getItems()`.
 *
 * @property-read SomeType $thing
 *
 * @author <Author Name>
 * @since 5.0.0
 */

Method Docblocks

/**
 * Returns the item matching the given ID.
 *
 * @param int $id the item ID
 * @return Item|null
 * @throws InvalidConfigException if the service is not initialized
 *
 * @author <Author Name>
 * @since 5.0.0
 */
  • Full sentence description, proper capitalization and punctuation.
  • @param / @return: no capitalization, no ending punctuation. (The official Craft guideline says this, but core itself routinely capitalizes @param/@return descriptions; this project follows the official guideline as its house rule — lowercase, unpunctuated.)
  • @throws: document every thrown exception, including uncaught exceptions from called methods.
  • @author and @since at the bottom, after a blank line. (Craft core puts @author at the class level only — not on methods. Repeating it on each method is this project's house convention, not core style.)

Property Docblocks

@author is NOT used on properties — only on classes and methods. Properties use @var and @since:

/**
 * @var MemoizableArray<Item>|null
 * @see _items()
 */
private ?MemoizableArray $_items = null;

/**
 * @var int|null The parent entity this item belongs to.
 *
 * @since 5.0.0
 */
public ?int $parentId = null;

Constant Docblocks

Follow Craft core pattern — @event for event constants, @since always:

/**
 * @event ItemEvent The event that is triggered before an item is saved.
 * @since 5.0.0
 */
public const EVENT_BEFORE_SAVE_ITEM = 'beforeSaveItem';

@inheritdoc Rule

Only when the parent class or interface has a meaningful doc comment. Otherwise write a full docblock.

Type References

  • Public service methods: reference interfaces (ElementInterface, not Element).
  • Inline @var tags: reference implementations.
  • Use bool/int, not boolean/integer.
  • Use static as return type for chainable methods.
  • Use typed arrays in docblocks: ElementInterface[].
  • Always import classnames in docblocks — never fully qualified names.
  • For iterables, specify key and value types: @param array<int, MyObject> $items.

Source: SKILL.md on GitHub

No alerts16d3 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides comprehensive PHP coding standards, project organization rules, and development guidelines for Craft CMS 5. It emphasizes secure coding practices, such as implementing authorization parity across multiple application surfaces and using framework-specific helpers for environment access and date handling. No malicious patterns or security risks were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

Signed by skilld at 614a89e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 weeks ago

README badge

README badge for michtio/craftcms-claude-skills/craft-php-guidelines