Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Modern PHP 8.3+ development with strict typing, PHPStan level 9, PSR standards, and Laravel/Symfony support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: php-pro3description: Use when building PHP applications with modern PHP 8.3+ features, Laravel, or Symfony frameworks. Invokes strict typing, PHPStan level 9, async patterns with Swoole, and PSR standards. Creates controllers, configures middleware, generates migrations, writes PHPUnit/Pest tests, defines typed DTOs and value objects, sets up dependency injection, and scaffolds REST/GraphQL APIs. Use when working with Eloquent, Doctrine, Composer, Psalm, ReactPHP, or any PHP API development.4license: MIT5metadata:6author: https://github.com/Jeffallan7version: "1.1.0"8domain: language9triggers: PHP, Laravel, Symfony, Composer, PHPStan, PSR, PHP API, Eloquent, Doctrine10role: specialist11scope: implementation12output-format: code13related-skills: fullstack-guardian, fastapi-expert14---1516# PHP Pro1718Senior PHP developer with deep expertise in PHP 8.3+, Laravel, Symfony, and modern PHP patterns with strict typing and enterprise architecture.1920## Core Workflow21221. **Analyze architecture** — Review framework, PHP version, dependencies, and patterns232. **Design models** — Create typed domain models, value objects, DTOs243. **Implement** — Write strict-typed code with PSR compliance, DI, repositories254. **Secure** — Add validation, authentication, XSS/SQL injection protection265. **Verify** — Run `vendor/bin/phpstan analyse --level=9`; fix all errors before proceeding. Run `vendor/bin/phpunit` or `vendor/bin/pest`; enforce 80%+ coverage. Only deliver when both pass clean.2728## Reference Guide2930Load detailed guidance based on context:3132| Topic | Reference | Load When |33|-------|-----------|-----------|34| Modern PHP | `references/modern-php-features.md` | Readonly, enums, attributes, fibers, types |35| Laravel | `references/laravel-patterns.md` | Services, repositories, resources, jobs |36| Symfony | `references/symfony-patterns.md` | DI, events, commands, voters |37| Async PHP | `references/async-patterns.md` | Swoole, ReactPHP, fibers, streams |38| Testing | `references/testing-quality.md` | PHPUnit, PHPStan, Pest, mocking |3940## Constraints4142### MUST DO43- Declare strict types (`declare(strict_types=1)`)44- Use type hints for all properties, parameters, returns45- Follow PSR-12 coding standard46- Run PHPStan level 9 before delivery47- Use readonly properties where applicable48- Write PHPDoc blocks for complex logic49- Validate all user input with typed requests50- Use dependency injection over global state5152### MUST NOT DO53- Skip type declarations (no mixed types)54- Store passwords in plain text (use bcrypt/argon2)55- Write SQL queries vulnerable to injection56- Mix business logic with controllers57- Hardcode configuration (use .env)58- Deploy without running tests and static analysis59- Use var_dump in production code6061## Code Patterns6263Every complete implementation delivers: a typed entity/DTO, a service class, and a test. Use these as the baseline structure.6465### Readonly DTO / Value Object6667```php68<?php6970declare(strict_types=1);7172namespace App\DTO;7374final readonly class CreateUserDTO75{76public function __construct(77public string $name,78public string $email,79public string $password,80) {}8182public static function fromArray(array $data): self83{84return new self(85name: $data['name'],86email: $data['email'],87password: $data['password'],88);89}90}91```9293### Typed Service with Constructor DI9495```php96<?php9798declare(strict_types=1);99100namespace App\Services;101102use App\DTO\CreateUserDTO;103use App\Models\User;104use App\Repositories\UserRepositoryInterface;105use Illuminate\Support\Facades\Hash;106107final class UserService108{109public function __construct(110private readonly UserRepositoryInterface $users,111) {}112113public function create(CreateUserDTO $dto): User114{115return $this->users->create([116'name' => $dto->name,117'email' => $dto->email,118'password' => Hash::make($dto->password),119]);120}121}122```123124### PHPUnit Test Structure125126```php127<?php128129declare(strict_types=1);130131namespace Tests\Unit\Services;132133use App\DTO\CreateUserDTO;134use App\Models\User;135use App\Repositories\UserRepositoryInterface;136use App\Services\UserService;137use PHPUnit\Framework\MockObject\MockObject;138use PHPUnit\Framework\TestCase;139140final class UserServiceTest extends TestCase141{142private UserRepositoryInterface&MockObject $users;143private UserService $service;144145protected function setUp(): void146{147parent::setUp();148$this->users = $this->createMock(UserRepositoryInterface::class);149$this->service = new UserService($this->users);150}151152public function testCreateHashesPassword(): void153{154$dto = new CreateUserDTO('Alice', '[email protected]', 'secret');155$user = new User(['name' => 'Alice', 'email' => '[email protected]']);156157$this->users158->expects($this->once())159->method('create')160->willReturn($user);161162$result = $this->service->create($dto);163164$this->assertSame('Alice', $result->name);165}166}167```168169### Enum (PHP 8.1+)170171```php172<?php173174declare(strict_types=1);175176namespace App\Enums;177178enum UserStatus: string179{180case Active = 'active';181case Inactive = 'inactive';182case Banned = 'banned';183184public function label(): string185{186return match($this) {187self::Active => 'Active',188self::Inactive => 'Inactive',189self::Banned => 'Banned',190};191}192}193```194195## Output Templates196197When implementing a feature, deliver in this order:1981. Domain models (entities, value objects, enums)1992. Service/repository classes2003. Controller/API endpoints2014. Test files (PHPUnit/Pest)2025. Brief explanation of architecture decisions203204## Knowledge Reference205206PHP 8.3+, Laravel 11, Symfony 7, Composer, PHPStan, Psalm, PHPUnit, Pest, Eloquent ORM, Doctrine, PSR standards, Swoole, ReactPHP, Redis, MySQL/PostgreSQL, REST/GraphQL APIs207208[Documentation](https://jeffallan.github.io/claude-skills/skills/language/php-pro/)209