This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
make test # Run unit tests (excludes integration tests)
make test-integration # Run integration tests (requires credentials)
make examples # Run all example scripts
make us_street_api # Run US Street API examplesTo run a single test file:
./vendor/bin/phpunit tests/US_Street/ClientTest.phpTo run a specific test method:
./vendor/bin/phpunit --filter testMethodName tests/US_Street/ClientTest.phpThis is the official SmartyStreets PHP SDK for address validation APIs. All code lives under the SmartyStreets\PhpSdk namespace with PSR-4 autoloading.
ClientBuilder (src/ClientBuilder.php) - Entry point for creating API clients. Uses fluent builder pattern with chainable methods (retryAtMost(), withMaxTimeout(), withLicenses()). Each API has a dedicated build method (e.g., buildUsStreetApiClient()).
Sender Chain - HTTP requests flow through a decorator/chain pattern:
CustomQuerySender → LicenseSender → URLPrefixSender → SigningSender → RetrySender → StatusCodeSender → NativeSender (cURL)
Each sender wraps the next and implements the Sender interface.
API Modules - Each API (US_Street, US_ZIPCode, International_Street, etc.) has its own directory with:
Client.php- API client withsendLookup()andsendBatch()methodsLookup.php- Input container implementingJsonSerializableCandidate.php- Response object- Supporting classes for metadata, components, analysis results
- Batch Processing:
Batchclass holds up to 100 lookups per request. Results map back to inputs by index. - Authentication:
Credentialsinterface withStaticCredentials(auth-id/auth-token query params),SharedCredentials(embedded key signing), andBasicAuthCredentials(HTTP Basic Auth header) implementations. - Exception Hierarchy: All exceptions inherit from
SmartyException. Status codes map to specific exceptions (e.g.,BadCredentialsException,TooManyRequestsException). - Retry Logic:
RetrySenderhandles retryable status codes (408, 429, 500, 502, 503, 504) with backoff viaSleeperinterface.
Tests mirror the src directory structure. Key test utilities in tests/Mocks/:
MockSender- Mocks HTTP responsesRequestCapturingSender- Captures requests for assertionsMockSerializer,MockSleeper,MockLogger- Infrastructure mocks
- PHP >= 8.3
- Zero runtime dependencies (PSR Log is optional for custom logging)
- Dev: PHPUnit 12