Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c4ae34e
HP-2116: Run pipelines on php-billing repo
VadymHrechukha Sep 17, 2024
65767c9
HP-2116: fixed 'PHP Fatal error: Declaration of hiqdev\php\billing\t…
VadymHrechukha Sep 17, 2024
cbf7ce4
HP-2116: fixing falling build
VadymHrechukha Sep 17, 2024
11a8e59
HP-2116: added PHP 8.3 to the test matrix alongside PHP 8.1 in Behat …
VadymHrechukha Sep 17, 2024
754558a
HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutin…
VadymHrechukha Sep 19, 2024
4ac68f0
Merge branch 'master' into HP-2116_run_pipelines_on_php-billing_repo
VadymHrechukha Sep 19, 2024
c03f134
HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutin…
VadymHrechukha Sep 19, 2024
aa7ae10
HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutin…
VadymHrechukha Sep 19, 2024
cea59ee
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
b032170
HP-2116: Use a Public PHP 8.3 Docker Image in Scrutinizer
VadymHrechukha Sep 19, 2024
c4a1bd1
HP-2116: Use a Public PHP 8.3 Docker Image in Scrutinizer
VadymHrechukha Sep 19, 2024
855c542
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
a8d68b6
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
2a4b521
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
66e981a
HP-2116: fixed CertificatePlan::getRawPrice() method
VadymHrechukha Sep 19, 2024
b964efa
HP-2116: fixed AggregatorTest
VadymHrechukha Sep 19, 2024
dfb3961
HP-2116: fixing "PHP Deprecated" for TypeTest in CI pipeline
VadymHrechukha Sep 19, 2024
190be29
HP-2116: fixing "PHP Deprecated" for FixedDiscountTest in CI pipeline
VadymHrechukha Sep 19, 2024
31899db
HP-2116: fixing "PHP Deprecated" for ModifierTest in CI pipeline
VadymHrechukha Sep 19, 2024
17eb0ba
HP-2116: fixing "PHP Deprecated" for PriceFactoryTest in CI pipeline
VadymHrechukha Sep 19, 2024
3f7342e
HP-2116: fixing "PHP Deprecated" for SinglePriceTest in CI pipeline
VadymHrechukha Sep 19, 2024
39a3ec6
HP-2116: fixing "PHP Deprecated" for SaleTest in CI pipeline
VadymHrechukha Sep 19, 2024
d584450
HP-2116: fixing "PHP Deprecated" for TargetTest in CI pipeline
VadymHrechukha Sep 19, 2024
8087a36
HP-2116: fixing "PHP Deprecated" for PlanTest in CI pipeline
VadymHrechukha Sep 19, 2024
b065614
HP-2116: fixing "PHP Deprecated" for FactoryTest in CI pipeline
VadymHrechukha Sep 19, 2024
b43736d
HP-2116: fixing "PHP Deprecated" for TypeTest in CI pipeline
VadymHrechukha Sep 19, 2024
2e713a1
HP-2116: exclude the vendor directory from testing using the --exclud…
VadymHrechukha Sep 19, 2024
92de32f
HP-2116: The vendor/ directory is excluded from code coverage calcula…
VadymHrechukha Sep 19, 2024
e0fa4e9
HP-2116: Exclude vendor directory to ignore warnings from third-party…
VadymHrechukha Sep 19, 2024
1bc51c4
HP-2116: use <coverage> instead of <filter> to manage which parts of …
VadymHrechukha Sep 19, 2024
0270de6
HP-2116: Updated PHPUnit from 8.5.39 to 10 version
VadymHrechukha Sep 19, 2024
df10864
HP-2116: Updated PHPUnit from 8.5.39 to 10 version
VadymHrechukha Sep 19, 2024
970a4d0
HP-2116: Fixed 'Option "--exclude" is ambiguous' error
VadymHrechukha Sep 19, 2024
e1cc8f9
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
fff1f37
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
4439a57
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 19, 2024
ba283ef
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 20, 2024
a7a7e2c
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 20, 2024
0fc4e65
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 20, 2024
5aa527f
HP-2116: Configuring PHP8.3 on Scrutinizer
VadymHrechukha Sep 20, 2024
d89ddf0
HP-2116: Created GitHub Actions .yml file that runs Psalm for static …
VadymHrechukha Sep 20, 2024
2e5a115
HP-2116: Created GitHub Actions .yml file that runs Psalm for static …
VadymHrechukha Sep 20, 2024
92aa162
HP-2116: fixing psalm plugin
VadymHrechukha Sep 20, 2024
2b055fe
HP-2116: fixing errors in psalm file
VadymHrechukha Sep 20, 2024
e0836b5
HP-2116: testing psalm config
VadymHrechukha Sep 20, 2024
b3116a2
HP-2116: deleted scrutinizer
VadymHrechukha Sep 20, 2024
f29071b
HP-2116: rollback changes in AbstractPrice::jsonSerialize() method be…
VadymHrechukha Sep 20, 2024
44ba82e
HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\…
VadymHrechukha Sep 20, 2024
fdeda2c
HP-2116: fixing 'UnusedVariable: $integer is never referenced or the …
VadymHrechukha Sep 20, 2024
dff9001
HP-2116: fixing 'UnnecessaryVarAnnotation: The @var hiqdev\php\billin…
VadymHrechukha Sep 20, 2024
f4e55ee
HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\…
VadymHrechukha Sep 20, 2024
589a094
HP-2116: fixing 'UndefinedClass: Class' Psalm error
VadymHrechukha Sep 20, 2024
d4a4228
HP-2116: fixing 'UndefinedClass: Class' Psalm error
VadymHrechukha Sep 20, 2024
775d91a
HP-2116: fixing 'UndefinedClass: Class' Psalm error
VadymHrechukha Sep 20, 2024
05dc273
HP-2116: fixing 'UndefinedClass: Class' Psalm error
VadymHrechukha Sep 20, 2024
87ef792
HP-2116: fixing 'Argument 1 of hiqdev\php\billing\sale\Sale::close ha…
VadymHrechukha Sep 20, 2024
35f7742
HP-2116: fixing 'UndefinedClass: Class, interface or enum named Lamin…
VadymHrechukha Sep 20, 2024
830571b
HP-2116: fixing 'Method hiqdev\php\billing\charge\ChargeInterface::re…
VadymHrechukha Sep 20, 2024
37c4e46
HP-2116: fixing 'Argument 1 of hiqdev\php\billing\charge\modifiers\In…
VadymHrechukha Sep 20, 2024
9933e9e
HP-2116: fixing 'Method hiqdev\php\billing\charge\ChargeInterface::re…
VadymHrechukha Sep 20, 2024
e10f3d8
HP-2116: fixing 'Argument 1 of hiqdev\php\billing\charge\modifiers\ad…
VadymHrechukha Sep 20, 2024
dcbddc4
HP-2116: fixing 'UndefinedClass: Class, interface or enum named hiqde…
VadymHrechukha Sep 20, 2024
633210c
HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37…
VadymHrechukha Sep 20, 2024
5c26c5c
HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37…
VadymHrechukha Sep 20, 2024
ec4d5a8
HP-2116: fixing 'hiqdev\php\billing\price\PriceInvalidArgumentExcepti…
VadymHrechukha Sep 20, 2024
d746d59
HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37…
VadymHrechukha Sep 20, 2024
0b79794
HP-2116: fixing 'ParamNameMismatch: Argument 1 of hiqdev\php\billing\…
VadymHrechukha Sep 20, 2024
ef04c3d
HP-2116: fixing 'ParamNameMismatch: Argument 1 of hiqdev\php\billing\…
VadymHrechukha Sep 20, 2024
29faef7
HP-2116: fixing 'Error: src/order/Calculator.php:193:37: UnusedVariab…
VadymHrechukha Sep 20, 2024
b828397
HP-2116: fixing 'UndefinedMethod: Method hiqdev\php\billing\plan\Plan…
VadymHrechukha Sep 20, 2024
3d38bf7
HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\…
VadymHrechukha Sep 20, 2024
94bacfe
HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element…
VadymHrechukha Sep 20, 2024
cf2b922
HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element…
VadymHrechukha Sep 20, 2024
4bbedfa
HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element…
VadymHrechukha Sep 20, 2024
6632a24
HP-2116: updated it to the latest version, actions/checkout@v3
VadymHrechukha Sep 20, 2024
108caa2
HP-2116: updated it to the latest version, actions/cache@v3
VadymHrechukha Sep 20, 2024
e3a63cd
HP-2116: trying to upload phpunit result to Scrutinizer
VadymHrechukha Sep 20, 2024
7371905
HP-2116: fixing "@covers ChargeDerivativeQuery" is invalid error
VadymHrechukha Sep 20, 2024
bf06b47
HP-2116: fixing Upload Code Coverage To Scrutinizer
VadymHrechukha Sep 20, 2024
dd4553d
HP-2116: removed Upload Code Coverage To Scrutinizer
VadymHrechukha Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/behat-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1']
php: ['8.1', '8.3']
coverage-driver: [pcov]
name: PHP ${{ matrix.php }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1']
php: ['8.3']
coverage-driver: [pcov]
name: PHP ${{ matrix.php }}
steps:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/psalm-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Psalm Static Analysis

on:
push:
pull_request:
schedule:
- cron: "0 9 * * 1"

jobs:
psalm:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.3' ]
coverage-driver: [ pcov ]
name: PHP ${{ matrix.php }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: gmp
coverage: pcov
tools: composer:v2, infection

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Update composer
run: composer self-update

- name: Composer install
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install -n

- name: Run Psalm
run: vendor/bin/psalm
14 changes: 0 additions & 14 deletions .scrutinizer.yml

This file was deleted.

7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.3",
"moneyphp/money": "^3.0 | ^4.0",
"hiqdev/php-units": "dev-master",
"psr/simple-cache": "^1.0",
Expand All @@ -52,14 +52,15 @@
"require-dev": {
"ext-intl": "*",
"behat/behat": "^3.4.3",
"phpunit/phpunit": "^8.1",
"phpunit/phpunit": "^10.0.0",
"league/event": "^2.1",
"hoa/ruler": "^2.17",
"hiqdev/hidev": "dev-master",
"hiqdev/hidev-php": "dev-master",
"hiqdev/hidev-behat": "dev-master",
"hiqdev/hidev-hiqdev": "dev-master",
"vimeo/psalm": "^3.0",
"hiqdev/php-data-mapper": "dev-master",
"vimeo/psalm": "^5.0",
"cache/array-adapter": "*",
"matthiasnoback/behat-expect-exception": "^v0.3.0"
},
Expand Down
12 changes: 8 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<directory>./tests/unit/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">

<coverage>
<include>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</include>
<exclude>
<directory suffix=".php">./vendor/</directory>
</exclude>
</coverage>
</phpunit>
19 changes: 15 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config file:///Users/silverfire/prj/github/hiqdev/php-billing/vendor/vimeo/psalm/config.xsd"
strictBinaryOperands="true"
allowStringToStandInForClass="true"
usePhpDocPropertiesWithoutMagicCall="true"
usePhpDocMethodsWithoutMagicCall="true"
ignoreInternalFunctionNullReturn="false"
findUnusedVariablesAndParams="true"
findUnusedPsalmSuppress="true"
ensureArrayStringOffsetsExist="true"
ensureArrayIntOffsetsExist="true"
ignoreInternalFunctionFalseReturn="false"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
Expand All @@ -23,7 +36,6 @@
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
Expand All @@ -43,7 +55,6 @@

<MoreSpecificReturnType errorLevel="info" />
<LessSpecificReturnStatement errorLevel="info" />
<TypeCoercion errorLevel="info" />

<PossiblyFalseArgument errorLevel="info" />
<PossiblyFalseIterator errorLevel="info" />
Expand Down
4 changes: 2 additions & 2 deletions src/Money/MultipliedMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace hiqdev\php\billing\Money;

use Laminas\Code\Reflection\Exception\InvalidArgumentException;
use InvalidArgumentException;
use Money\Currencies\ISOCurrencies;
use Money\Currency;
use Money\Money;
Expand Down Expand Up @@ -86,7 +86,7 @@ private static function calculateMultiplierToInteger(string $amount): int
return 1;
}

[$integer, $fraction] = explode('.', $amount, 2);
[, $fraction] = explode('.', $amount, 2);
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.

Ensure proper handling of the integer part in calculateMultiplierToInteger.

The change in the calculateMultiplierToInteger method discards the integer part of the amount string by only extracting the fraction part using explode. This may lead to unexpected behavior if the method is called with an amount that has a non-zero integer part.

To handle the integer part appropriately, consider updating the method to use the integer part in the calculation of the multiplier. For example:

-[, $fraction] = explode('.', $amount, 2);
+[$integer, $fraction] = array_pad(explode('.', $amount, 2), 2, '0');
+$multiplier = (int)('1' . implode(array_fill(0, strlen($fraction), '0')));
+return (int)$integer * $multiplier + $multiplier;

This change ensures that the integer part is considered in the calculation of the multiplier, aligning with the method's purpose of converting the entire amount string to an integer representation.

Committable suggestion was skipped due to low confidence.

return (int)('1' . implode(array_fill(0, strlen($fraction), 0)));
}

