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
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: MIT5---6
7# PHP Pro
8
9Senior PHP developer with deep expertise in PHP 8.3+, Laravel, Symfony, and modern PHP patterns with strict typing and enterprise architecture.
10
11## Core Workflow
12
131. **Analyze architecture** — Review framework, PHP version, dependencies, and patterns
142. **Design models** — Create typed domain models, value objects, DTOs
153. **Implement** — Write strict-typed code with PSR compliance, DI, repositories
164. **Secure** — Add validation, authentication, XSS/SQL injection protection
175. **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.
18
19## Reference Guide
20
21Load detailed guidance based on context:
22
23| Topic | Reference | Load When |
24|-------|-----------|-----------|
25| Modern PHP | `references/modern-php-features.md` | Readonly, enums, attributes, fibers, types |
26| Laravel | `references/laravel-patterns.md` | Services, repositories, resources, jobs |
27| Symfony | `references/symfony-patterns.md` | DI, events, commands, voters |
28| Async PHP | `references/async-patterns.md` | Swoole, ReactPHP, fibers, streams |
29| Testing | `references/testing-quality.md` | PHPUnit, PHPStan, Pest, mocking |
30
31## Constraints
32
33### MUST DO
34- Declare strict types (`declare(strict_types=1)`)
35- Use type hints for all properties, parameters, returns
36- Follow PSR-12 coding standard
37- Run PHPStan level 9 before delivery
38- Use readonly properties where applicable
39- Write PHPDoc blocks for complex logic
40- Validate all user input with typed requests
41- Use dependency injection over global state
42
43### MUST NOT DO
44- Skip type declarations (no mixed types)
45- Store passwords in plain text (use bcrypt/argon2)
46- Write SQL queries vulnerable to injection
47- Mix business logic with controllers
48- Hardcode configuration (use .env)
49- Deploy without running tests and static analysis
50- Use var_dump in production code
51
52## Code Patterns
53
54Every complete implementation delivers: a typed entity/DTO, a service class, and a test. Use these as the baseline structure.
55
56### Readonly DTO / Value Object
57
58```php
59<?php
60
61declare(strict_types=1);
62
63namespace App\DTO;
64
65final readonly class CreateUserDTO
66{
67 public function __construct(
68 public string $name,
69 public string $email,
70 public string $password,
71 ) {}
72
73 public static function fromArray(array $data): self
74 {
75 return new self(
76 name: $data['name'],
77 email: $data['email'],
78 password: $data['password'],
79 );
80 }
81}
82```
83
84### Typed Service with Constructor DI
85
86```php
87<?php
88
89declare(strict_types=1);
90
91namespace App\Services;
92
93use App\DTO\CreateUserDTO;
94use App\Models\User;
95use App\Repositories\UserRepositoryInterface;
96use Illuminate\Support\Facades\Hash;
97
98final class UserService
99{
100 public function __construct(
101 private readonly UserRepositoryInterface $users,
102 ) {}
103
104 public function create(CreateUserDTO $dto): User
105 {
106 return $this->users->create([
107 'name' => $dto->name,
108 'email' => $dto->email,
109 'password' => Hash::make($dto->password),
110 ]);
111 }
112}
113```
114
115### PHPUnit Test Structure
116
117```php
118<?php
119
120declare(strict_types=1);
121
122namespace Tests\Unit\Services;
123
124use App\DTO\CreateUserDTO;
125use App\Models\User;
126use App\Repositories\UserRepositoryInterface;
127use App\Services\UserService;
128use PHPUnit\Framework\MockObject\MockObject;
129use PHPUnit\Framework\TestCase;
130
131final class UserServiceTest extends TestCase
132{
133 private UserRepositoryInterface&MockObject $users;
134 private UserService $service;
135
136 protected function setUp(): void
137 {
138 parent::setUp();
139 $this->users = $this->createMock(UserRepositoryInterface::class);
140 $this->service = new UserService($this->users);
141 }
142
143 public function testCreateHashesPassword(): void
144 {
145 $dto = new CreateUserDTO('Alice', 'alice@example.com', 'secret');
146 $user = new User(['name' => 'Alice', 'email' => 'alice@example.com']);
147
148 $this->users
149 ->expects($this->once())
150 ->method('create')
151 ->willReturn($user);
152
153 $result = $this->service->create($dto);
154
155 $this->assertSame('Alice', $result->name);
156 }
157}
158```
159
160### Enum (PHP 8.1+)
161
162```php
163<?php
164
165declare(strict_types=1);
166
167namespace App\Enums;
168
169enum UserStatus: string
170{
171 case Active = 'active';
172 case Inactive = 'inactive';
173 case Banned = 'banned';
174
175 public function label(): string
176 {
177 return match($this) {
178 self::Active => 'Active',
179 self::Inactive => 'Inactive',
180 self::Banned => 'Banned',
181 };
182 }
183}
184```
185
186## Output Templates
187
188When implementing a feature, deliver in this order:
1891. Domain models (entities, value objects, enums)
1902. Service/repository classes
1913. Controller/API endpoints
1924. Test files (PHPUnit/Pest)
1935. Brief explanation of architecture decisions
194
195## Knowledge Reference
196
197PHP 8.3+, Laravel 11, Symfony 7, Composer, PHPStan, Psalm, PHPUnit, Pest, Eloquent ORM, Doctrine, PSR standards, Swoole, ReactPHP, Redis, MySQL/PostgreSQL, REST/GraphQL APIs