M1I10: ProtocolHandlerInterface + TcpHandler#67
Merged
Conversation
s2x
commented
May 2, 2026
Contributor
Author
s2x
left a comment
There was a problem hiding this comment.
Review Summary — Round 1
| # | Severity | File:Line | Finding |
|---|---|---|---|
| — | — | — | No inline findings to report |
Acceptance Criteria Check ✅
- Interface has single method:
handle(Connection): void—ProtocolHandlerInterfacedefines exactly one method with correct signature -
TcpHandleraccepts optional Closure callback — constructor takes?\Closure $callback = null, correctly nullable - No callback = no-op —
handle()checks for closure before invoking; no side effects when callback is null - Handler does NOT close the connection — no
$connection->close()call anywhere inTcpHandler
What's Fine ✔️
- PSR-4 autoloading:
CrazyGoat\Forklift\Server\Protocolmaps correctly tosrc/Server/Protocol/ declare(strict_types=1)on all new files- PHPStan level (neon.dist): 0 errors
- PHPUnit: 3/3 tests pass, 7 assertions
- Constructor uses
readonlyproperty promotion — clean PHP 8.2+ pattern - Closure doc annotation
@var \Closure(Connection): void|nullaids IDE/static analysis - Test covers all three scenarios: null callback, callback invocation, and no-close verification
- Matches issue #12 and milestone doc
docs/superpowers/milestone-1/10-protocol-interface-tcp.mdrequirements exactly
Follow-up Observations
- Tests use real sockets —
socket_create()couples tests to the socket extension and OS networking. Consider extracting aConnectionInterface+ mock pattern in a future milestone. (Low effort, good isolation payoff.) instanceof \Closurecheck — Could be simplified to$this->callback !== nullsince the type hint already guarantees?\Closure. Current approach is defensively safer (protects against edge cases like unserialize corruption), so no action needed — just noting for awareness.- Callback exception propagation —
handle()doesn't catch exceptions from the callback. When the worker loop is implemented, ensure it wraps handler invocations in try/catch to prevent a single misbehaving callback from terminating the worker process. - No test for
ProtocolHandlerInterfacein isolation — Covered implicitly byTcpHandlerTest, but a dedicated interface compliance test (e.g.,ProtocolHandlerInterfaceTestwith a mock implementation) could catch future regressions if the interface changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/Server/Protocol/ProtocolHandlerInterface.phpsrc/Server/Protocol/TcpHandler.phptests/Server/Protocol/TcpHandlerTest.phphandle(Connection): voidmethodClosurecallback; no-op without callback; does NOT close the connectionAcceptance criteria
handle(Connection): voidTcpHandleraccepts optional Closure callbackCloses #12