Skip to content

HP-2482/Close_prices_and_notices_for_client_and_reseller #100

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

Conversation

ValeriyShnurovoy
Copy link
Contributor

@ValeriyShnurovoy ValeriyShnurovoy commented Jun 3, 2025

Summary by CodeRabbit

  • New Features

    • Introduced new interfaces to manage billing product behaviors and tariff definitions with enhanced retrieval and behavior-checking methods.
    • Added methods for direct access to tariff definitions by name and verification of specific behaviors on tariff definitions.
  • Tests

    • Added comprehensive tests for behavior retrieval and tariff-related services.
    • Enhanced test coverage for tariff definition lookup and behavior presence validation.

Copy link
Contributor

coderabbitai bot commented Jun 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This change introduces two new interfaces, BillingRegistryBehaviorServiceInterface and BillingRegistryTariffServiseInterface, and refactors the BillingRegistryServiceInterface to extend them. The BillingRegistryService class gains new methods for tariff and behavior management. Tests are reorganized to match the new structure, with new test classes added and redundant tests removed.

Changes

File(s) Change Summary
src/product/Application/BillingRegistryBehaviorServiceInterface.php Added new interface for behavior management methods.
src/product/Application/BillingRegistryTariffServiseInterface.php Added new interface for tariff-related methods.
src/product/Application/BillingRegistryServiceInterface.php Refactored to extend new interfaces and removed now-inherited method declarations.
src/product/Application/BillingRegistryService.php Added getTariffDefinitionByName and hasBehaviour methods.
tests/unit/product/Application/BillingRegistryBehaviorServiceTest.php Added new test class for behavior service functionality.
tests/unit/product/Application/BillingRegistryTariffServiceTest.php Added new test class for tariff service functionality.
tests/unit/product/Application/BillingRegistryServiceTest.php No executable test changes; commented-out test remains inactive.
tests/unit/product/Domain/Model/DummyTariffType.php Added public property $name and updated name() method accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant BillingRegistryService
    participant BillingRegistry
    participant TariffTypeDefinition

    Client->>BillingRegistryService: getTariffDefinitionByName(tariffName)
    BillingRegistryService->>BillingRegistry: getTariffTypeDefinitions()
    BillingRegistry-->>BillingRegistryService: [TariffTypeDefinition...]
    BillingRegistryService->>TariffTypeDefinition: name()
    BillingRegistryService-->>Client: TariffTypeDefinition or null

    Client->>BillingRegistryService: hasBehaviour(tariffDef, behaviorClass)
    BillingRegistryService->>TariffTypeDefinition: hasBehavior(behaviorClass)
    TariffTypeDefinition-->>BillingRegistryService: bool
    BillingRegistryService-->>Client: bool
Loading

Possibly related PRs

Poem

In the meadow of code, new interfaces bloom,
Behaviors and tariffs now each have their room.
Old tests hop away, while new ones appear,
With rabbits inspecting, the logic is clear.
A registry garden, both tidy and bright—
Hop, hop, hooray! The structure feels right.
🐇✨


📜 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 3eac41a and 606ed29.

