Loading...
Loading...
Modern PHP application development guidance for PHP 8.3+, Symfony, Composer, PHPUnit/Pest, PHPStan, Psalm, PSR standards, Doctrine, DTOs, value objects, dependency injection, migrations, middleware, and REST or GraphQL APIs. Use when Codex needs to build, refactor, test, statically analyze, or review PHP code and framework integrations.
npx skill4agent add corneliusio/skills phpMUSTMUST NOTREQUIREDSHALLSHALL NOTSHOULDSHOULD NOTRECOMMENDEDMAYOPTIONALvendor/bin/phpstan analyse --level=9vendor/bin/phpunitvendor/bin/pest| Topic | Reference | Load When |
|---|---|---|
| Modern PHP | | Readonly, enums, attributes, fibers, types |
| Symfony | | DI, events, commands, voters |
| Async PHP | | Fibers, streams, generators, Amphp |
| Testing | | PHPUnit, PHPStan, Pest, mocking |
declare(strict_types=1)array{...}var_dump<?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'],
);
}
}<?php
declare(strict_types=1);
namespace App\Contracts;
final readonly class ImageContract
{
public function __construct(
public string $url,
public int $width,
public int $height,
public ?string $alt,
) {}
}<?php
declare(strict_types=1);
namespace App\Services;
use App\Models\User;
use App\DTO\CreateUserDTO;
use App\Repositories\UserRepositoryInterface;
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' => password_hash($dto->password, PASSWORD_ARGON2ID),
]);
}
}<?php
declare(strict_types=1);
namespace Tests\Unit\Services;
use App\Models\User;
use App\DTO\CreateUserDTO;
use App\Services\UserService;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
use App\Repositories\UserRepositoryInterface;
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 test_create_hashes_password(): 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);
}
}<?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',
};
}
}