arielespinoza07/result-pattern

A modern implementation of the Result pattern for handling operation outcomes and HTTP responses

v2.1.0 2025-08-08 20:40 UTC

This package is auto-updated.

Last update: 2025-09-13 19:51:39 UTC


README

Build Status Total Downloads Latest Stable Version License

A modern and simple implementation of the Result pattern for handling operation outcomes or HTTP responses.

**Requires PHP 8.3+ **

Features

  • 🛡️ Type-safe result handling with strict type hints
  • 🌐 Complete HTTP response status codes support (1xx to 5xx)
  • 🔒 Immutable objects using PHP 8.3+ readonly classes
  • 🎯 SOLID principles adherence
  • 🧩 Composable and extensible design
  • 📝 Comprehensive test suite with Pest PHP

Project Structure

src/
├── Enums/
│   └── HttpResponseStatusCode.php
├── Failure.php
├── Success.php
└── Result.php

Installation

composer require arielespinoza07/result-pattern

Documentation

The following documentation files provide examples and usage patterns for the Result pattern:

Available Response Codes

  • Informational Responses (1xx)
  • Success Responses (2xx)
  • Redirection Responses (3xx)
  • Client Error Responses (4xx)
  • Server Error Responses (5xx)

Development

Requirements

  • PHP 8.3+
  • Composer 2.0+

Installation

composer require arielespinoza07/result-pattern

Development Installation

git https://github.com/ArielEspinoza07/result-pattern.git
cd result-pattern
composer install

Quality Tools

This package uses several tools to ensure code quality:

# Run all checks
composer test

# Run specific checks
composer test:lint     # Check code style
composer test:types    # Run static analysis
composer test:unit     # Run unit tests
composer test:coverage # Check test coverage

Continuous Integration

GitHub Actions automatically run the following checks on push and pull requests:

  • Static analysis with PHPStan (level max)
  • Unit tests with Pest PHP
  • Code style with Laravel Pint
  • Type coverage check
  • Typo check with Peck

Testing

This package uses Pest PHP for testing. To run the tests:

composer test

To generate a coverage report:

composer test:coverage

The coverage report will be available in the coverage directory.

Development Tools

This package uses several development tools: to ensure code quality and maintainability:

Code Quality Tools

  • Pest PHP: Modern Testing Framework with custom expectations

    composer test           # Run tests
    composer test:coverage  # Run tests with coverage report
  • Laravel Pint: PSR-12 Code Style Fixer

    composer pint      # Fix code style
    composer pint:test # Check code style
  • PHPStan: Static Analysis (Level 9)

    composer analyse   # Run static analysis
  • Rector: PHP 8.3 Compatibility and Code Quality

    composer rector    # Run code quality checks

License

MIT License