All skills
asyrafhussin avatar

/php-best-practices

@e7ea05d

PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/php-best-practices

This session only. Nothing lands on disk.

rulestype-parameter-types.md

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

Parameter Type Declarations

Always declare types for all function and method parameters.

Bad Example

<?php

declare(strict_types=1);

class OrderService
{
    // No parameter types - anything could be passed
    public function createOrder($user, $items, $discount)
    {
        // What is $user? An ID? An object? An array?
        // What format should $items be?
        // Is $discount a percentage or fixed amount?
    }

    public function processPayment($amount, $method)
    {
        // Type assumptions lead to bugs
    }
}

Good Example

<?php

declare(strict_types=1);

class OrderService
{
    public function createOrder(
        User $user,
        array $items,
        float $discountPercentage = 0.0
    ): Order {
        $order = new Order($user);

        foreach ($items as $item) {
            $order->addItem($item);
        }

        $order->applyDiscount($discountPercentage);

        return $order;
    }

    public function processPayment(
        Money $amount,
        PaymentMethod $method
    ): PaymentResult {
        return $this->paymentGateway->charge($amount, $method);
    }
}

Why

  • Clear Contracts: Parameters define the method's expected input
  • Early Error Detection: Type errors are caught immediately at call site
  • Self-Documenting: Types eliminate guesswork about expected inputs
  • Refactoring Safety: Changes to parameter types are caught by static analysis
  • IDE Intelligence: Enables parameter hints and autocompletion
  • Defensive Programming: Prevents invalid data from entering your methods

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    This skill is a comprehensive and safe resource for PHP 8.x best practices. It provides structured guidance on type safety, modern PHP syntax, PSR standards, and secure coding practices (such as prepared statements and password hashing). The agent is instructed to use standard environment detection commands (php -v, grep) to tailor its advice. No malicious patterns or security risks were identified.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    39 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

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

Last checked against GitHub last month.

Steadyupdated 7 months ago
Other metadata
metadata
{
  "author": "php-community",
  "version": "2.1.0",
  "phpVersion": "8.0 - 8.5"
}

README badge

README badge for asyrafhussin/agent-skills/php-best-practices