arielespinoza07/result-pattern
最新稳定版本:v2.1.0
Composer 安装命令:
composer require arielespinoza07/result-pattern
包简介
A modern implementation of the Result pattern for handling operation outcomes and HTTP responses
README 文档
README
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:
- Basic Success and Failure Examples - Creating and using Success and Failure objects
- Try Method Examples - Using the
trymethod to handle operations that might throw exceptions - onSuccess and onFailure Examples - Using callbacks for Success and Failure cases
- Map Method Examples - Transforming values inside Success results
- FlatMap Method Examples - Transforming Success results into new Result objects
- Fold Method Examples - Handling both Success and Failure cases with a single return value
- Error Handling Examples - Proper error handling techniques and best practices
- HTTP Response Code Available
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
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-09