Skip to content

Conversation

@VadymHrechukha
Copy link
Collaborator

@VadymHrechukha VadymHrechukha commented Dec 1, 2025

Summary by CodeRabbit

  • Refactor

    • Exception classes now capture metadata in a shared context mechanism instead of per-class private fields.
  • Breaking Changes

    • Several exception accessor methods were removed; related details must be retrieved from the exception context.
  • Chore

    • Static analysis configuration updated with a new root attribute.
  • Style

    • Minor method signature normalization and added PHPDoc generics annotation for a collection class.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

Exception classes were migrated to store domain data in exception context via HasContextInterface/HasContext; several getters/private fields were removed. Also: psalm.xml gained ensureOverrideAttribute, FormulaEngine::__clone lost its return type, and a PHPDoc generic was added to PriceTypeCollection.

Changes

Cohort / File(s) Summary
Exceptions — context migration
src/Exception/ActionChargingException.php, src/Exception/CannotReassignException.php, src/Exception/ChargeOverlappingException.php, src/Exception/ChargeStealingException.php
Each exception now implements HasContextInterface and uses the HasContext trait. Private properties and their getters were removed; constructors/static factories call $this->addContext([...]) to store former property data.
Static analysis config
psalm.xml
Added ensureOverrideAttribute="false" to the root <psalm> element.
Core class signature
src/formula/FormulaEngine.php
Removed the : void return type from public function __clone().
Docblock generics
src/product/Domain/Model/Price/PriceTypeCollection.php
Added @template-implements IteratorAggregate<int, PriceTypeInterface> PHPDoc annotation.
Manifest
composer.json
Listed in manifest section (no code changes described).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify all call sites that previously relied on removed getters now read the data from exception context (confirm exact context key names).
  • Check CannotReassignException context key (field) and related message construction for correctness.
  • Ensure HasContext trait behavior (serialization/logging) matches previous expectations.
  • Run static analysis (psalm) and unit tests to catch signature/docblock mismatches.

Possibly related PRs

Suggested reviewers

  • SilverFire

Poem

"I hop through code and stash a tiny clue,
No bulky getters — context holds the view.
A whisker twitch, a trait to tuck inside,
Neat exceptions now on a comfy ride.
🥕🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main objective of the PR: fixing failing Psalm static analysis in the php-billing package, which aligns with the changes that refactor exception classes to implement HasContextInterface and update method signatures.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba64371 and eda4f0b.

📒 Files selected for processing (2)
  • src/Exception/ChargeStealingException.php (2 hunks)
  • src/product/Domain/Model/Price/PriceTypeCollection.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/product/Domain/Model/Price/PriceTypeCollection.php
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-01-13T12:20:09.570Z
Learnt from: SilverFire
Repo: hiqdev/php-billing PR: 93
File: src/product/BillingRegistry.php:5-5
Timestamp: 2025-01-13T12:20:09.570Z
Learning: The `hiqdev/php-billing` repository should not depend on `advancedhosters/billing-registry`. Use internal interfaces and implementations instead.

Applied to files:

  • src/Exception/ChargeStealingException.php
🧬 Code graph analysis (1)
src/Exception/ChargeStealingException.php (1)
tests/behat/bootstrap/BillingContext.php (1)
  • charge (367-370)
🪛 GitHub Check: PHP 8.3
src/Exception/ChargeStealingException.php

