Skip to content

HP-2116: Run pipelines on php-billing repo#77

Merged
SilverFire merged 80 commits intohiqdev:masterfrom
VadymHrechukha:HP-2116_run_pipelines_on_php-billing_repo
Oct 1, 2024
Merged

HP-2116: Run pipelines on php-billing repo#77
SilverFire merged 80 commits intohiqdev:masterfrom
VadymHrechukha:HP-2116_run_pipelines_on_php-billing_repo

Conversation

@VadymHrechukha
Copy link
Copy Markdown
Collaborator

@VadymHrechukha VadymHrechukha commented Sep 17, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced testing environments by updating PHP versions to include 8.3, improving compatibility and functionality.
    • Added detailed code coverage reports and integration with external services for better visibility into code quality.
  • Bug Fixes

    • Improved performance and security of the application by updating the required PHP version and PHPUnit.
  • Chores

    • Updated the required PHP version to 8.3 in configuration files, allowing access to new features and improvements.
    • Updated Composer and testing configurations to ensure the latest standards are met.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

The changes involve an update to the PHP version specified in the GitHub Actions workflows for running PHPUnit tests, changing from PHP 8.1 to PHP 8.3. The PHPUnit command has been modified to include options for generating code coverage reports. Additionally, new steps have been added to archive code coverage results using Codecov and to upload code coverage data to Scrutinizer. Overall, these updates enhance the testing process and integration with external services.

Changes

Files Change Summary
.github/workflows/phpunit-tests.yml Updated PHP version from 8.1 to 8.3 in the job matrix for PHPUnit tests; added coverage options and steps for Codecov and Scrutinizer.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHubActions
    participant PHPUnit
    participant Codecov
    participant Scrutinizer

    Developer->>GitHubActions: Push changes
    GitHubActions->>PHPUnit: Run tests on PHP 8.3
    PHPUnit->>GitHubActions: Return test results
    GitHubActions->>Codecov: Archive coverage results
    GitHubActions->>Scrutinizer: Upload coverage data
    GitHubActions-->>Developer: Send results
Loading

🐇 "In fields of code, we hop with glee,
PHP 8.3, oh what a spree!
Tests now run with a joyful cheer,
New features bloom, the path is clear.
With every change, we leap and bound,
In the world of code, joy is found!" 🐇


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7371905 and dd4553d.

Files selected for processing (1)
  • .github/workflows/phpunit-tests.yml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/phpunit-tests.yml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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.
    -- Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    -- @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 generate unit testing code.
    -- @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.

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 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
Copy Markdown
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

Outside diff range and nitpick comments (1)
.github/workflows/phpunit-tests.yml (1)

14-14: Approve the PHP version update with additional considerations.

Updating the PHP version to 8.3 in the test environment is a good change as it ensures the codebase is tested against the latest stable PHP version. PHP 8.3 introduces new features and improvements that could enhance the codebase.

However, please consider the following:

  • Thoroughly test the codebase with PHP 8.3 to ensure there are no breaking changes or unexpected behavior.
  • Update the development environment and production servers to PHP 8.3 to maintain consistency across all environments.
  • Update the PHP version in other relevant configuration files such as composer.json, Dockerfile, etc.
  • Communicate the PHP version update to the team and update the relevant documentation.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 373e60f and c4ae34e.

Files selected for processing (3)
  • .github/workflows/behat-tests.yml (1 hunks)
  • .github/workflows/phpunit-tests.yml (1 hunks)
  • composer.json (1 hunks)
Additional comments not posted (1)
composer.json (1)

46-46: Verify compatibility and update CI/CD pipeline.

Updating the required PHP version to ^8.3 aligns the project with the latest PHP standards and capabilities. However, please ensure that:

  1. All other dependencies in the project are compatible with PHP 8.3.
  2. The CI/CD pipeline is updated to use PHP 8.3 for testing and deployment.

Run the following script to verify the compatibility and CI/CD pipeline:

Verification successful

PHP 8.3 upgrade correctly implemented, but update testing tools

The PHP 8.3 requirement has been correctly updated in composer.json, and no conflicting PHP version requirements were found in other files. However, to ensure full compatibility:

  1. Update Behat, PHPUnit, PHPStan, and Psalm to their latest versions that support PHP 8.3.
  2. Run your test suite and static analysis tools with PHP 8.3 to catch any potential compatibility issues.
  3. If you have a custom build or CI process, ensure it uses PHP 8.3 for all stages (build, test, static analysis).
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify compatibility and CI/CD pipeline for PHP 8.3 upgrade.