📒 Files selected for processing (2)
  • src/product/Application/BillingRegistryService.php (1 hunks)
  • tests/unit/product/Application/BillingRegistryServiceTest.php (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 3

🧹 Nitpick comments (4)
src/product/Application/BillingRegistryService.php (1)

62-65: Consider spelling consistency

The method name uses British spelling "Behaviour" while other methods in the codebase use American spelling "Behavior" (e.g., getBehavior, hasBehavior). Consider standardizing the spelling throughout the codebase.

The delegation logic itself is correct.

src/product/Application/BillingRegistryTariffServiseInterface.php (1)

17-17: Consider spelling consistency

The method name hasBehaviour uses British spelling while other parts of the codebase use American spelling "Behavior". Consider standardizing to match the existing codebase conventions.

tests/unit/product/Application/BillingRegistryTariffServiceTest.php (1)

30-59: Extract common setup to reduce code duplication.

Both test methods have nearly identical setup code. Consider extracting the common tariff setup to a helper method to improve maintainability.

+    private function createTariffWithBehavior(string $behaviorName = 'dummy'): TariffTypeDefinition
+    {
+        $tariffType = new DummyTariffType();
+        $tariffTypeDefinition = new TariffTypeDefinition($tariffType);
+        $dummyBehavior = new TestBehavior($behaviorName);
+        $tariffTypeDefinition
+            ->withBehaviors()
+            ->attach($dummyBehavior);
+        
+        $this->registry->addTariffType($tariffTypeDefinition);
+        return $tariffTypeDefinition;
+    }

     public function testGetTariffDefinitionByName(): void
     {
-        $tariffType = new DummyTariffType();
-        $tariffTypeDefinition = new TariffTypeDefinition($tariffType);
-        $dummyBehavior = new TestBehavior('dummy');
-        $tariffTypeDefinition
-            ->withBehaviors()
-            ->attach($dummyBehavior);
-
-        $this->registry->addTariffType($tariffTypeDefinition);
+        $tariffTypeDefinition = $this->createTariffWithBehavior();

         $tariff = $this->registryService->getTariffDefinitionByName('dummy');

-        $this->assertSame($tariffType->name(), $tariff->tariffType()->name());
+        $this->assertSame($tariffTypeDefinition->tariffType()->name(), $tariff->tariffType()->name());
     }

     public function testCheckBehaviorInTariff(): void
     {
-        $tariffType = new DummyTariffType();
-        $tariffTypeDefinition = new TariffTypeDefinition($tariffType);
-        $dummyBehavior = new TestBehavior('dummy');
-        $tariffTypeDefinition
-            ->withBehaviors()
-            ->attach($dummyBehavior);
-
-        $this->registry->addTariffType($tariffTypeDefinition);
+        $this->createTariffWithBehavior();

         $tariff = $this->registryService->getTariffDefinitionByName('dummy');
         $this->assertTrue($this->registryService->hasBehaviour($tariff, TestBehavior::class));
     }
tests/unit/product/Application/BillingRegistryBehaviorServiceTest.php (1)

8-9: Remove unused imports.

The imports AggregateNotFoundException and InvalidRepresentationException appear to be unused in this test class.

-use hiqdev\php\billing\product\Exception\AggregateNotFoundException;
-use hiqdev\php\billing\product\invoice\InvalidRepresentationException;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5343fbe and 3eac41a.

📒 Files selected for processing (8)
  • src/product/Application/BillingRegistryBehaviorServiceInterface.php (1 hunks)
  • src/product/Application/BillingRegistryService.php (1 hunks)
  • src/product/Application/BillingRegistryServiceInterface.php (2 hunks)
  • src/product/Application/BillingRegistryTariffServiseInterface.php (1 hunks)
  • tests/unit/product/Application/BillingRegistryBehaviorServiceTest.php (1 hunks)
  • tests/unit/product/Application/BillingRegistryServiceTest.php (0 hunks)
  • tests/unit/product/Application/BillingRegistryTariffServiceTest.php (1 hunks)
  • tests/unit/product/Domain/Model/DummyTariffType.php (1 hunks)
💤 Files with no reviewable changes (1)
  • tests/unit/product/Application/BillingRegistryServiceTest.php
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/unit/product/Domain/Model/DummyTariffType.php (3)
src/product/Domain/Model/TariffTypeInterface.php (1)
  • name (7-7)
tests/unit/product/Domain/Model/FakeTariffType.php (1)
  • name (7-10)
tests/unit/product/Domain/Model/MockTariffType.php (1)
  • name (7-10)
src/product/Application/BillingRegistryService.php (6)
src/product/Application/BillingRegistryTariffServiseInterface.php (2)
  • getTariffDefinitionByName (15-15)
  • hasBehaviour (17-17)
src/product/BillingRegistryInterface.php (1)
  • getTariffTypeDefinitions (16-16)
src/product/BillingRegistry.php (1)
  • getTariffTypeDefinitions (21-24)
src/product/TariffTypeDefinitionInterface.php (1)
  • tariffType (15-15)
src/product/TariffTypeDefinition.php (2)
  • tariffType (32-35)
  • hasBehavior (86-89)
src/product/price/PriceTypeDefinition.php (1)
  • hasBehavior (164-173)
src/product/Application/BillingRegistryTariffServiseInterface.php (1)
src/product/Application/BillingRegistryService.php (3)
  • findTariffTypeDefinitionByBehavior (160-171)
  • getTariffDefinitionByName (52-60)
  • hasBehaviour (62-65)
src/product/Application/BillingRegistryBehaviorServiceInterface.php (3)
src/product/behavior/BehaviorNotFoundException.php (1)
  • BehaviorNotFoundException (7-9)
src/product/behavior/InvalidBehaviorException.php (1)
  • InvalidBehaviorException (7-9)
src/product/Application/BillingRegistryService.php (3)
  • getBehavior (84-113)
  • getBehaviors (128-145)
  • findPriceTypeDefinitionsByBehavior (173-180)
🔇 Additional comments (5)
tests/unit/product/Domain/Model/DummyTariffType.php (1)

7-11: LGTM: Enhanced test flexibility

The modification to use a configurable $name property instead of a hardcoded string improves the flexibility of this test dummy. This allows for more dynamic test scenarios where different tariff names can be tested.

src/product/Application/BillingRegistryTariffServiseInterface.php (1)

13-15: Method signatures look appropriate

The method signatures correctly define the expected contract for tariff-related operations. The return types and parameter types align with the implementation.

src/product/Application/BillingRegistryBehaviorServiceInterface.php (1)

13-41: Excellent interface design and documentation

This interface demonstrates good design principles:

  • Comprehensive documentation: Clear PHPDoc comments with parameter descriptions, return types, and exception handling
  • Appropriate use of generators: Using Generator return types for methods that yield multiple results promotes memory efficiency
  • Clear separation of concerns: Focused specifically on behavior-related operations
  • Consistent exception handling: Properly documents the exceptions that can be thrown

The interface provides a clean contract for behavior management within the billing registry system.

tests/unit/product/Application/BillingRegistryTariffServiceTest.php (1)

30-44:

✅ Verification successful

Verify test logic - potential name mismatch.

In this test, you're setting a behavior with name 'dummy' but then comparing the tariff type name with the retrieved tariff type name. The behavior name and tariff type name might not be the same, which could lead to a false positive test result.

Please verify that DummyTariffType().name() returns 'dummy' to ensure this assertion is correct:


🏁 Script executed:

#!/bin/bash
# Check the DummyTariffType implementation to verify the name() method
ast-grep --pattern 'class DummyTariffType {
  $$$
  name() {
    $$$
  }
  $$$
}'

