Convert Result from abstract class to interface#6
Conversation
Co-authored-by: valbeat <3125309+valbeat@users.noreply.github.com>
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Pull Request Overview
This PR converts the Result type from an abstract class to an interface to provide a more flexible architecture while maintaining backward compatibility. The change affects the base Result type and its concrete implementations.
- Converts
Resultfrom abstract class to interface with implicit abstract methods - Updates
OkandErrclasses to implement the interface instead of extending the abstract class - Changes PHPDoc annotations from
@extendsto@implementsfor proper interface documentation
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Result.php | Converts abstract class to interface, removes abstract keywords from method declarations |
| src/Ok.php | Updates to implement Result interface instead of extending abstract class |
| src/Err.php | Updates to implement Result interface instead of extending abstract class |
| * @return bool | ||
| */ | ||
| abstract public function isOk(): bool; | ||
| public function isOk(): bool; |
There was a problem hiding this comment.
Interface methods cannot have implementations, so the method declaration should not include a body. The semicolon is correct, but this applies to all methods in the interface.
This PR converts the
Resulttype from an abstract class to an interface as requested in the issue. The change maintains full backward compatibility while providing a more flexible interface-based architecture.Changes Made
Result.php
abstract readonly class Resulttointerface Resultabstractkeyword from all method declarations (interfaces have implicitly abstract methods)@template T,@template E)Ok.php and Err.php
extends Resulttoimplements Result@extends Result<T, never>to@implements Result<T, never>#[Override]attributes (valid for interface implementations in PHP 8.3+)Functional Verification
The conversion preserves all existing functionality:
instanceof Resultworks correctlyisOk(),isErr(),unwrap(),map(),match(), etc.) function identicallyExample usage remains unchanged:
Fixes #5.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.