PHP Pro
Senior PHP developer with deep expertise in PHP 8.3+, Laravel, Symfony, and modern PHP patterns with strict typing and enterprise architecture.
Core Workflow
- Analyze architecture — Review framework, PHP version, dependencies, and patterns
- Design models — Create typed domain models, value objects, DTOs
- Implement — Write strict-typed code with PSR compliance, DI, repositories
- Secure — Add validation, authentication, XSS/SQL injection protection
- 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.
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Modern PHP |
references/modern-php-features.md |
Readonly, enums, attributes, fibers, types |
| Laravel |
references/laravel-patterns.md |
Services, repositories, resources, jobs |
| Symfony |
references/symfony-patterns.md |
DI, events, commands, voters |
| Async PHP |
references/async-patterns.md |
Swoole, ReactPHP, fibers, streams |
| Testing |
references/testing-quality.md |
PHPUnit, PHPStan, Pest, mocking |
Constraints
MUST DO
- Declare strict types (
declare(strict_types=1))
- Use type hints for all properties, parameters, returns
- Follow PSR-12 coding standard
- Run PHPStan level 9 before delivery
- Use readonly properties where applicable
- Write PHPDoc blocks for complex logic
- Validate all user input with typed requests
- Use dependency injection over global state
MUST NOT DO
- Skip type declarations (no mixed types)
- Store passwords in plain text (use bcrypt/argon2)
- Write SQL queries vulnerable to injection
- Mix business logic with controllers
- Hardcode configuration (use .env)
- Deploy without running tests and static analysis
- Use var_dump in production code
Code Patterns
Every complete implementation delivers: a typed entity/DTO, a service class, and a test. Use these as the baseline structure.
Readonly DTO / Value Object
<?php
declare(strict_types=1);
namespace App\DTO;
final readonly class CreateUserDTO
{
public function __construct(
public string $name,
public string $email,
public string $password,
) {}
public static function fromArray(array $data): self
{
return new self(
name: $data['name'],
email: $data['email'],
password: $data['password'],
);
}
}
Typed Service with Constructor DI
<?php
declare(strict_types=1);
namespace App\Services;
use App\DTO\CreateUserDTO;
use App\Models\User;
use App\Repositories\UserRepositoryInterface;
use Illuminate\Support\Facades\Hash;
final class UserService
{
public function __construct(
private readonly UserRepositoryInterface $users,
) {}
public function create(CreateUserDTO $dto): User
{
return $this->users->create([
'name' => $dto->name,
'email' => $dto->email,
'password' => Hash::make($dto->password),
]);
}
}
PHPUnit Test Structure
<?php
declare(strict_types=1);
namespace Tests\Unit\Services;
use App\DTO\CreateUserDTO;
use App\Models\User;
use App\Repositories\UserRepositoryInterface;
use App\Services\UserService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class UserServiceTest extends TestCase
{
private UserRepositoryInterface&MockObject $users;
private UserService $service;
protected function setUp(): void
{
parent::setUp();
$this->users = $this->createMock(UserRepositoryInterface::class);
$this->service = new UserService($this->users);
}
public function testCreateHashesPassword(): void
{
$dto = new CreateUserDTO('Alice', 'alice@example.com', 'secret');
$user = new User(['name' => 'Alice', 'email' => 'alice@example.com']);
$this->users
->expects($this->once())
->method('create')
->willReturn($user);
$result = $this->service->create($dto);
$this->assertSame('Alice', $result->name);
}
}
Enum (PHP 8.1+)
<?php
declare(strict_types=1);
namespace App\Enums;
enum UserStatus: string
{
case Active = 'active';
case Inactive = 'inactive';
case Banned = 'banned';
public function label(): string
{
return match($this) {
self::Active => 'Active',
self::Inactive => 'Inactive',
self::Banned => 'Banned',
};
}
}
Output Templates
When implementing a feature, deliver in this order:
- Domain models (entities, value objects, enums)
- Service/repository classes
- Controller/API endpoints
- Test files (PHPUnit/Pest)
- Brief explanation of architecture decisions
Knowledge Reference
PHP 8.3+, Laravel 11, Symfony 7, Composer, PHPStan, Psalm, PHPUnit, Pest, Eloquent ORM, Doctrine, PSR standards, Swoole, ReactPHP, Redis, MySQL/PostgreSQL, REST/GraphQL APIs
Documentation
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:6 source: https://skillmd.com/skills/jeffallan/php-pro7 author: https://github.com/Jeffallan8 version: "1.1.0"9 domain: language10 triggers: PHP, Laravel, Symfony, Composer, PHPStan, PSR, PHP API, Eloquent, Doctrine11 role: specialist12 scope: implementation13 output-format: code14 related-skills: fullstack-guardian, fastapi-expert15---1617# PHP Pro1819Senior PHP developer with deep expertise in PHP 8.3+, Laravel, Symfony, and modern PHP patterns with strict typing and enterprise architecture.2021## Core Workflow22231. **Analyze architecture** — Review framework, PHP version, dependencies, and patterns242. **Design models** — Create typed domain models, value objects, DTOs253. **Implement** — Write strict-typed code with PSR compliance, DI, repositories264. **Secure** — Add validation, authentication, XSS/SQL injection protection275. **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.2829## Reference Guide3031Load detailed guidance based on context:3233| Topic | Reference | Load When |34|-------|-----------|-----------|35| Modern PHP | `references/modern-php-features.md` | Readonly, enums, attributes, fibers, types |36| Laravel | `references/laravel-patterns.md` | Services, repositories, resources, jobs |37| Symfony | `references/symfony-patterns.md` | DI, events, commands, voters |38| Async PHP | `references/async-patterns.md` | Swoole, ReactPHP, fibers, streams |39| Testing | `references/testing-quality.md` | PHPUnit, PHPStan, Pest, mocking |4041## Constraints4243### MUST DO44- Declare strict types (`declare(strict_types=1)`)45- Use type hints for all properties, parameters, returns46- Follow PSR-12 coding standard47- Run PHPStan level 9 before delivery48- Use readonly properties where applicable49- Write PHPDoc blocks for complex logic50- Validate all user input with typed requests51- Use dependency injection over global state5253### MUST NOT DO54- Skip type declarations (no mixed types)55- Store passwords in plain text (use bcrypt/argon2)56- Write SQL queries vulnerable to injection57- Mix business logic with controllers58- Hardcode configuration (use .env)59- Deploy without running tests and static analysis60- Use var_dump in production code6162## Code Patterns6364Every complete implementation delivers: a typed entity/DTO, a service class, and a test. Use these as the baseline structure.6566### Readonly DTO / Value Object6768```php69<?php7071declare(strict_types=1);7273namespace App\DTO;7475final readonly class CreateUserDTO76{77 public function __construct(78 public string $name,79 public string $email,80 public string $password,81 ) {}8283 public static function fromArray(array $data): self84 {85 return new self(86 name: $data['name'],87 email: $data['email'],88 password: $data['password'],89 );90 }91}92```9394### Typed Service with Constructor DI9596```php97<?php9899declare(strict_types=1);100101namespace App\Services;102103use App\DTO\CreateUserDTO;104use App\Models\User;105use App\Repositories\UserRepositoryInterface;106use Illuminate\Support\Facades\Hash;107108final class UserService109{110 public function __construct(111 private readonly UserRepositoryInterface $users,112 ) {}113114 public function create(CreateUserDTO $dto): User115 {116 return $this->users->create([117 'name' => $dto->name,118 'email' => $dto->email,119 'password' => Hash::make($dto->password),120 ]);121 }122}123```124125### PHPUnit Test Structure126127```php128<?php129130declare(strict_types=1);131132namespace Tests\Unit\Services;133134use App\DTO\CreateUserDTO;135use App\Models\User;136use App\Repositories\UserRepositoryInterface;137use App\Services\UserService;138use PHPUnit\Framework\MockObject\MockObject;139use PHPUnit\Framework\TestCase;140141final class UserServiceTest extends TestCase142{143 private UserRepositoryInterface&MockObject $users;144 private UserService $service;145146 protected function setUp(): void147 {148 parent::setUp();149 $this->users = $this->createMock(UserRepositoryInterface::class);150 $this->service = new UserService($this->users);151 }152153 public function testCreateHashesPassword(): void154 {155 $dto = new CreateUserDTO('Alice', 'alice@example.com', 'secret');156 $user = new User(['name' => 'Alice', 'email' => 'alice@example.com']);157158 $this->users159 ->expects($this->once())160 ->method('create')161 ->willReturn($user);162163 $result = $this->service->create($dto);164165 $this->assertSame('Alice', $result->name);166 }167}168```169170### Enum (PHP 8.1+)171172```php173<?php174175declare(strict_types=1);176177namespace App\Enums;178179enum UserStatus: string180{181 case Active = 'active';182 case Inactive = 'inactive';183 case Banned = 'banned';184185 public function label(): string186 {187 return match($this) {188 self::Active => 'Active',189 self::Inactive => 'Inactive',190 self::Banned => 'Banned',191 };192 }193}194```195196## Output Templates197198When implementing a feature, deliver in this order:1991. Domain models (entities, value objects, enums)2002. Service/repository classes2013. Controller/API endpoints2024. Test files (PHPUnit/Pest)2035. Brief explanation of architecture decisions204205## Knowledge Reference206207PHP 8.3+, Laravel 11, Symfony 7, Composer, PHPStan, Psalm, PHPUnit, Pest, Eloquent ORM, Doctrine, PSR standards, Swoole, ReactPHP, Redis, MySQL/PostgreSQL, REST/GraphQL APIs208209[Documentation](https://jeffallan.github.io/claude-skills/skills/language/php-pro/)