|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to LLM Agents when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Laravel Ban (`cybercog/laravel-ban`) is a Laravel package for banning/unbanning any Eloquent model. It uses a polymorphic `bans` table with soft deletes to maintain ban history, and a `banned_at` timestamp flag on the bannable model for quick status checks. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +All commands run inside Docker. Use the `php84` service (or any other PHP version service from `compose.yml`). |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build and start the container |
| 15 | +docker compose up -d php85 |
| 16 | + |
| 17 | +# Install dependencies |
| 18 | +docker compose exec php85 composer install |
| 19 | + |
| 20 | +# Run all tests |
| 21 | +docker compose exec php85 composer test |
| 22 | + |
| 23 | +# Run a single test file |
| 24 | +docker compose exec php85 vendor/bin/phpunit tests/Unit/Models/BanTest.php |
| 25 | + |
| 26 | +# Run a single test method |
| 27 | +docker compose exec php85 vendor/bin/phpunit --filter test_method_name |
| 28 | + |
| 29 | +# Run tests with details |
| 30 | +docker compose exec php85 vendor/bin/phpunit --testdox |
| 31 | +``` |
| 32 | + |
| 33 | +Available PHP services: `php81`, `php82`, `php83`, `php84`, `php85`. |
| 34 | + |
| 35 | +No dedicated lint or build commands are configured. Code style follows the Laravel StyleCI preset (PSR-2 based). |
| 36 | + |
| 37 | +## Architecture |
| 38 | + |
| 39 | +### Namespace layout |
| 40 | + |
| 41 | +- `Cog\Contracts\Ban\` (`contracts/`) — Interfaces: `Ban`, `Bannable`, `BanService` |
| 42 | +- `Cog\Laravel\Ban\` (`src/`) — Implementations |
| 43 | +- `Cog\Tests\Laravel\Ban\` (`tests/`) — Tests using Orchestra Testbench |
| 44 | + |
| 45 | +### How banning works (the flow) |
| 46 | + |
| 47 | +1. **User calls** `$model->ban($attributes)` (from `HasBannedAtHelpers` trait) |
| 48 | +2. **Delegates to** `BanService::ban()` which creates a `Ban` morph record via `$bannable->bans()->create()` |
| 49 | +3. **BanObserver::created()** fires, sets `banned_at` on the bannable model, dispatches `ModelWasBanned` event |
| 50 | +4. **On unban**: `BanService::unban()` soft-deletes all ban records → `BanObserver::deleted()` fires → clears `banned_at` flag, dispatches `ModelWasUnbanned` event |
| 51 | + |
| 52 | +### Key design decisions |
| 53 | + |
| 54 | +- **Contracts-first**: All core types have interfaces in `contracts/`. The service provider binds `BanContract` → `Ban` model and `BanServiceContract` → `BanService` as singleton. |
| 55 | +- **Composite trait**: `Bannable` trait composes `HasBannedAtHelpers` (ban/unban/isBanned methods), `HasBannedAtScope` (auto-apply global scope), and `HasBansRelation` (morphMany relationship). |
| 56 | +- **Observer pattern**: `BanObserver` handles setting/unsetting the `banned_at` flag and firing events—logic is not in the model or service. |
| 57 | +- **Bans use SoftDeletes**: Unbanning soft-deletes ban records, keeping history. The `bans()` relation only returns active (non-deleted) bans. |
| 58 | + |
| 59 | +### Testing |
| 60 | + |
| 61 | +Tests extend `AbstractTestCase` (Orchestra Testbench). The base class handles publishing migrations, running them on an in-memory SQLite database, and registering model factories. Test stubs live in `tests/Stubs/Models/`, factories in `tests/database/factories/`. |
| 62 | + |
| 63 | +## Supported versions |
| 64 | + |
| 65 | +PHP 8.0+, Laravel 9–12, with corresponding Orchestra Testbench versions. CI tests against PHP 8.0–8.4 with prefer-lowest and prefer-stable dependency resolution. |
0 commit comments