-
Notifications
You must be signed in to change notification settings - Fork 12
Adding Bill::usageInterval() #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||||||||||||
| namespace hiqdev\php\billing\bill; | ||||||||||||||||
|
|
||||||||||||||||
| use DateTimeImmutable; | ||||||||||||||||
| use hiqdev\php\billing\action\UsageInterval; | ||||||||||||||||
| use hiqdev\php\billing\charge\ChargeInterface; | ||||||||||||||||
| use hiqdev\php\billing\customer\CustomerInterface; | ||||||||||||||||
| use hiqdev\php\billing\Exception\CannotReassignException; | ||||||||||||||||
|
|
@@ -63,6 +64,9 @@ class Bill implements BillInterface | |||||||||||||||
| /** @var string */ | ||||||||||||||||
| protected $comment; | ||||||||||||||||
|
|
||||||||||||||||
| /** @var UsageInterval */ | ||||||||||||||||
| protected $usageInterval; | ||||||||||||||||
|
|
||||||||||||||||
| public function __construct( | ||||||||||||||||
| $id, | ||||||||||||||||
| TypeInterface $type, | ||||||||||||||||
|
|
@@ -85,6 +89,7 @@ public function __construct( | |||||||||||||||
| $this->plan = $plan; | ||||||||||||||||
| $this->charges = $charges; | ||||||||||||||||
| $this->state = $state; | ||||||||||||||||
| $this->setUsageInterval(UsageInterval::wholeMonth($time)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
|
|
@@ -104,6 +109,10 @@ public function getUniqueString(): string | |||||||||||||||
| return implode('-', $parts); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public function getUsageInterval(): UsageInterval | ||||||||||||||||
| { | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+112
to
+114
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Implement getUsageInterval() method. The method is empty and needs to be implemented. Based on the standard getter pattern in this class, it should return the protected $usageInterval property. public function getUsageInterval(): UsageInterval
{
+ return $this->usageInterval;
}📝 Committable suggestion
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing implementation |
||||||||||||||||
|
|
||||||||||||||||
| public function calculatePrice() | ||||||||||||||||
| { | ||||||||||||||||
| $quantity = $this->quantity->getQuantity(); | ||||||||||||||||
|
|
@@ -233,4 +242,9 @@ public function jsonSerialize(): array | |||||||||||||||
| { | ||||||||||||||||
| return array_filter(get_object_vars($this)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public function setUsageInterval(UsageInterval $usageInterval): void | ||||||||||||||||
| { | ||||||||||||||||
| $this->usageInterval = $usageInterval; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| namespace hiqdev\php\billing\bill; | ||
|
|
||
| use DateTimeImmutable; | ||
| use hiqdev\php\billing\action\UsageInterval; | ||
| use hiqdev\php\billing\charge\ChargeInterface; | ||
| use hiqdev\php\billing\customer\CustomerInterface; | ||
| use hiqdev\php\billing\EntityInterface; | ||
|
|
@@ -50,4 +51,8 @@ public function getPlan(): ?PlanInterface; | |
| * @return ChargeInterface[] | ||
| */ | ||
| public function getCharges(); | ||
|
|
||
| public function getUsageInterval(): UsageInterval; | ||
|
|
||
| public function setUsageInterval(UsageInterval $usageInterval): void; | ||
|
Comment on lines
+55
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Implementation of The verification revealed:
🔗 Analysis chainVerify interface implementation in all concrete classes. The addition of new interface methods requires updates to all implementing classes. Let's verify the implementation: Let me gather more information about the implementation details in the identified files. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Find all PHP files that might implement BillInterface
echo "Searching for potential BillInterface implementations..."
rg -l "implements.*BillInterface" --type php
# Look for classes that have the new methods
echo -e "\nChecking for getUsageInterval implementation..."
ast-grep --pattern 'class $_ {
$$$
getUsageInterval(): UsageInterval {
$$$
}
$$$
}'
echo -e "\nChecking for setUsageInterval implementation..."
ast-grep --pattern 'class $_ {
$$$
setUsageInterval($_): void {
$$$
}
$$$
}'
Length of output: 630 Script: #!/bin/bash
# Check the content of both implementing classes
echo "Content of src/bill/Bill.php:"
cat src/bill/Bill.php
echo -e "\nContent of src/statement/StatementBill.php:"
cat src/statement/StatementBill.php
Length of output: 8788 |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation to prevent invalid interval combinations.
The
extend()method implementation looks correct for combining intervals, but could benefit from additional validation to prevent edge cases.Consider adding validation checks:
public function extend(self $other): self { + $newStart = min($this->start, $other->start); + $newEnd = max($this->end, $other->end); + + if ($newStart > $newEnd) { + throw new InvalidArgumentException('Cannot extend intervals: resulting interval would be invalid'); + } + return new self( - min($this->start, $other->start), - max($this->end, $other->end), + $newStart, + $newEnd, ); }📝 Committable suggestion