Skip to content

add stopsGrowing discount modifier#121

Open
hiqsol wants to merge 1 commit into
masterfrom
stops-growing
Open

add stopsGrowing discount modifier#121
hiqsol wants to merge 1 commit into
masterfrom
stops-growing

Conversation

@hiqsol

@hiqsol hiqsol commented Jun 24, 2026

Copy link
Copy Markdown
Member

stopsGrowing() caps the growth calculation at the given month while the discount continues to apply

Summary by CodeRabbit

  • New Features

    • Added support for stopping discount growth at a specified month while keeping the discount active afterward.
    • Introduced a new fluent option for configuring this cutoff in growing discounts.
  • Documentation

    • Updated the billing docs with a new usage example and clearer explanation of how the cutoff works.
    • Added the new option to the addon reference table.
  • Tests

    • Added coverage for both fixed-amount and percentage-based growing discounts with a growth cutoff.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b277008-bba4-4907-9b37-42adf41baec1

📥 Commits

Reviewing files that changed from the base of the PR and between c77f7bb and 0c6f03d.

📒 Files selected for processing (4)
  • docs/formula-and-modifiers.md
  • src/charge/modifiers/GrowingDiscount.php
  • src/charge/modifiers/addons/StopsGrowing.php
  • tests/behat/GrowingDiscount.feature

📝 Walkthrough

Walkthrough

Adds a stopsGrowing cutoff to GrowingDiscount: a new StopsGrowing addon class (extending Date, implementing AddonInterface) is introduced, GrowingDiscount gains a constant, setter, and getter for it, and countPeriodsPassed() clamps the growth window at the cutoff month. Two Behat scenarios and documentation updates cover the new behavior.

Changes

GrowingDiscount stopsGrowing cutoff

Layer / File(s) Summary
StopsGrowing addon class and GrowingDiscount public API
src/charge/modifiers/addons/StopsGrowing.php, src/charge/modifiers/GrowingDiscount.php
Defines StopsGrowing as a subclass of Date implementing AddonInterface. Adds STOPS_GROWING constant, stopsGrowing($month) setter, and getStopsGrowing(): ?StopsGrowing getter to GrowingDiscount, along with the required import.
countPeriodsPassed() clamping logic
src/charge/modifiers/GrowingDiscount.php
Updates the period calculation to extract sinceTime, optionally cap $time at the StopsGrowing value when it is earlier, clamp the result to sinceTime, and forward the adjusted window to Period::countPeriodsPassed().
Behat scenarios and documentation
tests/behat/GrowingDiscount.feature, docs/formula-and-modifiers.md
Adds two Scenario Outline blocks covering absolute and relative discounts with stopsGrowing(). Extends the docs with the new fluent API example and adds StopsGrowing to the Addon System table.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A discount that grows but knows when to stop,
With stopsGrowing() called, it caps right at the top.
The months keep on ticking, the savings stay capped,
No infinite growth — it's precisely mapped.
Hop hop, little addon, your job here is done! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the new stopsGrowing discount modifier.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch stops-growing

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.

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