Skip to content

Implemented JavaSe10\Optional - #61

Merged
petrknap merged 1 commit into
mainfrom
java-bump
Oct 30, 2026
Merged

petrknap merged 1 commit into
mainfrom
java-bump

Conversation

@petrknap

@petrknap petrknap commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner
  • This pull request does not contain any breaking change.
  • I asked the AI to briefly summarize, use and improve the feature(s), and I'm okay with the output:

This pull request introduces support for Java SE 10 and Java SE 16 specifications into the PHP Optional library. Specifically, it:

  1. Adds JavaSe10\Optional interface containing the parameterless orElseThrow() method (which throws a NoSuchElementException by default).
  2. Adds JavaSe16\Optional test harness and support for record-based equality checks.
  3. Refactors the test setup (JavaSe8, JavaSe9, JavaSe10, JavaSe16) to use a clean matrix strategy in GitHub Actions (.github/workflows/java-test.yaml) and separates Java-to-PHP test translations cleanly.
  4. Updates README.md to reference the new Java SE 10 and 16 compliance test suites.

Detailed Code Review

1. Interface Evolution (src/JavaSe10/Optional.php)

  • Addition: Introduces JavaSe10\Optional extending JavaSe9\Optional.
  • Signature: public function orElseThrow(?callable $exceptionSupplier = null): mixed;
  • PHPStan / Generics: The return type and conditional exception throwing are correctly documented using PHPStan templates and conditional throw types (@throws ($exceptionSupplier is null ? JavaSe8\NoSuchElementException : E)), matching the implementation already present in base Optional.

2. Test Suite & Java Compatibility Layer

  • Java SE 10 Tests (tests/JavaSe10/OptionalTest.java): Properly tests parameterless orElseThrow() behavior for both present options and empty options.
  • Java SE 16 & Records (tests/JavaSe16/OptionalTest.java & Record.php): Moves record-equality testing out of Java SE 8 (where records didn't exist natively) into the appropriate Java SE 16 context, maintaining accurate parity with Java's specification.
  • CI Workflow (.github/workflows/java-test.yaml): Upgraded to actions/setup-java@v5 using Amazon Corretto across a matrix of Java versions (SE 8, 9, 10, and 16 mapped to appropriate LTS runtimes). This ensures robust verification against multiple Java target standards.

3. Documentation & Readme

  • README.md: Updated to point to the new Java SE 10 and SE 16 test files, keeping documentation transparent about compliance targets.

Recommendation

  • Status: Approve ✅
  • Reasoning: The changes are clean, strictly adhere to the project's goal of mirroring Java's Optional specifications across different language versions, improve the test architecture modularity, and pass all type-checking and structural conventions established in the library.

@petrknap petrknap self-assigned this Oct 29, 2026
@petrknap petrknap added the enhancement New feature or request label Oct 29, 2026
@petrknap
petrknap force-pushed the java-bump branch 3 times, most recently from 8701990 to 70b8770 Compare October 30, 2026 16:45
@petrknap
petrknap marked this pull request as ready for review October 30, 2026 16:51
@petrknap
petrknap merged commit 0c7b064 into main Oct 30, 2026
6 checks passed
@petrknap
petrknap deleted the java-bump branch October 30, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant