Skip to content

commit changes#2

Merged
eldadfux merged 1 commit into
mainfrom
dev
Dec 1, 2025
Merged

commit changes#2
eldadfux merged 1 commit into
mainfrom
dev

Conversation

@eldadfux

@eldadfux eldadfux commented Dec 1, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • API Changes

    • Updated condition serialization method from toString() to encode()
    • Updated condition deserialization method from parse() to decode()
  • Documentation

    • Updated README examples to reflect new method names

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request renames two public API methods on the Condition class: toString() becomes encode() and parse() becomes decode(). These method names now reflect encoding/decoding semantics. The changes are reflected across the implementation file (src/Condition.php), test file (tests/ConditionTest.php), and documentation (README.md), with consistent updates to all call sites and examples.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Areas requiring attention:

  • Verify that no additional files outside this diff reference the old method names (parse() or toString())
  • Confirm that README examples correctly demonstrate the new method names and are accurate relative to the implementation
  • Check that test cases comprehensively cover both happy path and error scenarios for encode() and decode()

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'commit changes' is vague and generic, providing no meaningful information about the changeset's primary purpose or content. Use a descriptive title that reflects the main change, such as 'Rename Condition API methods from toString/parse to encode/decode' to clearly communicate the refactoring's intent.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/Condition.php (1)

130-146: API rename is clearer; consider deprecated aliases for BC + docblock tweak

The decode() / encode() names are much clearer than parse() / toString() and the implementations look unchanged. The only concern is potential breakage for existing callers that still use the old methods.

If you expect any external usage of Condition::parse() or $condition->toString(), consider keeping thin, deprecated shims to smooth the transition:

@@
-    /**
-     * Decode a JSON encoded condition string.
-     */
-    public static function decode(string $payload): self
+    /**
+     * Decode a JSON encoded condition string.
+     *
+     * @throws ConditionException
+     */
+    public static function decode(string $payload): self
     {
         try {
             $decoded = \json_decode($payload, true, flags: JSON_THROW_ON_ERROR);
@@
         return self::fromArray($decoded);
     }
+
+    /**
+     * @deprecated Use Condition::decode() instead.
+     */
+    public static function parse(string $payload): self
+    {
+        return self::decode($payload);
+    }
@@
-    /**
-     * Encode condition as JSON string.
-     *
-     * @throws ConditionException
-     */
-    public function encode(): string
+    /**
+     * Encode condition as JSON string.
+     *
+     * @throws ConditionException
+     */
+    public function encode(): string
     {
@@
             throw new ConditionException('Unable to encode condition: ' . $exception->getMessage());
         }
     }
+
+    /**
+     * @deprecated Use encode() instead.
+     */
+    public function toString(): string
+    {
+        return $this->encode();
+    }

If this library is still pre‑1.0 or you explicitly plan a breaking release, you can of course skip the aliases and just keep the @throws annotation addition for decode().

Also applies to: 221-233

tests/ConditionTest.php (1)

184-189: Rename test to reflect decode() rather than parse()

The test body now exercises Condition::decode(), but the method name is still testParseRejectsInvalidJson(), which can be confusing when scanning the suite.

Consider renaming it for clarity:

-    public function testParseRejectsInvalidJson(): void
+    public function testDecodeRejectsInvalidJson(): void
     {
         $this->expectException(ConditionException::class);

-        Condition::decode('{"method":');
+        Condition::decode('{"method":');
     }

Purely cosmetic, but keeps the terminology consistent with the new API.

README.md (1)

69-81: Docs correctly updated to encode/decode; optional terminology alignment

The example and surrounding text now match the encode() / decode() API, which is good. For extra consistency with the earlier bullet that mentions “JSON parsing helpers,” you might want to standardize the phrasing to “JSON encoding/decoding helpers” throughout, but that’s entirely optional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10587a3 and 3dd0724.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • src/Condition.php (2 hunks)
  • tests/ConditionTest.php (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/ConditionTest.php (1)
src/Condition.php (3)
  • encode (226-233)
  • Condition (13-572)
  • decode (133-146)
🔇 Additional comments (1)
tests/ConditionTest.php (1)

155-171: Round‑trip serialization test correctly updated to encode/decode

The round‑trip now goes through Condition::encode() and Condition::decode() and still asserts the same behavior. This keeps the test aligned with the new public API without changing semantics.

@eldadfux eldadfux merged commit 59ba855 into main Dec 1, 2025
7 checks passed
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.

1 participant