mcpField
S
solid-php

solid-php

github.com/fusengineDevelopment34103 installsUpdated 2w ago
Repository

About solid-php

solid-php is a coding-guidance skill for Laravel 13 and PHP 8.3+ projects. It detects Laravel or FuseCore modular architecture and provides placement rules, anti-pattern checks, and refactoring guidance based on SOLID and DRY.

Key features

  1. 01Detects Laravel and FuseCore architecture
  2. 02Maps code responsibilities to file locations
  3. 03Enforces file-size and PHPDoc conventions
  4. 04Flags duplication and common anti-patterns
  5. 05Provides SOLID-based refactoring guidance

Use cases

  1. 01Choose a structure for Laravel 13 features
  2. 02Place interfaces and services in FuseCore modules
  3. 03Refactor oversized classes and model business logic

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fusengine/agents --skill solid-php

After installing, type/solid-phpin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
anti-patterns.md
decision-guide.md
dependency-inversion.md
fusecore-structure.md
interface-segregation.md
laravel12-structure.md
liskov-substitution.md
open-closed.md
php85-features.md
single-responsibility.md
solid-principles.md
references/templates/
code-templates.md
controller-templates.md
refactoring-guide.md

Details

From the project README
Enforces SOLID principles and DRY on Laravel 13 + PHP 8.3+ code: files under 100 lines (split at 90), interfaces separated into FuseCore/[Module]/App/Contracts/ (or FuseCore/Core/App/Contracts/ for shared ones), and mandatory PHPDoc on all public methods. Auto-detects Laravel vs FuseCore modular architecture and routes code placement accordingly (Controllers/Requests/Actions/Services/Repositories/DTOs/Contracts/Events/ Policies), with anti-pattern detection (fat classes, business logic in models, concrete dependencies, missing strict_types) and refactoring guidance per SOLID principle (SRP/OCP/LSP/ISP/DIP).

SOLID PHP - Laravel 13 + PHP 8.3

Agent Workflow (MANDATORY)

Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:

  1. fuse-ai-pilot:explore-codebase - Analyze existing architecture
  2. fuse-ai-pilot:research-expert - Verify Laravel/PHP docs via Context7
  3. mcp__context7__query-docs - Check SOLID patterns

After implementation, run fuse-ai-pilot:sniper for validation.


DRY - Reuse Before Creating (MANDATORY)

Before writing ANY new code:

  1. Grep the codebase for similar class names, methods, or logic
  2. Check shared locations: FuseCore/Core/App/Services/, FuseCore/Core/App/Traits/, FuseCore/[Module]/App/Contracts/
  3. If similar code exists → extend/reuse instead of duplicate
  4. If code will be used by 2+ features → create it in shared Services or Traits
  5. Extract repeated logic (3+ occurrences) into shared helpers or Traits
  6. Verify no duplication introduced after writing

Auto-Detection (Modular MANDATORY)

Files DetectedArchitectureInterfaces Location
FuseCore/ directoryFuseCore ModularFuseCore/[Module]/App/Contracts/
module.json in modulesFuseCore ModularFuseCore/[Module]/App/Contracts/

Verification: php artisan --version → Laravel 13.x Structure: Always FuseCore modular. Shared in FuseCore/Core/App/.


Decision Tree: Where to Put Code? (FuseCore Modular)

New code needed?
├── HTTP validation → FuseCore/[Module]/App/Http/Requests/
├── Single action → FuseCore/[Module]/App/Actions/
├── Business logic → FuseCore/[Module]/App/Services/
├── Data access → FuseCore/[Module]/App/Repositories/
├── Data transfer → FuseCore/[Module]/App/DTOs/
├── Interface → FuseCore/[Module]/App/Contracts/
├── Event → FuseCore/[Module]/App/Events/
└── Authorization → FuseCore/[Module]/App/Policies/

Decision Tree: Which Pattern?