Expand Down
3 changes: 1 addition & 2 deletions src/action/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use DateInterval;
use DateTimeImmutable;
use hiqdev\php\billing\customer\CustomerInterface;
use hiqdev\php\billing\EntityInterface;
use hiqdev\php\billing\Exception\CannotReassignException;
use hiqdev\php\billing\sale\SaleInterface;
use hiqdev\php\billing\target\TargetInterface;
Expand All @@ -27,7 +26,7 @@
*
* @author Andrii Vasyliev <sol@hiqdev.com>
*/
abstract class AbstractAction implements ActionInterface, EntityInterface
abstract class AbstractAction implements \JsonSerializable, ActionInterface
{
/** @var int */
protected $id;
Expand Down
3 changes: 2 additions & 1 deletion src/action/ActionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use DateTimeImmutable;
use hiqdev\php\billing\customer\CustomerInterface;
use hiqdev\php\billing\EntityInterface;
use hiqdev\php\billing\price\PriceInterface;
use hiqdev\php\billing\sale\SaleInterface;
use hiqdev\php\billing\target\TargetInterface;
Expand All @@ -30,7 +31,7 @@
*
* @author Andrii Vasyliev <sol@hiqdev.com>
*/
interface ActionInterface extends \JsonSerializable
interface ActionInterface extends EntityInterface
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.

Tip

Codebase Verification

Update ActionInterface implementations and usages

The change to ActionInterface extending EntityInterface instead of JsonSerializable has not been fully implemented across the codebase. This inconsistency could lead to potential issues. Please address the following:

