|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file helps agentic coding tools work effectively in this repository. |
| 4 | + |
| 5 | +## Scope and intent |
| 6 | +- This is a PHP SDK for PayPal Checkout. |
| 7 | +- Primary code lives in `src/`; tests live in `tests/`. |
| 8 | +- CI runs on PHP 8.1, 8.2, 8.3. |
| 9 | + |
| 10 | +## Build, lint, test |
| 11 | + |
| 12 | +### Install dependencies |
| 13 | +- `composer install` |
| 14 | + |
| 15 | +### Build |
| 16 | +- No dedicated build step is defined for this library. |
| 17 | + |
| 18 | +### Lint/format |
| 19 | +- `composer pint` (Laravel Pint; formatting) |
| 20 | +- `./vendor/bin/pint` (same as above) |
| 21 | + |
| 22 | +### Static analysis |
| 23 | +- `composer analyse` (PHPStan, level max) |
| 24 | +- `phpstan analyse --ansi --debug` (direct) |
| 25 | + |
| 26 | +### Test |
| 27 | +- `composer test` (Pest) |
| 28 | +- `vendor/bin/pest` |
| 29 | + |
| 30 | +### Run a single test |
| 31 | +- `vendor/bin/pest tests/Orders/OrderTest.php` |
| 32 | +- `vendor/bin/pest --filter "can initialize an order"` |
| 33 | +- `vendor/bin/pest tests/Requests/OrderCreateRequestTest.php --filter "has correct request uri"` |
| 34 | + |
| 35 | +### Test configuration notes |
| 36 | +- PHPUnit config: `phpunit.xml` |
| 37 | +- Strict settings are enabled (warnings/risky tests fail the run). |
| 38 | + |
| 39 | +## Repository rules |
| 40 | + |
| 41 | +### Cursor/Copilot rules |
| 42 | +- No `.cursor/rules/`, `.cursorrules`, or `.github/copilot-instructions.md` found. |
| 43 | + |
| 44 | +### Contributing requirements (from `CONTRIBUTING.md`) |
| 45 | +- Follow PSR-2 coding standard. |
| 46 | +- Add tests for changes. |
| 47 | +- Update docs for behavior changes. |
| 48 | +- Keep commits meaningful and squash before PR if needed. |
| 49 | + |
| 50 | +## Code style and conventions |
| 51 | + |
| 52 | +### Formatting |
| 53 | +- Indent with 4 spaces (see `.editorconfig`). |
| 54 | +- Use LF line endings and final newline. |
| 55 | +- Keep trailing whitespace trimmed (except Markdown). |
| 56 | +- Follow PSR-2 layout rules. |
| 57 | + |
| 58 | +### Namespaces and imports |
| 59 | +- Use `PayPal\Checkout\...` namespaces for production code. |
| 60 | +- Place `use` statements after `namespace` with a blank line between. |
| 61 | +- Prefer alphabetical ordering of imports when adding new ones. |
| 62 | + |
| 63 | +### Naming |
| 64 | +- Classes: `PascalCase` (e.g., `OrderCreateRequest`). |
| 65 | +- Methods/properties/variables: `camelCase`. |
| 66 | +- Constants: `UPPER_SNAKE_CASE` (e.g., `CAPTURE`, `AUTHORIZE`). |
| 67 | +- Tests: Pest `it('does something', function () { ... })` with readable names. |
| 68 | + |
| 69 | +### Types and docblocks |
| 70 | +- Use typed properties and return types where possible. |
| 71 | +- Use docblocks for array element types and readonly notes. |
| 72 | +- Interfaces: `Arrayable`, `Jsonable` for objects that serialize. |
| 73 | + |
| 74 | +### Serialization |
| 75 | +- Objects implement `toArray()` and `toJson()` via `CastsToJson`. |
| 76 | +- Throw `JsonEncodingException` on JSON errors. |
| 77 | +- Payload keys are snake_case to match PayPal API. |
| 78 | + |
| 79 | +### Error handling |
| 80 | +- Validate inputs early and throw domain exceptions in `src/Exceptions/`. |
| 81 | +- Prefer specific exceptions (e.g., `InvalidOrderIntentException`). |
| 82 | +- Messages should be explicit and user-facing when appropriate. |
| 83 | + |
| 84 | +### Requests |
| 85 | +- Request classes extend `PayPal\Http\PaypalRequest`. |
| 86 | +- Use explicit headers and JSON body streams. |
| 87 | +- Avoid side effects in request constructors beyond setup. |
| 88 | + |
| 89 | +### Collections and helpers |
| 90 | +- `HasCollection` and similar concerns encapsulate list logic. |
| 91 | +- Use array_map and small helpers for array transformations. |
| 92 | + |
| 93 | +### Tests |
| 94 | +- Use Pest expectations (`expect()->toBe(...)`, etc.). |
| 95 | +- Use helper functions in `tests/Pest.php` for common fixtures. |
| 96 | +- Keep tests deterministic and JSON comparisons explicit. |
| 97 | + |
| 98 | +## Suggested workflow for changes |
| 99 | +- Add or update tests in `tests/` when behavior changes. |
| 100 | +- Run `composer pint` before committing formatting changes. |
| 101 | +- Run `composer analyse` for static analysis checks. |
| 102 | +- Run `composer test` or targeted `vendor/bin/pest` for fast feedback. |
| 103 | + |
| 104 | +## Key files |
| 105 | +- `composer.json`: scripts, dependencies, PHP version support. |
| 106 | +- `phpstan.neon`: static analysis config. |
| 107 | +- `phpunit.xml`: test configuration and strictness settings. |
| 108 | +- `tests/Pest.php`: shared test helpers and setup. |
| 109 | +- `CONTRIBUTING.md`: PSR-2 and contribution expectations. |
0 commit comments