[failure] 30-30: PossiblyUnusedMethod
src/Exception/ChargeStealingException.php:30:28: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\Exception\ChargeStealingException::fromPdoException (see https://psalm.dev/087)

🔇 Additional comments (3)
src/Exception/ChargeStealingException.php (3)

14-15: Context interface/trait imports are consistent and minimal.

Importing HasContext and HasContextInterface here is clean and matches the new context-based exception pattern; no further changes needed.


26-28: Context wiring for ChargeStealingException looks correct.

Implementing HasContextInterface, using HasContext, and pushing the ChargeInterface instance into context via $self->addContext(['charge' => $charge]); is a straightforward, side‑effect‑free replacement for the removed property/getter and should satisfy Psalm about unused fields.

Also applies to: 36-36


30-39: Psalm PossiblyUnusedMethod on fromPdoException still needs an explicit decision.

Psalm reports PossiblyUnusedMethod for fromPdoException. For a library, a public static named constructor can be intentionally unused inside the repo but used by consumers. You probably want to either:

  • Keep it as public API and annotate/suppress for Psalm (e.g., via @psalm-api or a targeted @psalm-suppress PossiblyUnusedMethod), or
  • If it's truly dead, remove it or add an internal call site so the Psalm run is clean.

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/Exception/CannotReassignException.php (1)

22-25: Context-based exception wiring looks good; consider preserving old accessor for BC

The move to a context-based exception (extra interface + trait) looks consistent and doesn’t introduce obvious functional issues. If previous versions exposed a dedicated property/getter for this metadata (e.g., getField()), consider re‑adding a thin accessor that reads from the stored context to avoid breaking external consumers that may still call it.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5716c1 and eedab62.

📒 Files selected for processing (1)
  • src/Exception/CannotReassignException.php (1 hunks)

@VadymHrechukha VadymHrechukha changed the title AHN-131: Fix Failing Psalm Static Analysis in php-billing Composer Package Build HP-2824: Fix Failing Psalm Static Analysis in php-billing Composer Package Build Dec 2, 2025
…d ChargeOverlappingException::getCharge() method
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/Exception/ChargeOverlappingException.php (1)

30-33: Consider preserving the charge reference in context.

The refactoring removed the ability to retrieve the original ChargeInterface object (the previous getCharge() method is gone). While storing serializable data in context is good for logging, consider whether consumers of this exception need access to the full charge object for error handling or recovery logic.

If the charge object is needed by exception handlers, consider adding it to the context:

 $self->addContext([
     'chargeTypeName' => $charge->getType()->getName(),
     'chargeActionTime' => $charge->getAction()->getTime()->format(DATE_ATOM),
+    'charge' => $charge,
 ]);

Alternatively, if only specific charge data is needed, extract and add those specific fields to the context.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eedab62 and 7e537b4.

📒 Files selected for processing (4)
  • psalm.xml (1 hunks)
  • src/Exception/ChargeOverlappingException.php (2 hunks)
  • src/formula/FormulaEngine.php (1 hunks)
  • src/product/Domain/Model/Price/PriceTypeCollection.php (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Psalm Static Analysis
src/Exception/ChargeOverlappingException.php

[error] 23-23: Psalm: PossiblyUnusedMethod - Cannot find any calls to method hiqdev\php\billing\Exception\ChargeOverlappingException::forCharge (see https://psalm.dev/087)

🔇 Additional comments (4)
psalm.xml (1)

17-17: LGTM - Valid Psalm configuration.

The addition of ensureOverrideAttribute="false" is appropriate for disabling enforcement of the #[\Override] attribute, which is necessary if the project is not yet using PHP 8.3 features or if there are legitimate cases where methods override parent/interface methods without the attribute.

src/formula/FormulaEngine.php (1)

235-235: LGTM - Correct __clone signature.

Removing the return type declaration from __clone() is correct. PHP's magic __clone method should not declare a return type, and this change ensures compatibility with PHP's requirements for magic methods.

src/Exception/ChargeOverlappingException.php (2)

23-36: Verify method usage in the codebase.

Psalm reports forCharge() as a possibly unused static factory method. Search the codebase for all calls to ChargeOverlappingException::forCharge() to determine if this method is actively used or represents dead code.


13-14: Verify that hidev\exception\HasContext and hidev\exception\HasContextInterface are available in the hiqdev/hidev package.

The hiqdev/hidev package exists on Packagist, but I could not locate the specific exception classes referenced in the imports through public documentation. Confirm that these classes are present in the package version declared in composer.json and that the dependency is correctly installed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e537b4 and c882c4e.

📒 Files selected for processing (1)
  • src/Exception/ChargeStealingException.php (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-01-13T12:20:09.570Z
Learnt from: SilverFire
Repo: hiqdev/php-billing PR: 93
File: src/product/BillingRegistry.php:5-5
Timestamp: 2025-01-13T12:20:09.570Z
Learning: The `hiqdev/php-billing` repository should not depend on `advancedhosters/billing-registry`. Use internal interfaces and implementations instead.

Applied to files:

  • src/Exception/ChargeStealingException.php
🔇 Additional comments (2)
src/Exception/ChargeStealingException.php (2)

26-28: LGTM! Context pattern implemented correctly.

The integration of HasContextInterface and HasContext trait is implemented correctly, and storing the charge via addContext() aligns with the context-based storage pattern adopted across other exception classes in this PR.

Also applies to: 38-38


14-15: Verify the namespace for HasContext imports.

The imports use hidev\exception\ (without 'q'), which differs from the package's hiqdev\php\billing\ pattern. Confirm whether this is the correct namespace or if it's a typo that would cause class-not-found errors.

@SilverFire SilverFire merged commit 7cccf4b into hiqdev:master Dec 3, 2025
3 of 5 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.

2 participants