NeedPatternLocationMax Lines
HTTP handlingControllerControllers/50
ValidationFormRequestRequests/50
Single operationActionActions/50
Complex logicServiceServices/100
Data accessRepositoryRepositories/100
Data structureDTODTOs/50
AbstractionInterfaceContracts/30

Critical Rules (MANDATORY)

1. Files < 100 lines
  • Split at 90 lines - Never exceed 100
  • Controllers < 50 lines
  • Models < 80 lines (excluding relations)
  • Services < 100 lines
2. Interfaces Separated (FuseCore Modular MANDATORY)
FuseCore/[Module]/App/Contracts/   # Module interfaces ONLY
├── UserRepositoryInterface.php
└── PaymentGatewayInterface.php
FuseCore/Core/App/Contracts/       # Shared interfaces
3. PHPDoc Mandatory
/**
 * Create a new user from DTO.
 *
 * @param CreateUserDTO $dto User data transfer object
 * @return User Created user model
 * @throws ValidationException If email already exists
 */
public function create(CreateUserDTO $dto): User

Reference Guide

Concepts
TopicReferenceWhen to consult
SOLID Overviewsolid-principles.mdQuick reference all principles
SRPsingle-responsibility.mdFile too long, fat controller/model
OCPopen-closed.mdAdding payment methods, channels
LSPliskov-substitution.mdInterface contracts, swapping providers
ISPinterface-segregation.mdFat interfaces, unused methods
DIPdependency-inversion.mdTight coupling, testing, mocking
Anti-Patternsanti-patterns.mdCode smells detection
Decisionsdecision-guide.mdPattern selection
PHP 8.5php85-features.mdModern PHP features
Structurelaravel12-structure.mdStandard Laravel
FuseCorefusecore-structure.mdModular architecture
Templates
TemplateWhen to use
code-templates.mdService, DTO, Repository, Interface
controller-templates.mdController, Action, FormRequest, Policy
refactoring-guide.mdStep-by-step migration from legacy code

Forbidden

Anti-PatternDetectionFix
Files > 100 linesLine countSplit into smaller files
Controllers > 50 linesLine countExtract to Service
Interfaces in impl filesLocationMove to FuseCore/[Module]/App/Contracts/
Business logic in ModelsCode in modelExtract to Service
Concrete dependenciesnew Class()Inject via ModuleServiceProvider
Missing PHPDocNo doc blockAdd documentation
Missing strict_typesNo declareAdd to all files
Fat classes> 5 public methodsSplit responsibilities
Duplicated logicSame code in 2+ filesExtract to Service/Trait
No Grep before codingCreating without searchGrep codebase first

Best Practices

DODON'T
Use constructor property promotionUse property assignment
Depend on interfacesDepend on concrete classes
Use final readonly classUse mutable classes
Use declare(strict_types=1)Skip type declarations
Split at 90 linesWait until 100 lines
Use DTOs for data transferUse arrays

Laravel 13 Notes

PHP 8.3 minimum

Laravel 13 requires PHP 8.3 (was 8.2 on L12). SOLID-friendly features:

  • readonly classes: final readonly class UserDto (full immutability)
  • Typed class constants: const int MAX_RETRIES = 3;
  • #[\Override] attribute: explicitly declares an override of a parent method (catches typos)
  • Native json_validate() (faster than json_decode + try/catch)
  • Dynamic class constant fetch: $class::{$name}
use Override;

final readonly class PaymentService implements PaymentContract
{
    public const int DEFAULT_TIMEOUT = 30;

    public function __construct(
        private StripeClient $stripe,
        private LoggerInterface $logger,
    ) {}

    #[Override]
    public function process(PaymentDto $payment): PaymentResult
    {
        // ...
    }
}
Stricter SOLID rules for L13
  • Prefer final readonly class for all DTOs/Value Objects
  • Use #[\Override] on every inherited method (caught in CI)
  • Type constants (const string ROLE = 'admin';)

Comments

Markdown supported