This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Run all tests:
composer test - Run unit tests only:
composer test:unit - Run integration tests only:
composer test:integration - Run tests with coverage:
composer test:coverage - Run specific test:
./vendor/bin/phpunit tests/Unit/SomeTest.php - Run tests with filter:
./vendor/bin/phpunit --filter=testMethodName
- Lint code:
composer lint(runs Duster) - Fix code style:
composer fix(runs Duster fix) - Static analysis:
composer analyse(runs PHPStan) - Run all checks:
composer check(lint + analyse + test)
- Install dependencies:
composer install - Run with NO_NETWORK=1:
NO_NETWORK=1 composer test- For tests that shouldn't make network calls
Fetch PHP is a modern HTTP client library that brings JavaScript's fetch API experience to PHP, built on top of Guzzle HTTP.
src/Fetch/
├── Http/ # Core HTTP components
│ ├── Client.php # Main HTTP client (PSR-18 compliant)
│ ├── ClientHandler.php # Handler for client operations
│ ├── Request.php # HTTP request wrapper
│ └── Response.php # HTTP response wrapper
├── Concerns/ # Trait-based functionality
│ ├── ConfiguresRequests.php # Request configuration
│ ├── HandlesUris.php # URI handling
│ ├── ManagesPromises.php # Async promise management
│ ├── ManagesRetries.php # Retry logic
│ └── PerformsHttpRequests.php # HTTP request execution
├── Enum/ # Type-safe enumerations
│ ├── Method.php # HTTP methods (GET, POST, etc.)
│ ├── ContentType.php # Content type constants
│ └── Status.php # HTTP status codes
├── Support/
│ └── helpers.php # Global helper functions
└── Interfaces/ # Contracts
-
Multiple API Styles: Supports both JavaScript-like
fetch()and traditional PHP helper functions (get(),post(), etc.) -
Global Client Management: Uses a singleton pattern via
fetch_client()for application-wide configuration -
Trait-based Architecture: Core functionality split into focused traits for better separation of concerns
-
PSR Compliance: Implements PSR-18 (HTTP Client), PSR-7 (HTTP Messages), and PSR-3 (Logger)
-
Async/Promise Support: Built on React PHP promises with
async(),await(),all(),race()utilities
fetch()- Main JavaScript-like APIfetch_client()- Global client instance- HTTP method helpers:
get(),post(),put(),patch(),delete() - Async utilities:
async(),await(),all(),race(),map(),batch(),retry()
- Uses Duster (by Tighten) for code formatting
- Configuration in
pint.json(Laravel Pint rules) - Runs PHP CS Fixer and PHPStan under the hood
- Enforces PSR-12 with custom rules
- PHPUnit 11.5+ for unit testing (not Pest)
- Test structure:
tests/Unit/,tests/Integration/ - Coverage reports generated with Xdebug
- CI runs tests on PHP 8.3, 8.4 across Ubuntu, Windows, macOS
- Helper functions (
src/Fetch/Support/) excluded from coverage
- Guzzle HTTP 7.9+ (underlying HTTP client)
- React components (event-loop, promise) for async operations
- Jerome/Matrix 3.3+ (utility library)
- Main branch:
main - Feature branches:
feature/*,fix/*,refactor/* - Development branch:
develop
NO_NETWORK=1- Disables network calls in tests
- Add enum value to
src/Fetch/Enum/Method.php - Add helper function in
src/Fetch/Support/helpers.php - Update
PerformsHttpRequeststrait if needed - Add tests in
tests/Unit/
- Update
ConfiguresRequeststrait - Add to options processing in helper functions
- Document in README examples
- Add tests for new option
- Check CI logs for specific PHP version failures
- Run locally with same PHP version:
php -v - Use
NO_NETWORK=1for offline testing - Check coverage reports in
coverage/directory