maxiviper117 / result-flow
A minimal Result type with branch-aware chaining for PHP
Fund package maintenance!
v1.11.6
2026-03-27 17:25 UTC
Requires
- php: ^8.2
Requires (Dev)
- laravel/pint: ^1.14
- pestphp/pest: ^3.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- rector/rector: ^2.3
- dev-main
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11.0
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.1
- v1.7.0
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v0.1.2
- v0.1.1
- v0.1.0
- dev-dependabot/github_actions/pnpm/action-setup-6
- dev-feat/structured-domain-errors
- dev-dependabot/github_actions/dependabot/fetch-metadata-3.0.0
- dev-dependabot/github_actions/actions/deploy-pages-5
- dev-release-please--branches--main--components--result-flow
- dev-03-27-fix_metaops-reflection-arity-and-test-helper-diagnostics
- dev-docs/improve-docs
- dev-dependabot/github_actions/pnpm/action-setup-5
- dev-dependabot/github_actions/ramsey/composer-install-4
- dev-feat/examples-reorg-and-quality
- dev-refactor/support-structure
- dev-alert-autofix-1
- dev-alert-autofix-2
- dev-alert-autofix-3
- dev-02-15-codex_setup-rector-php
- dev-02-15-codex_add-laravel-boost-package-guidelines
- dev-02-07-ci_update_ci
- dev-02-07-docs_improve_docs
- dev-feature/add-collection-helpers-for-mapping-arrays-to-result-pipelines
- dev-copilot/add-log-level-mapping
This package is auto-updated.
Last update: 2026-04-13 14:48:10 UTC
README
Minimal, type-safe Result type for explicit success/failure handling in PHP (PHP 8.2+).
Composer:
composer require maxiviper117/result-flow
Documentation map
Why Result Flow
- Explicit branches: success and failure are handled intentionally.
- Metadata propagation: context survives across every chain step.
- Predictable semantics: fail-fast and collect-all tools are explicit and separate.
- Type-aware design: PHPStan-friendly templates across public methods.
Quick example
use Maxiviper117\ResultFlow\Result; $result = Result::ok(['order_id' => 123, 'total' => 42], ['request_id' => 'r-1']) ->ensure(fn (array $order) => $order['total'] > 0, 'Order total must be positive') ->then(fn (array $order) => Result::ok([ 'saved' => true, 'id' => $order['order_id'], ])); $output = $result->match( onSuccess: fn (array $v) => ['ok' => true, 'data' => $v], onFailure: fn ($e) => ['ok' => false, 'error' => (string) $e], );
Deferred operations
use Maxiviper117\ResultFlow\Result; $result = Result::defer(fn () => loadUserById($id)) ->then(fn (array $user) => Result::ok(normalizeUser($user)));
Retry deferred operations
use Maxiviper117\ResultFlow\Result; $result = Result::retryDefer( 3, fn () => callExternalApi($payload), delay: 100, exponential: true, );
Resource-safe operations
use Maxiviper117\ResultFlow\Result; $result = Result::bracket( acquire: fn () => fopen($path, 'r'), use: fn ($handle) => fread($handle, 100), release: fn ($handle) => fclose($handle), );
Batch workflows
Result::mapItems($items, $fn)for per-itemResultstatus.Result::mapAll($items, $fn)for fail-fast aggregate processing.Result::mapCollectErrors($items, $fn)for collect-all error reporting.
All batch callbacks use: fn ($item, $key) => Result|value.
Laravel Boost
This package ships Laravel Boost source assets so AI agents in downstream consumer apps can generate ResultFlow-aware code.
Package-shipped guideline source
- Source file in this package:
resources/boost/guidelines/core.blade.php - In a Laravel app that uses Boost, run:
php artisan boost:install
Boost applies package-shipped guidance within the app AI context.
Package-shipped central skill source
- Source file in this package:
resources/boost/skills/result-flow/SKILL.md
- The central skill loads only needed concept references from:
resources/boost/skills/result-flow/references/*.md
App-level overrides
App teams can define or override guidelines locally:
.ai/guidelines/...
To override a built-in guideline, use the same relative path in .ai/guidelines, for example:
.ai/guidelines/inertia-react/2/forms.blade.php
Contributing
- Tests:
composer test - Static analysis:
composer analyse - Rector check:
composer rector-dry - Rector apply:
composer rector - Format:
composer format
See CONTRIBUTING.md.
License
MIT - see LICENSE.md.