# Test 1: Check if any other dependency in the `composer.json` file requires a PHP version lower than 8.3.
# Expect: No dependencies requiring PHP version lower than 8.3.
rg --type json $'"php":\s*"\^[0-7]\.[0-9]"' -g 'composer.json'

# Test 2: Check if the CI/CD pipeline configuration files use PHP 8.3 for testing and deployment.
# Expect: All pipeline configurations use PHP 8.3.
rg --type yaml $'php:\s*[\'"]?8\.3' -g '.github/workflows/*.yml'
rg --type yaml $'php:\s*[\'"]?8\.3' -g '.travis.yml'
rg --type yaml $'php:\s*[\'"]?8\.3' -g '.circleci/config.yml'
rg --type yaml $'php:\s*[\'"]?8\.3' -g 'bitbucket-pipelines.yml'
rg --type yaml $'php:\s*[\'"]?8\.3' -g 'azure-pipelines.yml'

Length of output: 970


Script:

#!/bin/bash

# 1. Verify the existence and content of composer.json
echo "=== composer.json content ==="
cat composer.json

# 2. List existing CI/CD configuration files
echo -e "\n=== Existing CI/CD configuration files ==="
fd -e yml -e yaml

# 3. Check the content of existing CI/CD files for any PHP version specifications
echo -e "\n=== PHP versions in CI/CD files ==="
fd -e yml -e yaml -x grep -H -i 'php:' {} +

Length of output: 3308


Script:

#!/bin/bash

# Check content of behat.yml and hidev.yml for PHP version specifications
echo "=== Content of behat.yml ==="
cat behat.yml
echo -e "\n=== Content of hidev.yml ==="
cat hidev.yml

# Search for any files containing CI/CD related keywords
echo -e "\n=== Files potentially related to CI/CD ==="
fd -t f | xargs grep -l -i -E 'ci|cd|test|build|deploy'

# Search for PHP version specifications in all files
echo -e "\n=== PHP version specifications in all files ==="
fd -t f | xargs grep -H -i 'php:' || echo "No PHP version specifications found"

Length of output: 4358

strategy:
matrix:
php: ['8.1']
php: ['8.3']
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.

Verify PHP 8.3 compatibility before updating the version.

Updating the PHP version from 8.1 to 8.3 in the job matrix can potentially impact the compatibility and functionality of the tests being executed. PHP 8.3 may introduce new features, deprecations, or changes in behavior that could affect the codebase and its dependencies.

Before merging this change, please ensure that:

  1. The codebase is compatible with PHP 8.3 and does not rely on PHP 8.1 specific features.
  2. All dependencies are compatible with PHP 8.3. Update the dependencies if necessary.
  3. The tests pass successfully with PHP 8.3.

If the codebase requires significant changes to be compatible with PHP 8.3, consider a phased approach to update the PHP version. You can start by adding PHP 8.3 to the test matrix alongside PHP 8.1 to identify and fix compatibility issues gradually.

- php: ['8.3']
+ php: ['8.1', '8.3']

Once the codebase and dependencies are fully compatible with PHP 8.3, you can remove PHP 8.1 from the matrix.

Committable suggestion was skipped due to low confidence.

…sts\unit\order\CalculatorTest::testCalculateCharges() must be compatible with hiqdev\php\billing\tests\unit\plan\PlanTest::testCalculateCharges(): void in /home/runner/work/php-billing/php-billing/tests/unit/order/CalculatorTest.php on line 57' error
@SilverFire
Copy link
Copy Markdown
Member

Thank you. Could you fix Scrutinizer job as well, please?

Copy link
Copy Markdown
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: 0

Outside diff range and nitpick comments (1)
src/price/Sums.php (1)

9-11: Please clarify the purpose of the $values parameter and update the documentation.

The comments indicate that the purpose of the $values parameter in the constructor is unclear. It would be helpful to provide more context on what the quantities and sums represent.

Consider updating the documentation to clearly explain the meaning of the $values parameter and how it is used within the class.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2a4b521 and 66e981a.

Files selected for processing (2)
  • src/price/Sums.php (2 hunks)
  • tests/support/plan/CertificatePlan.php (1 hunks)
Additional comments not posted (2)
src/price/Sums.php (1)

36-39: LGTM!

The new getSum(int $quantity) method provides a convenient way to retrieve the sum for a specific quantity. The implementation is clear and concise, using the null coalescing operator to handle cases where the quantity does not exist in the $values array.

The addition of this method enhances the functionality of the Sums class and improves its usability.

tests/support/plan/CertificatePlan.php (1)

111-114: LGTM!

The changes in the getRawPrice method look good:

  • Renaming $years to $quantity improves clarity without affecting functionality.
  • Using getSum($quantity) instead of directly indexing into the raw prices array allows for more flexible price retrieval based on the quantity.

The changes align with the provided summary and do not introduce any apparent issues or inconsistencies.

…dons\DayPeriod::addTo has wrong name $since' Psalm error
…v\DataMapper\Query\Specification does not exist' Psalm error
…: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error
…: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error
…on depends on class or interface hiapi\exceptions\hiapiexception' Psalm error
…: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error
…plan\Plan::setParentId has wrong name $id, expecting $parentId' Psalm error
…price\SinglePrice::calculatePrice has wrong name $usage, expecting $quantity' Psalm error
…le: $actionKey is never referenced or the value is not used' Psalm error
Copy link
Copy Markdown
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: 0

Outside diff range and nitpick comments (1)
src/price/SinglePrice.php (1)

66-66: LGTM!

The change in the method signature does not introduce any issues and the functionality remains unaffected.

Consider renaming the method to better align with its functionality. For example, getPrice() might be more appropriate since the method always returns the same price regardless of the input quantity.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 633210c and b828397.