Length of output: 83


🏁 Script executed:

#!/bin/bash
# Locate the DummyTariffType implementation to inspect its name() method
rg --color=never -n "class DummyTariffType"

Length of output: 140


🏁 Script executed:

#!/bin/bash
# Inspect the name() method implementation in DummyTariffType
rg --color=never -n "function name" -A3 -B3 tests/unit/product/Domain/Model/DummyTariffType.php

Length of output: 227


Assertion validated – DummyTariffType::name() returns “dummy”.

The test’s assertion comparing $tariffType->name() to the retrieved tariff definition’s name is correct:

  • DummyTariffType::$name is initialized to 'dummy'
  • DummyTariffType::name() returns this value

No changes required.

tests/unit/product/Application/BillingRegistryBehaviorServiceTest.php (1)

30-128: Excellent test coverage for behavior service functionality.

The test methods provide comprehensive coverage of the behavior retrieval functionality:

  • Basic behavior retrieval
  • Multiple behaviors and price types within a single tariff
  • Multiple tariff definitions with different behaviors
  • Proper exception handling for non-existent behaviors

The test scenarios are well-designed and follow good testing practices with proper setup, execution, and assertions.

Comment on lines +52 to +60
public function getTariffDefinitionByName(string $tariffName): ?TariffTypeDefinitionInterface
{
foreach ($this->registry->getTariffTypeDefinitions() as $tariffTypeDefinition) {
if ($tariffName === $tariffTypeDefinition->tariffType()->name) {
return $tariffTypeDefinition;
}
}
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bug: Missing method call parentheses

The comparison on line 55 is accessing name as a property instead of calling the name() method. Based on the TariffTypeInterface (line 7), name() is a method that should be called.

-            if ($tariffName === $tariffTypeDefinition->tariffType()->name) {
+            if ($tariffName === $tariffTypeDefinition->tariffType()->name()) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function getTariffDefinitionByName(string $tariffName): ?TariffTypeDefinitionInterface
{
foreach ($this->registry->getTariffTypeDefinitions() as $tariffTypeDefinition) {
if ($tariffName === $tariffTypeDefinition->tariffType()->name) {
return $tariffTypeDefinition;
}
}
return null;
}
public function getTariffDefinitionByName(string $tariffName): ?TariffTypeDefinitionInterface
{
foreach ($this->registry->getTariffTypeDefinitions() as $tariffTypeDefinition) {
if ($tariffName === $tariffTypeDefinition->tariffType()->name()) {
return $tariffTypeDefinition;
}
}
return null;
}
🤖 Prompt for AI Agents
In src/product/Application/BillingRegistryService.php lines 52 to 60, the code
incorrectly accesses the name as a property on line 55. Replace the property
access with a method call by changing
`$tariffTypeDefinition->tariffType()->name` to
`$tariffTypeDefinition->tariffType()->name()`. This ensures the name() method is
properly invoked as defined in the TariffTypeInterface.

use hiqdev\php\billing\product\behavior\BehaviorInterface;
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;

interface BillingRegistryTariffServiseInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Fix typo in interface name

The interface name contains a typo: "BillingRegistryTariffServiseInterface" should be "BillingRegistryTariffServiceInterface" (missing 'c' in "Service").

-interface BillingRegistryTariffServiseInterface
+interface BillingRegistryTariffServiceInterface

This typo will need to be corrected everywhere this interface is referenced.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
interface BillingRegistryTariffServiseInterface
-interface BillingRegistryTariffServiseInterface
+interface BillingRegistryTariffServiceInterface
🤖 Prompt for AI Agents
In src/product/Application/BillingRegistryTariffServiseInterface.php at line 10,
correct the typo in the interface name from
"BillingRegistryTariffServiseInterface" to
"BillingRegistryTariffServiceInterface" by adding the missing 'c'. Then, update
all references to this interface throughout the codebase to use the corrected
name to ensure consistency and avoid errors.

@@ -13,7 +13,7 @@
use hiqdev\php\billing\product\quantity\QuantityFormatterInterface;
use hiqdev\php\billing\product\TariffTypeDefinitionInterface;

interface BillingRegistryServiceInterface
interface BillingRegistryServiceInterface extends BillingRegistryTariffServiseInterface, BillingRegistryBehaviorServiceInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in interface name.

There's a typo in the interface name: BillingRegistryTariffServiseInterface should be BillingRegistryTariffServiceInterface (missing 'c' in "Service").

-interface BillingRegistryServiceInterface extends BillingRegistryTariffServiseInterface, BillingRegistryBehaviorServiceInterface
+interface BillingRegistryServiceInterface extends BillingRegistryTariffServiceInterface, BillingRegistryBehaviorServiceInterface
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
interface BillingRegistryServiceInterface extends BillingRegistryTariffServiseInterface, BillingRegistryBehaviorServiceInterface
interface BillingRegistryServiceInterface extends BillingRegistryTariffServiceInterface, BillingRegistryBehaviorServiceInterface
🤖 Prompt for AI Agents
In src/product/Application/BillingRegistryServiceInterface.php at line 16, fix
the typo in the interface name by changing BillingRegistryTariffServiseInterface
to BillingRegistryTariffServiceInterface, adding the missing 'c' in "Service".

@SilverFire SilverFire merged commit 277995a into hiqdev:master Jun 6, 2025
2 of 4 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