From 468c4194f5ac4ef3bc3837a48177f0e1c60ebf50 Mon Sep 17 00:00:00 2001 From: Petr Knap <8299754+petrknap@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:22:14 +0100 Subject: [PATCH] chore: methods `get` and `ifPresentOrElse` marked as not recommended --- README.md | 7 ++++--- src/Optional.php | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c3a3ef2..46e8a1f 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,12 @@ This ensures absolute reliability and alignment with the Java specification. ```php use PetrKnap\Optional\Optional; +// Create string option which holds data $stringOption = Optional::of('data'); -if ($stringOption->isPresent()) { - echo $stringOption->get(); -} +// Print data from string option +echo $stringOption->orElse('missing data'); +// Handle function that returns false on failure Optional::ofFalsable(tmpfile())->ifPresent(function ($tmpFile): void { fwrite($tmpFile, 'data'); fclose($tmpFile); diff --git a/src/Optional.php b/src/Optional.php index c632c3b..eda0078 100644 --- a/src/Optional.php +++ b/src/Optional.php @@ -167,7 +167,7 @@ public function flatMap(callable $mapper): JavaSe8\Optional } /** - * @see self::orElseThrow() - more explicit alternative + * @deprecated Not recommended; use {@see self::orElseThrow()} instead. */ public function get(): mixed { @@ -187,7 +187,7 @@ public function ifPresent(callable $consumer, callable|null $else = null): void } /** - * @see self::ifPresent() - shorter alternative + * @deprecated Not recommended; use {@see self::ifPresent()} instead. */ public function ifPresentOrElse(callable $action, callable $emptyAction): void {