Files selected for processing (7)
  • composer.json (2 hunks)
  • src/order/Calculator.php (4 hunks)
  • src/plan/Plan.php (1 hunks)
  • src/price/PriceInvalidArgumentException.php (1 hunks)
  • src/price/PriceWithSubpriceInterface.php (0 hunks)
  • src/price/SinglePrice.php (1 hunks)
  • src/sale/SaleRepositoryInterface.php (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • src/price/PriceWithSubpriceInterface.php
Files skipped from review as they are similar to previous changes (1)
  • composer.json
Additional comments not posted (7)
src/price/PriceInvalidArgumentException.php (1)

5-5: Verify the impact of changing the base exception class.

The PriceInvalidArgumentException class now extends RuntimeException instead of HiapiException. This change in the base exception class could potentially affect exception handling logic in other parts of the codebase.

Please run the following script to verify the usage of PriceInvalidArgumentException and HiapiException across the codebase:

Review the results to ensure that:

  1. Exception handling code is updated to catch RuntimeException instead of HiapiException where PriceInvalidArgumentException is used.
  2. Any specific functionality or properties of HiapiException that were being used with PriceInvalidArgumentException are refactored appropriately.

If you find any inconsistencies or areas that need updating, please let me know, and I'll be happy to suggest the necessary changes.

Also applies to: 7-7

Verification successful

Change to RuntimeException appears to have minimal impact

The switch from HiapiException to RuntimeException as the base class for PriceInvalidArgumentException seems to have minimal impact on the codebase. The exception is used in src/price/Sums.php and src/price/SumsHydrator.php, but only for throwing, not catching. No usage of HiapiException was found.

While this change simplifies the exception hierarchy, please verify:

  • Any global exception handling that might have been catching HiapiException (if it existed) is updated to handle RuntimeException if necessary.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

echo "Searching for usage of PriceInvalidArgumentException..."
rg --type php -w 'PriceInvalidArgumentException' -A 5

echo "Searching for usage of HiapiException..."
rg --type php -w 'HiapiException' -A 5

Length of output: 1077

src/sale/SaleRepositoryInterface.php (1)

37-37: Verify the impact of the return type change.

The return type annotation change from PlanInterface[] to SaleInterface[] improves code clarity and consistency within the SaleRepositoryInterface.

Please ensure that:

  1. Existing implementations of this interface are updated to return SaleInterface objects.
  2. Dependent code that relies on the returned PlanInterface objects is refactored to handle SaleInterface objects.

Run the following script to verify the impact:

Verification successful

To gather more information about the implementation details and potential impacts, let's run the following scripts:


Return type change is verified and approved.

The return type annotation change from PlanInterface[] to SaleInterface[] in SaleRepositoryInterface::findByOrder has been successfully implemented and its impact has been verified. Here are the key findings:

  1. The SimpleSaleRepository implementation is compatible with the new return type, as it returns an array of sales without explicit type hints.
  2. The Calculator class, which uses findByOrder, remains compatible as it treats the result as an iterable without type-checking.
  3. The docblock in SaleRepositoryInterface has been correctly updated to reflect the new return type.
  4. No code changes are required in the existing implementation due to the absence of explicit return type hints.

Note: The SimplePlanRepository and PlanRepositoryInterface are separate from SaleRepositoryInterface and are not affected by this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the return type change in `SaleRepositoryInterface::findByOrder`.

# Test 1: Search for implementations of the `SaleRepositoryInterface`. 
# Expect: Implementations should return `SaleInterface` objects.
rg --type php -A 5 $'implements SaleRepositoryInterface'

# Test 2: Search for usages of the `findByOrder` method.
# Expect: Dependent code should handle `SaleInterface` objects.
rg --type php -A 5 $'findByOrder'

Length of output: 2737


Script:

#!/bin/bash
# Description: Check implementation details and potential impacts of the return type change

# Check the implementation of SimpleSaleRepository::findByOrder
echo "Checking SimpleSaleRepository::findByOrder implementation:"
rg --type php -A 10 "public function findByOrder" tests/support/sale/SimpleSaleRepository.php

# Check if SimplePlanRepository implements SaleRepositoryInterface
echo "\nChecking if SimplePlanRepository implements SaleRepositoryInterface:"
rg --type php "class SimplePlanRepository" tests/support/plan/SimplePlanRepository.php

# Check for type hints or docblocks in findByOrder implementations and usages
echo "\nChecking for type hints or docblocks in findByOrder implementations and usages:"
rg --type php -A 5 -B 3 "function findByOrder|->findByOrder"

Length of output: 4316

src/plan/Plan.php (1)

112-114: LGTM!

The parameter name change from $id to $parentId enhances code readability by clearly indicating the purpose of the parameter. The functionality of the method remains unchanged.

src/order/Calculator.php (4)

64-69: LGTM!

The simplification of the condition checking for the existence of plans associated with actions improves readability and maintains the correct logic. The error handling remains intact, ensuring that exceptions are thrown for any issues encountered during the calculation of plans.


156-158: LGTM!

Explicitly defining the return type as an array in the method signature of findPlans enhances type clarity and improves the code's readability and maintainability.


Line range hint 164-182: LGTM!

The adjustment to the logic in the findPlans method simplifies the code and improves readability. By directly checking for non-empty sales instead of comparing against false, the assignment of null to plans when no sales are found becomes more straightforward and easier to understand. The updated comments also provide better clarity and context.


203-206: LGTM!

Explicitly defining the return type as an array in the method signature of findSales enhances type clarity and improves the code's readability and maintainability.

@VadymHrechukha
Copy link
Copy Markdown
Collaborator Author

VadymHrechukha commented Sep 20, 2024

I replaced Scrutinizer with Psalm and fixed all the errors that occurred. After that, I removed the .scrutinizer.yml file, but Scrutinizer keeps launching.
@SilverFire, how can I completely remove Scrutinizer from the php-billing repository?

Comment on lines +9 to +11
* Quantity of what?
* Sum of what?
* If you know answers please write in the comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Quantity of what?

Of the action being charges

Sum of what?

Amount for this given Quantity

If used to denote bulk prices.
E.g. when you buy an SSL certificate for 1 year – it costs 10$
But for 2 years you pay 15$.

It is stored as

[ 1 => 10, 2 => 15 ]

Comment on lines +150 to +153
* What purpose of this method? Because it looks like duplicate of PriceHydrator::extract()
* Where we are using the result of this method?
* Magic calls can't be determined and I don't know what can be broken if we change the method result.
* Which structure must have the result, because array can contain anything?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What purpose of this method? Because it looks like duplicate of PriceHydrator::extract()

PriceHydrator::extract() is highly-bound to HiAPI context and public API. This method provides a naive way to encode all the properties.

Where we are using the result of this method?

I can not remember the use cases. Maybe is not used at all not.

Add a logging statement with the stacktace, run tests and see when this method is being called.

@SilverFire
Copy link
Copy Markdown
Member

Remove the Scrutinizer workflow, please

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