  1. Update AbstractAction to remove the direct implementation of \JsonSerializable as it's now redundant.
  2. Review all classes implementing ActionInterface to ensure they comply with the new EntityInterface requirements.
  3. Verify that all usages of ActionInterface across the codebase are compatible with the new interface hierarchy.
  4. Consider updating the docblocks and type hints in files using ActionInterface to reflect the new relationship with EntityInterface.

These changes will ensure consistency and prevent potential runtime issues due to the altered interface contract.

Analysis chain

Verify the impact of the interface signature change.

The interface signature has been updated to extend EntityInterface instead of JsonSerializable. This change alters the contract of ActionInterface, indicating that it will now adhere to the methods and properties defined in EntityInterface.

Please ensure that:

  1. All implementations of ActionInterface have been updated to adhere to the new contract.
  2. EntityInterface provides all the necessary functionality that was previously provided by JsonSerializable.
  3. The change is consistent with the overall design and architecture of the codebase.

Run the following script to verify the usage of ActionInterface:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all implementations of `ActionInterface` adhere to the new contract.

# Test 1: Search for implementations of `ActionInterface`. Expect: Only occurrences of the new signature.
rg --type php -A 5 $'implements ActionInterface'

# Test 2: Search for usages of `JsonSerializable` methods in `ActionInterface` implementations. Expect: No occurrences.
rg --type php -A 5 $'jsonSerialize\('

Length of output: 5572


Script:

#!/bin/bash
# Description: Further investigate the ActionInterface change and its impact

# Test 1: Search for class declarations that might implement ActionInterface
rg --type php -A 5 'class .+ implements .*ActionInterface'

# Test 2: Check if EntityInterface exists and what it declares
rg --type php -A 10 'interface EntityInterface'

# Test 3: Check for uses of ActionInterface
rg --type php 'use .*ActionInterface'

# Test 4: Look for abstract classes that might implement ActionInterface
rg --type php -A 5 'abstract class .+ implements .*ActionInterface'

Length of output: 4017

{
/**
* Returns if the given price applicable to this action.
Expand Down
2 changes: 1 addition & 1 deletion src/charge/modifiers/FixedDiscount.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getValue(ChargeInterface $charge = null): Discount

public function isAbsolute()
{
return $this->getAddon(self::VALUE)->isAbsolute();
return $this->getValue()->isAbsolute();
}

public function isRelative()
Expand Down
5 changes: 2 additions & 3 deletions src/charge/modifiers/FullCombination.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action):
return []; // If there was at least one charge, but it disappeared – modifier does not want this charge to happen. Stop.
}

$originalChargeExists = array_reduce($leftCharges, function ($result, Charge $item) use ($charge) {
$originalChargeExists = array_reduce($leftCharges, static function ($result, Charge $item) use ($charge) {
return $result || $charge === $item;
}, false);
if ($charge && !$originalChargeExists) {
Expand All @@ -66,7 +66,6 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action):
// $leftCharge will contain original charge and 0+ additional charges (discounts)
}

/** @var Charge $leftTotal */
/** @var Charge $charge */
$leftTotal = $this->sumCharges($charge, $leftCharges);
if ($this->right->isSuitable($leftTotal, $action)) {
Expand All @@ -78,7 +77,6 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action):

$lastLeftCharge = end($leftCharges);
$rightCharges = array_filter($dirtyRightCharges, function (ChargeInterface $charge) use ($leftTotal, $lastLeftCharge) {
/** @var Charge $charge */
if ($charge->getParent() === $leftTotal) {
$charge->overwriteParent($lastLeftCharge);
}
Expand Down Expand Up @@ -109,6 +107,7 @@ public function modifyCharge(?ChargeInterface $charge, ActionInterface $action):
$charge->setComment($leftTotal->getComment());
}

/** @var Charge $leftTotal */
$events = $leftTotal->releaseEvents();
if (!empty($events)) {
foreach ($events as $event) {
Expand Down
4 changes: 2 additions & 2 deletions src/charge/modifiers/Installment.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getTarget()
return new Target(Target::ANY, Target::ANY);
}

public function till($dummy)
public function till($time)
{
throw new FormulaSemanticsError('till can not be defined for installment');
}
Expand Down Expand Up @@ -154,7 +154,7 @@ private function createInstallmentFinishingCharge(ChargeInterface $charge, DateT
return $result;
}

private function createInstallmentStartingCharge(ChargeInterface $charge, DateTimeImmutable $month): ChargeInterface
private function createInstallmentStartingCharge(Charge $charge, DateTimeImmutable $month): ChargeInterface
{
$charge->recordThat(InstallmentWasStarted::onCharge($charge, $month));

Expand Down
2 changes: 1 addition & 1 deletion src/charge/modifiers/addons/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ public static function ensureValidValue($value)
*
* @return DateTimeImmutable time of period end
*/
abstract public function addTo(DateTimeImmutable $startTime): DateTimeImmutable;
abstract public function addTo(DateTimeImmutable $since): DateTimeImmutable;
}
8 changes: 7 additions & 1 deletion src/formula/Asserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use hiqdev\php\billing\charge\modifiers\FullCombination;
use Hoa\Ruler\Context;
use Hoa\Ruler\Model\Model;
use Hoa\Visitor\Element;

/**
* @author Andrii Vasyliev <sol@hiqdev.com>
Expand All @@ -35,6 +36,11 @@ public function makeAnd($lhs, $rhs)

public function visitModel(Model $element, &$handle = null, $eldnah = null)
{
return $element->getExpression()->accept($this, $handle, $eldnah);
return $this->getExpression($element)->accept($this, $handle, $eldnah);
}

private function getExpression(Model $element): Element
{
return $element->getExpression();
}
}
36 changes: 16 additions & 20 deletions src/order/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace hiqdev\php\billing\order;

use Exception;
use hiqdev\php\billing\action\Action;
use hiqdev\php\billing\action\ActionInterface;
use hiqdev\php\billing\action\TemporaryActionInterface;
use hiqdev\php\billing\charge\Charge;
Expand All @@ -23,7 +22,6 @@
use hiqdev\php\billing\plan\PlanInterface;
use hiqdev\php\billing\plan\PlanRepositoryInterface;
use hiqdev\php\billing\price\PriceInterface;
use hiqdev\php\billing\sale\Sale;
use hiqdev\php\billing\sale\SaleInterface;
use hiqdev\php\billing\sale\SaleRepositoryInterface;
use hiqdev\php\billing\tools\ActualDateTimeProvider;
Expand Down Expand Up @@ -63,14 +61,12 @@ public function calculateOrder(OrderInterface $order): array
$plans = $this->findPlans($order);
$charges = [];
foreach ($order->getActions() as $actionKey => $action) {
if ($plans[$actionKey] === null) {
continue;
}

try {
$charges = array_merge($charges, $this->calculatePlan($plans[$actionKey], $action));
} catch (Throwable $e) {
throw ActionChargingException::forAction($action, $e);
if (!empty($plans[$actionKey])) {
try {
$charges = array_merge($charges, $this->calculatePlan($plans[$actionKey], $action));
} catch (Throwable $e) {
throw ActionChargingException::forAction($action, $e);
}
}
}

Expand Down Expand Up @@ -157,19 +153,15 @@ public function calculateCharge(PriceInterface $price, ActionInterface $action):

/**
* @throws Exception
* @return PlanInterface[]|Plan
* @return PlanInterface[]
*/
private function findPlans(OrderInterface $order)
private function findPlans(OrderInterface $order): array
{
$sales = $this->findSales($order);
$plans = [];
$lookPlanIds = [];
foreach ($order->getActions() as $actionKey => $action) {
/** @var Action $action */
if ($sales[$actionKey] === false) {
/// it is ok when no sale found for upper resellers
$plans[$actionKey] = null;
} else {
if (!empty($sales[$actionKey])) {
$sale = $sales[$actionKey];
/** @var Plan|PlanInterface[] $plan */
$plan = $sale->getPlan();
Expand All @@ -185,12 +177,15 @@ private function findPlans(OrderInterface $order)
} else {
$plans[$actionKey] = null;
}
} else {
// It is ok when no sale found for upper resellers
$plans[$actionKey] = null;
}
}

if ($lookPlanIds) {
$foundPlans = $this->planRepository->findByIds($lookPlanIds);
foreach ($foundPlans as $actionKey => $plan) {
foreach ($foundPlans as $plan) {
$foundPlans[$plan->getId()] = $plan;
}
foreach ($lookPlanIds as $actionKey => $planId) {
Expand All @@ -205,9 +200,10 @@ private function findPlans(OrderInterface $order)
}

/**
* @return SaleInterface[]|Sale
* @param OrderInterface $order
* @return SaleInterface[]
*/
private function findSales(OrderInterface $order)
private function findSales(OrderInterface $order): array
{
$sales = [];
$lookActions = [];
Expand Down
Loading