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', '<test-password>');
$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
Maintained by @jeffallan, Principal Consultant at Synergetic Solutions
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/tuyv/php-pro7 author: https://github.com/Jeffallan8 company: https://synergetic.solutions9 version: "1.1.0"10 domain: language11 triggers: PHP, Laravel, Symfony, Composer, PHPStan, PSR, PHP API, Eloquent, Doctrine12 role: specialist13 scope: implementation14 output-format: code15 related-skills: fullstack-guardian, fastapi-expert16---1718# PHP Pro1920Senior PHP developer with deep expertise in PHP 8.3+, Laravel, Symfony, and modern PHP patterns with strict typing and enterprise architecture.2122## Core Workflow23241. **Analyze architecture** — Review framework, PHP version, dependencies, and patterns252. **Design models** — Create typed domain models, value objects, DTOs263. **Implement** — Write strict-typed code with PSR compliance, DI, repositories274. **Secure** — Add validation, authentication, XSS/SQL injection protection285. **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.2930## Reference Guide3132Load detailed guidance based on context:3334| Topic | Reference | Load When |35|-------|-----------|-----------|36| Modern PHP | `references/modern-php-features.md` | Readonly, enums, attributes, fibers, types |37| Laravel | `references/laravel-patterns.md` | Services, repositories, resources, jobs |38| Symfony | `references/symfony-patterns.md` | DI, events, commands, voters |39| Async PHP | `references/async-patterns.md` | Swoole, ReactPHP, fibers, streams |40| Testing | `references/testing-quality.md` | PHPUnit, PHPStan, Pest, mocking |4142## Constraints4344### MUST DO45- Declare strict types (`declare(strict_types=1)`)46- Use type hints for all properties, parameters, returns47- Follow PSR-12 coding standard48- Run PHPStan level 9 before delivery49- Use readonly properties where applicable50- Write PHPDoc blocks for complex logic51- Validate all user input with typed requests52- Use dependency injection over global state5354### MUST NOT DO55- Skip type declarations (no mixed types)56- Store passwords in plain text (use bcrypt/argon2)57- Write SQL queries vulnerable to injection58- Mix business logic with controllers59- Hardcode configuration (use .env)60- Deploy without running tests and static analysis61- Use var_dump in production code6263## Code Patterns6465Every complete implementation delivers: a typed entity/DTO, a service class, and a test. Use these as the baseline structure.6667### Readonly DTO / Value Object6869```php70<?php7172declare(strict_types=1);7374namespace App\DTO;7576final readonly class CreateUserDTO77{78 public function __construct(79 public string $name,80 public string $email,81 public string $password,82 ) {}8384 public static function fromArray(array $data): self85 {86 return new self(87 name: $data['name'],88 email: $data['email'],89 password: $data['password'],90 );91 }92}93```9495### Typed Service with Constructor DI9697```php98<?php99100declare(strict_types=1);101102namespace App\Services;103104use App\DTO\CreateUserDTO;105use App\Models\User;106use App\Repositories\UserRepositoryInterface;107use Illuminate\Support\Facades\Hash;108109final class UserService110{111 public function __construct(112 private readonly UserRepositoryInterface $users,113 ) {}114115 public function create(CreateUserDTO $dto): User116 {117 return $this->users->create([118 'name' => $dto->name,119 'email' => $dto->email,120 'password' => Hash::make($dto->password),121 ]);122 }123}124```125126### PHPUnit Test Structure127128```php129<?php130131declare(strict_types=1);132133namespace Tests\Unit\Services;134135use App\DTO\CreateUserDTO;136use App\Models\User;137use App\Repositories\UserRepositoryInterface;138use App\Services\UserService;139use PHPUnit\Framework\MockObject\MockObject;140use PHPUnit\Framework\TestCase;141142final class UserServiceTest extends TestCase143{144 private UserRepositoryInterface&MockObject $users;145 private UserService $service;146147 protected function setUp(): void148 {149 parent::setUp();150 $this->users = $this->createMock(UserRepositoryInterface::class);151 $this->service = new UserService($this->users);152 }153154 public function testCreateHashesPassword(): void155 {156 $dto = new CreateUserDTO('Alice', 'alice@example.com', '<test-password>');157 $user = new User(['name' => 'Alice', 'email' => 'alice@example.com']);158159 $this->users160 ->expects($this->once())161 ->method('create')162 ->willReturn($user);163164 $result = $this->service->create($dto);165166 $this->assertSame('Alice', $result->name);167 }168}169```170171### Enum (PHP 8.1+)172173```php174<?php175176declare(strict_types=1);177178namespace App\Enums;179180enum UserStatus: string181{182 case Active = 'active';183 case Inactive = 'inactive';184 case Banned = 'banned';185186 public function label(): string187 {188 return match($this) {189 self::Active => 'Active',190 self::Inactive => 'Inactive',191 self::Banned => 'Banned',192 };193 }194}195```196197## Output Templates198199When implementing a feature, deliver in this order:2001. Domain models (entities, value objects, enums)2012. Service/repository classes2023. Controller/API endpoints2034. Test files (PHPUnit/Pest)2045. Brief explanation of architecture decisions205206## Knowledge Reference207208PHP 8.3+, Laravel 11, Symfony 7, Composer, PHPStan, Psalm, PHPUnit, Pest, Eloquent ORM, Doctrine, PSR standards, Swoole, ReactPHP, Redis, MySQL/PostgreSQL, REST/GraphQL APIs209210Maintained by [@jeffallan](https://github.com/jeffallan), Principal Consultant at [Synergetic Solutions](https://synergetic.solutions)211212[Documentation](https://jeffallan.github.io/claude-skills/skills/language/php-pro/)