Skip to content

Convert Result from abstract class to interface#6

Merged
valbeat merged 2 commits into
mainfrom
copilot/fix-5
Jul 29, 2025
Merged

Convert Result from abstract class to interface#6
valbeat merged 2 commits into
mainfrom
copilot/fix-5

Conversation

Copilot AI commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

This PR converts the Result type 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

  • Changed from abstract readonly class Result to interface Result
  • Removed abstract keyword from all method declarations (interfaces have implicitly abstract methods)
  • Preserved all method signatures, return types, and PHPDoc annotations
  • Maintained generic template types (@template T, @template E)

Ok.php and Err.php

  • Updated class declarations from extends Result to implements Result
  • Changed PHPDoc annotations from @extends Result<T, never> to @implements Result<T, never>
  • Kept all #[Override] attributes (valid for interface implementations in PHP 8.3+)

Functional Verification

The conversion preserves all existing functionality:

  • Type checking with instanceof Result works correctly
  • All Result methods (isOk(), isErr(), unwrap(), map(), match(), etc.) function identically
  • Generic type safety is maintained through PHPDoc templates
  • Method chaining and monadic operations continue to work as expected

Example usage remains unchanged:

$result = new Ok("success");
$result->map(fn($x) => strtoupper($x))->unwrap(); // "SUCCESS"

$error = new Err("failed");
$error->unwrapOr("default"); // "default"

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.

Co-authored-by: valbeat <3125309+valbeat@users.noreply.github.com>
Copilot AI changed the title [WIP] Resultの定義を抽象クラスではなく、interfaceに変更 Convert Result from abstract class to interface Jul 28, 2025
Copilot AI requested a review from valbeat July 28, 2025 15:42
@valbeat valbeat marked this pull request as ready for review July 29, 2025 04:54
Copilot AI review requested due to automatic review settings July 29, 2025 04:54
@valbeat valbeat merged commit 0676115 into main Jul 29, 2025
2 checks passed
@coderabbitai

coderabbitai Bot commented Jul 29, 2025

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-5

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Result from abstract class to interface with implicit abstract methods
  • Updates Ok and Err classes to implement the interface instead of extending the abstract class
  • Changes PHPDoc annotations from @extends to @implements for 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

Comment thread src/Result.php
* @return bool
*/
abstract public function isOk(): bool;
public function isOk(): bool;

Copilot AI Jul 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@valbeat valbeat deleted the copilot/fix-5 branch July 29, 2025 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resultの定義を抽象クラスではなく、interfaceに変更

3 participants