From c4ae34edd5b4b24375b1ec9acad0a6818a088964 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Tue, 17 Sep 2024 14:35:13 +0300 Subject: [PATCH 01/79] HP-2116: Run pipelines on php-billing repo --- .github/workflows/behat-tests.yml | 2 +- .github/workflows/phpunit-tests.yml | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index f9fd315c..add3b8fb 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -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: diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 805d040f..71075746 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -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: diff --git a/composer.json b/composer.json index d570c763..8ef7e402 100644 --- a/composer.json +++ b/composer.json @@ -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", From 65767c9542d4792939e0cd90fb9f05c1819d0855 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Tue, 17 Sep 2024 14:39:34 +0300 Subject: [PATCH 02/79] HP-2116: fixed 'PHP Fatal error: Declaration of hiqdev\php\billing\tests\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 --- tests/unit/order/CalculatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/order/CalculatorTest.php b/tests/unit/order/CalculatorTest.php index a28b3a6c..a9433a1e 100644 --- a/tests/unit/order/CalculatorTest.php +++ b/tests/unit/order/CalculatorTest.php @@ -54,7 +54,7 @@ protected function setUp(): void $this->order = new Order(null, $this->plan->customer, $actions); } - public function testCalculateCharges() + public function testCalculateCharges(): void { $charges = $this->calculator->calculateOrder($this->order); foreach ($this->order->getActions() as $actionKey => $action) { From cbf7ce4164dfe1d99657ccc12b3fabeecb77cdc4 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Tue, 17 Sep 2024 14:43:20 +0300 Subject: [PATCH 03/79] HP-2116: fixing falling build --- tests/unit/charge/modifiers/InstallmentTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/charge/modifiers/InstallmentTest.php b/tests/unit/charge/modifiers/InstallmentTest.php index dc8c5350..51d19f22 100644 --- a/tests/unit/charge/modifiers/InstallmentTest.php +++ b/tests/unit/charge/modifiers/InstallmentTest.php @@ -14,7 +14,7 @@ use hiqdev\php\billing\charge\modifiers\addons\MonthPeriod; use hiqdev\php\billing\charge\modifiers\addons\YearPeriod; use hiqdev\php\billing\charge\modifiers\event\InstallmentWasStarted; -use hiqdev\php\billing\charge\modifiers\Leasing; +use hiqdev\php\billing\charge\modifiers\Installment; use hiqdev\php\billing\price\SinglePrice; use hiqdev\php\billing\tests\unit\action\ActionTest; use hiqdev\php\billing\type\Type; From 11a8e590a666886555c0dd7ff9a1b6ac6f075b55 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Tue, 17 Sep 2024 14:48:08 +0300 Subject: [PATCH 04/79] HP-2116: added PHP 8.3 to the test matrix alongside PHP 8.1 in Behat tests --- .github/workflows/behat-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/behat-tests.yml b/.github/workflows/behat-tests.yml index add3b8fb..eba13004 100644 --- a/.github/workflows/behat-tests.yml +++ b/.github/workflows/behat-tests.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.3'] + php: ['8.1', '8.3'] coverage-driver: [pcov] name: PHP ${{ matrix.php }} steps: From 754558ac6cb22caae88f6fa783b4b986fc285431 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 13:46:31 +0300 Subject: [PATCH 05/79] HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutinizer.yml --- .scrutinizer.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 931289b4..3e4786bd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,3 +1,8 @@ +before_scripts: + - composer self-update --2 # Upgrade to Composer 2 +environment: + php: + version: 8.3 checks: php: code_rating: true From c03f1343b8491f078536a96c27b7b84be7959f13 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 14:13:10 +0300 Subject: [PATCH 06/79] HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutinizer.yml --- .scrutinizer.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 3e4786bd..16057a71 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,5 +1,6 @@ -before_scripts: +before_commands: - composer self-update --2 # Upgrade to Composer 2 + - composer install --no-interaction --no-scripts # Install dependencies environment: php: version: 8.3 @@ -15,5 +16,8 @@ tools: build: nodes: analysis: + environment: + php: + version: 8.3 # Specify PHP version tests: override: [php-scrutinizer-run] From aa7ae1077fb15f952e9e74f112d8614488b42225 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 14:15:03 +0300 Subject: [PATCH 07/79] HP-2116: Upgrade to Composer 2 and Set PHP version to 8.3 in .scrutinizer.yml --- .scrutinizer.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 16057a71..20d5e92d 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,9 +1,6 @@ before_commands: - composer self-update --2 # Upgrade to Composer 2 - composer install --no-interaction --no-scripts # Install dependencies -environment: - php: - version: 8.3 checks: php: code_rating: true From cea59ee206f3bb93d7f5146628f92935379ec950 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 14:41:58 +0300 Subject: [PATCH 08/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 20d5e92d..23fa67dd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -11,10 +11,10 @@ tools: external_code_coverage: timeout: 600 build: + image: default-bionic + environment: + php: 8.3 # Specify PHP version nodes: analysis: - environment: - php: - version: 8.3 # Specify PHP version tests: - override: [php-scrutinizer-run] + override: [php-scrutinizer-run] \ No newline at end of file From b032170bad6f5b397f5543ec30e1ab86f9a5ce50 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 14:53:59 +0300 Subject: [PATCH 09/79] HP-2116: Use a Public PHP 8.3 Docker Image in Scrutinizer --- .scrutinizer.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 23fa67dd..9e0058b3 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -11,9 +11,7 @@ tools: external_code_coverage: timeout: 600 build: - image: default-bionic - environment: - php: 8.3 # Specify PHP version + image: php:8.3-cli nodes: analysis: tests: From c4a1bd162ea58f2abefafac55f8f3574e2ec9aaa Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 14:55:13 +0300 Subject: [PATCH 10/79] HP-2116: Use a Public PHP 8.3 Docker Image in Scrutinizer --- .scrutinizer.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9e0058b3..0bd0df48 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -11,7 +11,9 @@ tools: external_code_coverage: timeout: 600 build: - image: php:8.3-cli + environment: + docker: + image: php:8.3-cli nodes: analysis: tests: From 855c54235d57f4a72b94b30ce546e72fd7840906 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 15:01:08 +0300 Subject: [PATCH 11/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0bd0df48..39fba57a 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,4 +1,9 @@ before_commands: + # Install PHP 8.3 manually + - sudo add-apt-repository ppa:ondrej/php -y + - sudo apt-get update -y + - sudo apt-get install php8.3-cli -y + - php -v # Check PHP version to ensure 8.3 is installed - composer self-update --2 # Upgrade to Composer 2 - composer install --no-interaction --no-scripts # Install dependencies checks: @@ -11,9 +16,9 @@ tools: external_code_coverage: timeout: 600 build: + image: default-bionic environment: - docker: - image: php:8.3-cli + php: 8.3 # Specify PHP version nodes: analysis: tests: From a8d68b6bedce570a14a56b1dbab7a8e0003f54e4 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 15:03:00 +0300 Subject: [PATCH 12/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 39fba57a..82f942e7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -17,8 +17,6 @@ tools: timeout: 600 build: image: default-bionic - environment: - php: 8.3 # Specify PHP version nodes: analysis: tests: From 2a4b5219a84852d063b97b11bda70f17856c4b78 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 15:21:27 +0300 Subject: [PATCH 13/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 82f942e7..b4fc4552 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -17,6 +17,18 @@ tools: timeout: 600 build: image: default-bionic + steps: + - before_commands: + # Install PHP 8.3 manually + - sudo add-apt-repository ppa:ondrej/php -y + - sudo apt-get update -y + - sudo apt-get install php8.3-cli -y + - php -v # Check PHP version to ensure 8.3 is installed + - composer install --no-interaction --no-scripts + - commands: + # Continue with the usual steps + - vendor/bin/phpunit --coverage-text + - php-scrutinizer-run nodes: analysis: tests: From 66e981aa08a227bad87be0a84890248611b7ab65 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 20:35:53 +0300 Subject: [PATCH 14/79] HP-2116: fixed CertificatePlan::getRawPrice() method --- src/price/Sums.php | 8 ++++++++ tests/support/plan/CertificatePlan.php | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/price/Sums.php b/src/price/Sums.php index 2d10117a..f92c2710 100644 --- a/src/price/Sums.php +++ b/src/price/Sums.php @@ -6,6 +6,9 @@ { /** * @param int[]|null $values quantity => total sum for the quantity + * Quantity of what? + * Sum of what? + * If you know answers please write in the comment */ public function __construct(private ?array $values) { @@ -30,6 +33,11 @@ public function values(): ?array return $this->values; } + public function getSum(int $quantity) + { + return $this->values[$quantity] ?? null; + } + public function getMinSum(): int|string { return min($this->values); diff --git a/tests/support/plan/CertificatePlan.php b/tests/support/plan/CertificatePlan.php index 1736aed8..c37acd81 100644 --- a/tests/support/plan/CertificatePlan.php +++ b/tests/support/plan/CertificatePlan.php @@ -108,9 +108,10 @@ public function __construct() */ public function getRawPrice($action) { - $years = $action->getQuantity()->convert(Unit::year())->getQuantity(); + $quantity = $action->getQuantity()->convert(Unit::year())->getQuantity(); - return $this->getRawPrices($action->getType(), $action->getTarget())[$years]; + return $this->getRawPrices($action->getType(), $action->getTarget()) + ->getSum($quantity); } public function getRawPrices($type, $target): Sums From b964efa1d21a48e77aa98df776f655bde0652fb1 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 20:46:17 +0300 Subject: [PATCH 15/79] HP-2116: fixed AggregatorTest --- tests/unit/tools/AggregatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tools/AggregatorTest.php b/tests/unit/tools/AggregatorTest.php index b192082c..ae7bd4dc 100644 --- a/tests/unit/tools/AggregatorTest.php +++ b/tests/unit/tools/AggregatorTest.php @@ -70,7 +70,7 @@ public function testCalculateCharges(): void $this->assertCount(4, $bills); foreach ($bills as $bill) { - $prices = $this->plan->getRawPrices($bill->getType(), $bill->getTarget()); + $prices = $this->plan->getRawPrices($bill->getType(), $bill->getTarget())->values(); $sum = Money::USD(array_sum($prices)); $this->assertTrue($sum->negative()->equals($bill->getSum())); $this->assertEquals(6, $bill->getQuantity()->getQuantity()); From dfb3961e0ef1e31016e25ed874f60ccae26e3f3b Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 20:57:49 +0300 Subject: [PATCH 16/79] HP-2116: fixing "PHP Deprecated" for TypeTest in CI pipeline --- tests/unit/type/TypeTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/type/TypeTest.php b/tests/unit/type/TypeTest.php index 98c98cfe..495492c7 100644 --- a/tests/unit/type/TypeTest.php +++ b/tests/unit/type/TypeTest.php @@ -30,6 +30,30 @@ class TypeTest extends \PHPUnit\Framework\TestCase protected $dop1 = 'domain1'; protected $dop2 = 'domain2'; + private Type $server11; + private Type $server12; + private Type $server_1; + private Type $server1_; + private Type $serverN1; + private Type $server1N; + private Type $serverN_; + private Type $server_N; + private Type $server22; + private Type $server21; + private Type $server_2; + private Type $server2_; + private Type $serverN2; + private Type $server2N; + + private Type $domain11; + private Type $domain_1; + private Type $domain1_; + private Type $domainN1; + private Type $domain1N; + private Type $domain22; + private Type $domain_2; + private Type $domain2_; + protected function setUp(): void { $this->nonenone = new Type(Type::NONE, Type::NONE); From 190be29f8e7f6b95f4b32aad5123c246b120db66 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 20:59:47 +0300 Subject: [PATCH 17/79] HP-2116: fixing "PHP Deprecated" for FixedDiscountTest in CI pipeline --- tests/unit/charge/modifiers/FixedDiscountTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/charge/modifiers/FixedDiscountTest.php b/tests/unit/charge/modifiers/FixedDiscountTest.php index f18bf542..8e6c1063 100644 --- a/tests/unit/charge/modifiers/FixedDiscountTest.php +++ b/tests/unit/charge/modifiers/FixedDiscountTest.php @@ -21,9 +21,14 @@ */ class FixedDiscountTest extends ActionTest { + private Money $value; + + private string $rate; + protected function setUp(): void { parent::setUp(); + $this->value = Money::USD(1000); $this->rate = '10'; } From 31899db6c796db61207bbe742bed6ac94063e5b2 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:01:41 +0300 Subject: [PATCH 18/79] HP-2116: fixing "PHP Deprecated" for ModifierTest in CI pipeline --- tests/unit/charge/modifiers/ModifierTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/charge/modifiers/ModifierTest.php b/tests/unit/charge/modifiers/ModifierTest.php index f6d6491c..46f0ffaa 100644 --- a/tests/unit/charge/modifiers/ModifierTest.php +++ b/tests/unit/charge/modifiers/ModifierTest.php @@ -22,7 +22,9 @@ */ class ModifierTest extends \PHPUnit\Framework\TestCase { - protected $modifier; + private DateTimeImmutable $now; + + protected Modifier $modifier; const SOME_TEXT = 'some text'; From 17eb0ba3f66417cdb787bb63791ee7077d5564a1 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:05:07 +0300 Subject: [PATCH 19/79] HP-2116: fixing "PHP Deprecated" for PriceFactoryTest in CI pipeline --- tests/unit/price/PriceFactoryTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/unit/price/PriceFactoryTest.php b/tests/unit/price/PriceFactoryTest.php index b89a6bc0..6439cebd 100644 --- a/tests/unit/price/PriceFactoryTest.php +++ b/tests/unit/price/PriceFactoryTest.php @@ -25,6 +25,24 @@ */ class PriceFactoryTest extends \PHPUnit\Framework\TestCase { + private string $id; + + private Type $single; + + private Type $enum; + + private Target $target; + + private $prepaid; + + private Money $price; + + private $unit; + + private array $sums; + + private PriceFactory $factory; + protected function setUp(): void { $this->id = 'foo:bar'; From 3f7342eb114dc005f1788f2a89880123becbabd3 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:07:01 +0300 Subject: [PATCH 20/79] HP-2116: fixing "PHP Deprecated" for SinglePriceTest in CI pipeline --- tests/unit/price/SinglePriceTest.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/unit/price/SinglePriceTest.php b/tests/unit/price/SinglePriceTest.php index 83670713..92829f97 100644 --- a/tests/unit/price/SinglePriceTest.php +++ b/tests/unit/price/SinglePriceTest.php @@ -22,20 +22,17 @@ */ class SinglePriceTest extends \PHPUnit\Framework\TestCase { - /** - * @var SinglePrice - */ - protected $price; + protected SinglePrice $price; - /** - * @var Action - */ - protected $action; + protected Action $action; - /** - * @var Money - */ - protected $money; + protected Money $money; + + private Target $target; + + private Type $type; + + private $quantity; protected function setUp(): void { From 39a3ec689acdfc2911937d24fe3f7374095d200c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:08:48 +0300 Subject: [PATCH 21/79] HP-2116: fixing "PHP Deprecated" for SaleTest in CI pipeline --- tests/unit/sale/SaleTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/tests/unit/sale/SaleTest.php b/tests/unit/sale/SaleTest.php index 10bc5724..f60ed6ad 100644 --- a/tests/unit/sale/SaleTest.php +++ b/tests/unit/sale/SaleTest.php @@ -20,14 +20,11 @@ class SaleTest extends PlanTest { - /** - * @var Sale|SaleInterface - */ - protected $sale; - /** - * @var SaleRepositoryInterface|SimpleSaleRepository - */ - protected $repository; + protected DateTimeImmutable $time; + + protected SaleInterface $sale; + + protected SaleRepositoryInterface $repository; protected function setUp(): void { From d58445082a13bd13397f2f5a41d8a8bd753ed9d9 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:10:44 +0300 Subject: [PATCH 22/79] HP-2116: fixing "PHP Deprecated" for TargetTest in CI pipeline --- tests/unit/target/TargetTest.php | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/unit/target/TargetTest.php b/tests/unit/target/TargetTest.php index 63a53249..183b78f9 100644 --- a/tests/unit/target/TargetTest.php +++ b/tests/unit/target/TargetTest.php @@ -20,10 +20,49 @@ class TargetTest extends \PHPUnit\Framework\TestCase { protected $id1 = 1; + protected $id2 = 2; + protected $idA = 8; + protected $idB = 9; + private \hiqdev\php\billing\target\AbstractTarget $target_; + + private Target $target1; + + private Target $target2; + + private Target $targetA; + + private Target $targetB; + + private TargetCollection $targets; + + private Target $server_; + + private Target $server1; + + private Target $server2; + + private Target $serverA; + + private Target $serverB; + + private Target $serverN; + + private TargetCollection $servers; + + private Target $domain_; + + private Target $domain1; + + private Target $domain2; + + private Target $domainN; + + private TargetCollection $domains; + protected function setUp(): void { $this->target_ = Target::any(); From 8087a360d2db9d80f5c1e3d41e16beca3d219f04 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:12:48 +0300 Subject: [PATCH 23/79] HP-2116: fixing "PHP Deprecated" for PlanTest in CI pipeline --- tests/unit/plan/PlanTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/plan/PlanTest.php b/tests/unit/plan/PlanTest.php index 3c5da891..3e7bff4b 100644 --- a/tests/unit/plan/PlanTest.php +++ b/tests/unit/plan/PlanTest.php @@ -31,6 +31,8 @@ class PlanTest extends \PHPUnit\Framework\TestCase protected DateTimeImmutable $time; + private Calculator $calculator; + protected function setUp(): void { $this->plan = CertificatePlan::get(); From b065614e8d440d76057332aa6660d59ba6c9a8ce Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:13:18 +0300 Subject: [PATCH 24/79] HP-2116: fixing "PHP Deprecated" for FactoryTest in CI pipeline --- tests/unit/tools/FactoryTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/tools/FactoryTest.php b/tests/unit/tools/FactoryTest.php index 197d1012..286e4571 100644 --- a/tests/unit/tools/FactoryTest.php +++ b/tests/unit/tools/FactoryTest.php @@ -55,8 +55,11 @@ class FactoryTest extends \PHPUnit\Framework\TestCase private $priceId = 'price-id'; private $targetId = 'target-id'; + private $target = 'type:name'; + private SimpleFactory $factory; + protected function setUp(): void { $this->factory = new SimpleFactory(); From b43736d0ee3ef3864782cd921c1f0804ea03edc7 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:13:50 +0300 Subject: [PATCH 25/79] HP-2116: fixing "PHP Deprecated" for TypeTest in CI pipeline --- tests/unit/type/TypeTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/type/TypeTest.php b/tests/unit/type/TypeTest.php index 495492c7..731c0a68 100644 --- a/tests/unit/type/TypeTest.php +++ b/tests/unit/type/TypeTest.php @@ -30,6 +30,8 @@ class TypeTest extends \PHPUnit\Framework\TestCase protected $dop1 = 'domain1'; protected $dop2 = 'domain2'; + private Type $nonenone; + private Type $server11; private Type $server12; private Type $server_1; From 2e713a1ec5afb5e3ae2b2d0ea9235c689a70b5c4 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:21:28 +0300 Subject: [PATCH 26/79] HP-2116: exclude the vendor directory from testing using the --exclude option in your workflow file: --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 71075746..12146113 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -41,6 +41,6 @@ jobs: run: composer install -n - name: PHPUnit - run: vendor/bin/phpunit + run: vendor/bin/phpunit --exclude vendor env: XDEBUG_MODE: coverage From 92de32f7fe35d34d51ca4925ae4dbf5ddd06849e Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:26:24 +0300 Subject: [PATCH 27/79] HP-2116: The vendor/ directory is excluded from code coverage calculation via the blacklist section in the block. --- phpunit.xml.dist | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3c0a4945..15e5b9df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,5 +9,8 @@ ./src/ + + ./vendor/ + From e0fa4e92aff4b50ed25ccac11b07c344088bbd6f Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:29:16 +0300 Subject: [PATCH 28/79] HP-2116: Exclude vendor directory to ignore warnings from third-party code --- phpunit.xml.dist | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15e5b9df..422ffae1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,9 +8,9 @@ ./src/ + + ./vendor/ + - - ./vendor/ - From 1bc51c4ba96f82acf84cd273feccf370188fd381 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:39:19 +0300 Subject: [PATCH 29/79] HP-2116: use instead of to manage which parts of the code you want to include in code coverage and which parts to exclude. --- phpunit.xml.dist | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 422ffae1..804ccd60 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,12 +5,13 @@ ./tests/unit/ - - + + + ./src/ - - ./vendor/ - - - + + + ./vendor/ + + From 0270de610fb6a12db85e794e65f3b650e2aa594f Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:43:07 +0300 Subject: [PATCH 30/79] HP-2116: Updated PHPUnit from 8.5.39 to 10 version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8ef7e402..dbd05200 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "require-dev": { "ext-intl": "*", "behat/behat": "^3.4.3", - "phpunit/phpunit": "^8.1", + "phpunit/phpunit": "^10", "league/event": "^2.1", "hoa/ruler": "^2.17", "hiqdev/hidev": "dev-master", From df10864a68f063acfe9780bbbbb522360bf08c56 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:48:17 +0300 Subject: [PATCH 31/79] HP-2116: Updated PHPUnit from 8.5.39 to 10 version --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index dbd05200..da92c883 100644 --- a/composer.json +++ b/composer.json @@ -52,14 +52,14 @@ "require-dev": { "ext-intl": "*", "behat/behat": "^3.4.3", - "phpunit/phpunit": "^10", + "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", + "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" }, From 970a4d08004b55e5d8cf03fef181dbaf1c64fec9 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:49:50 +0300 Subject: [PATCH 32/79] HP-2116: Fixed 'Option "--exclude" is ambiguous' error --- .github/workflows/phpunit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 12146113..71075746 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -41,6 +41,6 @@ jobs: run: composer install -n - name: PHPUnit - run: vendor/bin/phpunit --exclude vendor + run: vendor/bin/phpunit env: XDEBUG_MODE: coverage From e1cc8f9e4fa14ad2f238a1c569ba5d9efe6ea637 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:56:33 +0300 Subject: [PATCH 33/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index b4fc4552..82f942e7 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -17,18 +17,6 @@ tools: timeout: 600 build: image: default-bionic - steps: - - before_commands: - # Install PHP 8.3 manually - - sudo add-apt-repository ppa:ondrej/php -y - - sudo apt-get update -y - - sudo apt-get install php8.3-cli -y - - php -v # Check PHP version to ensure 8.3 is installed - - composer install --no-interaction --no-scripts - - commands: - # Continue with the usual steps - - vendor/bin/phpunit --coverage-text - - php-scrutinizer-run nodes: analysis: tests: From fff1f374a6aed0d1fd804855d2cafd79e31d28c0 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 21:58:41 +0300 Subject: [PATCH 34/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 82f942e7..ed780b03 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,9 +1,4 @@ before_commands: - # Install PHP 8.3 manually - - sudo add-apt-repository ppa:ondrej/php -y - - sudo apt-get update -y - - sudo apt-get install php8.3-cli -y - - php -v # Check PHP version to ensure 8.3 is installed - composer self-update --2 # Upgrade to Composer 2 - composer install --no-interaction --no-scripts # Install dependencies checks: From 4439a57ab6aa487f8345b8a189837945a166076c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Thu, 19 Sep 2024 22:14:58 +0300 Subject: [PATCH 35/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index ed780b03..093c51a9 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,5 +14,11 @@ build: image: default-bionic nodes: analysis: + environment: + php: 8.3 + dependencies: + before: + - composer self-update --2 # Upgrade to Composer 2 + - composer install --no-interaction --no-scripts # Install dependencies tests: override: [php-scrutinizer-run] \ No newline at end of file From ba283ef3b62e20b77144320bee52d47ebb7727da Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 10:03:20 +0300 Subject: [PATCH 36/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 093c51a9..51146ae4 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -14,10 +14,13 @@ build: image: default-bionic nodes: analysis: - environment: - php: 8.3 dependencies: before: + # Install PHP 8.3 manually + - sudo add-apt-repository ppa:ondrej/php -y + - sudo apt-get update -y + - sudo apt-get install php8.3-cli -y + - php -v # Check PHP version to ensure 8.3 is installed - composer self-update --2 # Upgrade to Composer 2 - composer install --no-interaction --no-scripts # Install dependencies tests: From a7a7e2cff85bf37ae1e4ea9d120dd7c3ab679577 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 10:08:53 +0300 Subject: [PATCH 37/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 51146ae4..3effa2d9 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -17,6 +17,8 @@ build: dependencies: before: # Install PHP 8.3 manually + - sudo apt-get update + - sudo apt-get install -y software-properties-common - sudo add-apt-repository ppa:ondrej/php -y - sudo apt-get update -y - sudo apt-get install php8.3-cli -y From 0fc4e6597c85f950138600759783db4438165eac Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 10:27:40 +0300 Subject: [PATCH 38/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 3effa2d9..0af8e0dd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,7 +21,7 @@ build: - sudo apt-get install -y software-properties-common - sudo add-apt-repository ppa:ondrej/php -y - sudo apt-get update -y - - sudo apt-get install php8.3-cli -y + - sudo apt-get install php8.3 php8.3-cli -y - php -v # Check PHP version to ensure 8.3 is installed - composer self-update --2 # Upgrade to Composer 2 - composer install --no-interaction --no-scripts # Install dependencies From 5aa527fba7d1d0d9b1fd4136ae293648335130d5 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 10:27:52 +0300 Subject: [PATCH 39/79] HP-2116: Configuring PHP8.3 on Scrutinizer --- .scrutinizer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0af8e0dd..8dbd70ef 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -16,6 +16,8 @@ build: analysis: dependencies: before: + - composer self-update --2 # Upgrade to Composer 2 + - composer install --no-interaction --no-scripts # Install dependencies # Install PHP 8.3 manually - sudo apt-get update - sudo apt-get install -y software-properties-common @@ -23,7 +25,5 @@ build: - sudo apt-get update -y - sudo apt-get install php8.3 php8.3-cli -y - php -v # Check PHP version to ensure 8.3 is installed - - composer self-update --2 # Upgrade to Composer 2 - - composer install --no-interaction --no-scripts # Install dependencies tests: override: [php-scrutinizer-run] \ No newline at end of file From d89ddf0047933508f1ec10e1c245fb8d979408a8 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:05:20 +0300 Subject: [PATCH 40/79] HP-2116: Created GitHub Actions .yml file that runs Psalm for static analysis --- .github/workflows/psalm-analysis.yml | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/psalm-analysis.yml diff --git a/.github/workflows/psalm-analysis.yml b/.github/workflows/psalm-analysis.yml new file mode 100644 index 00000000..7bdd9bca --- /dev/null +++ b/.github/workflows/psalm-analysis.yml @@ -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@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: gmp + coverage: pcov + tools: composer:v2, infection + + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-composer-${{ hashFiles('composer.json', 'composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - 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 \ No newline at end of file From 2e5a1150596dc5cfccb302ecaaf59823a45bfae3 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:07:13 +0300 Subject: [PATCH 41/79] HP-2116: Created GitHub Actions .yml file that runs Psalm for static analysis --- .github/workflows/psalm-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/psalm-analysis.yml b/.github/workflows/psalm-analysis.yml index 7bdd9bca..697955a5 100644 --- a/.github/workflows/psalm-analysis.yml +++ b/.github/workflows/psalm-analysis.yml @@ -26,12 +26,12 @@ jobs: coverage: pcov tools: composer:v2, infection - - name: Cache Composer dependencies + - name: Cache Composer packages + id: composer-cache uses: actions/cache@v2 with: path: vendor - key: ${{ runner.os }}-composer-${{ hashFiles('composer.json', 'composer.lock') }} - restore-keys: ${{ runner.os }}-composer- + key: ${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Update composer run: composer self-update From 92aa16223b04e6c745f5ea6d97c767c0cd458b4c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:20:23 +0300 Subject: [PATCH 42/79] HP-2116: fixing psalm plugin --- psalm.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index dd796efd..e57914f1 100644 --- a/psalm.xml +++ b/psalm.xml @@ -2,11 +2,14 @@ + + + From 2b055fe7727a9fb8ee823c073b04a2ca12c78265 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:34:23 +0300 Subject: [PATCH 43/79] HP-2116: fixing errors in psalm file --- psalm.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/psalm.xml b/psalm.xml index e57914f1..9b3e6876 100644 --- a/psalm.xml +++ b/psalm.xml @@ -26,7 +26,6 @@ - @@ -46,7 +45,6 @@ - From e0836b55c5a8062927300a069bf7e3bde347cc05 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:44:51 +0300 Subject: [PATCH 44/79] HP-2116: testing psalm config --- psalm.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 9b3e6876..c0bb9e83 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,9 +1,19 @@ From b3116a2ed652117463629149e0b099eae27c4888 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 14:54:10 +0300 Subject: [PATCH 45/79] HP-2116: deleted scrutinizer --- .scrutinizer.yml | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 .scrutinizer.yml diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 8dbd70ef..00000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,29 +0,0 @@ -before_commands: - - composer self-update --2 # Upgrade to Composer 2 - - composer install --no-interaction --no-scripts # Install dependencies -checks: - php: - code_rating: true - duplication: true -tools: - php_code_coverage: - enabled: true - external_code_coverage: - timeout: 600 -build: - image: default-bionic - nodes: - analysis: - dependencies: - before: - - composer self-update --2 # Upgrade to Composer 2 - - composer install --no-interaction --no-scripts # Install dependencies - # Install PHP 8.3 manually - - sudo apt-get update - - sudo apt-get install -y software-properties-common - - sudo add-apt-repository ppa:ondrej/php -y - - sudo apt-get update -y - - sudo apt-get install php8.3 php8.3-cli -y - - php -v # Check PHP version to ensure 8.3 is installed - tests: - override: [php-scrutinizer-run] \ No newline at end of file From f29071bb0ab9a1f603175af98a759a032f39c61c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:17:19 +0300 Subject: [PATCH 46/79] HP-2116: rollback changes in AbstractPrice::jsonSerialize() method because it causing the errors in the next Unit test: - ProgressivePriceTest::testProgressivePriceSerialization - RatePriceTest::testJsonSerialize - SinglePriceTest::testJsonSerialize --- src/price/AbstractPrice.php | 49 +++++++++---------------------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/src/price/AbstractPrice.php b/src/price/AbstractPrice.php index 606790b9..938a77d1 100755 --- a/src/price/AbstractPrice.php +++ b/src/price/AbstractPrice.php @@ -146,47 +146,20 @@ public function calculateSum(QuantityInterface $quantity): ?Money return $sum; } + /** + * 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? + * + * @return array + */ public function jsonSerialize(): array { - $data = [ - 'id' => $this->id, - 'class' => (new \ReflectionClass($this))->getShortName(), - 'type' => $this->getType()->getName(), - 'type_id' => $this->getType()->getId(), - 'object_id' => $this->getTarget()->getId(), - 'object' => [ - 'id' => $this->getTarget()->getId(), - 'name' => $this->getTarget()->getName(), - 'type' => $this->getTarget()->getType(), - ], - 'plan_id' => $this->getPlan()?->getId(), - ]; - - if ($this instanceof PriceWithSubpriceInterface) { - $data['subprice'] = $this->getSubprices()->values(); - } - - if ($this instanceof PriceWithRateInterface) { - $data['rate'] = $this->getRate(); - } - - if ($this instanceof PriceWithUnitInterface) { - $data['unit'] = $this->getUnit()->getName(); - } - - if ($this instanceof PriceWithCurrencyInterface) { - $data['currency'] = $this->getCurrency()->getCode(); - } - - if ($this instanceof PriceWithSumsInterface) { - $data['sums'] = $this->getSums()->values(); - } - - if ($this instanceof PriceWithQuantityInterface) { - $data['quantity'] = $this->getPrepaid()->getQuantity(); - } + $res = array_filter(get_object_vars($this)); + unset($res['plan']); - return $data; + return $res; } /** From 44ba82e47ab87459241da64655b0c0f475ba3843 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:32:50 +0300 Subject: [PATCH 47/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\action\ActionInterface::getId does not exist' Psalm error --- src/action/AbstractAction.php | 3 +-- src/action/ActionInterface.php | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/action/AbstractAction.php b/src/action/AbstractAction.php index 4a500531..42857d01 100755 --- a/src/action/AbstractAction.php +++ b/src/action/AbstractAction.php @@ -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; @@ -27,7 +26,7 @@ * * @author Andrii Vasyliev */ -abstract class AbstractAction implements ActionInterface, EntityInterface +abstract class AbstractAction implements \JsonSerializable, ActionInterface { /** @var int */ protected $id; diff --git a/src/action/ActionInterface.php b/src/action/ActionInterface.php index 5ad95bf9..4662c1b0 100644 --- a/src/action/ActionInterface.php +++ b/src/action/ActionInterface.php @@ -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; @@ -30,7 +31,7 @@ * * @author Andrii Vasyliev */ -interface ActionInterface extends \JsonSerializable +interface ActionInterface extends EntityInterface { /** * Returns if the given price applicable to this action. From fdeda2c504c7099a33d4e2256b19b56db75c11d8 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:35:40 +0300 Subject: [PATCH 48/79] HP-2116: fixing 'UnusedVariable: $integer is never referenced or the value is not used' Psalm error --- src/Money/MultipliedMoney.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Money/MultipliedMoney.php b/src/Money/MultipliedMoney.php index e802e674..8fd3f6c6 100644 --- a/src/Money/MultipliedMoney.php +++ b/src/Money/MultipliedMoney.php @@ -86,7 +86,7 @@ private static function calculateMultiplierToInteger(string $amount): int return 1; } - [$integer, $fraction] = explode('.', $amount, 2); + [, $fraction] = explode('.', $amount, 2); return (int)('1' . implode(array_fill(0, strlen($fraction), 0))); } From dff90013e7841da9f412f8f574c7e3afd6693c1c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:45:43 +0300 Subject: [PATCH 49/79] HP-2116: fixing 'UnnecessaryVarAnnotation: The @var hiqdev\php\billing\charge\Charge annotation for $charge is unnecessary' Psalm error --- src/charge/modifiers/FullCombination.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/charge/modifiers/FullCombination.php b/src/charge/modifiers/FullCombination.php index 1b34b5c0..5e8e7d54 100644 --- a/src/charge/modifiers/FullCombination.php +++ b/src/charge/modifiers/FullCombination.php @@ -78,7 +78,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); } From f4e55eed2aba6ace8700fe407a1f1f097433dc4f Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:49:37 +0300 Subject: [PATCH 50/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\charge\ChargeInterface::hasEvents does not exist' Psalm error --- src/tools/DbMergingAggregator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/DbMergingAggregator.php b/src/tools/DbMergingAggregator.php index 771aef5f..cf70c280 100644 --- a/src/tools/DbMergingAggregator.php +++ b/src/tools/DbMergingAggregator.php @@ -12,6 +12,7 @@ use hiqdev\php\billing\bill\BillInterface; use hiqdev\php\billing\bill\BillRepositoryInterface; +use hiqdev\php\billing\charge\Charge; use hiqdev\php\billing\charge\ChargeInterface; /** @@ -74,6 +75,7 @@ private function excludeLocalOnlyZeroBills(array $localBills, array $dbBills): a { foreach ($localBills as $i => $localBill) { foreach ($localBill->getCharges() as $charge) { + /** @var Charge $charge */ if ($charge->hasEvents()) { continue 2; } From 589a094b82c9f6d09ed1b41fd2a71a566cc23c2e Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:53:07 +0300 Subject: [PATCH 51/79] HP-2116: fixing 'UndefinedClass: Class' Psalm error --- psalm.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/psalm.xml b/psalm.xml index c0bb9e83..5b84502d 100644 --- a/psalm.xml +++ b/psalm.xml @@ -20,6 +20,9 @@ + + vendor/autoload.php + From d4a42285ef731a8cd7d55c69aeb2ad3d6db09ec3 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:53:52 +0300 Subject: [PATCH 52/79] HP-2116: fixing 'UndefinedClass: Class' Psalm error --- psalm.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/psalm.xml b/psalm.xml index 5b84502d..6eb012f2 100644 --- a/psalm.xml +++ b/psalm.xml @@ -20,11 +20,12 @@ - - vendor/autoload.php - + + vendor/autoload.php + + From 775d91ab03a7b4979171d1d156016b462442efa6 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 15:57:26 +0300 Subject: [PATCH 53/79] HP-2116: fixing 'UndefinedClass: Class' Psalm error --- psalm.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/psalm.xml b/psalm.xml index 6eb012f2..b1a93dcb 100644 --- a/psalm.xml +++ b/psalm.xml @@ -22,9 +22,7 @@ - - vendor/autoload.php - + vendor/autoload.php From 05dc27316f246a61461cc7c19b313412b4f0bfa6 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:00:03 +0300 Subject: [PATCH 54/79] HP-2116: fixing 'UndefinedClass: Class' Psalm error --- psalm.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/psalm.xml b/psalm.xml index b1a93dcb..c0bb9e83 100644 --- a/psalm.xml +++ b/psalm.xml @@ -22,8 +22,6 @@ - vendor/autoload.php - From 87ef7929a00afa899477a42f512dcaecdeb49509 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:02:43 +0300 Subject: [PATCH 55/79] HP-2116: fixing 'Argument 1 of hiqdev\php\billing\sale\Sale::close has wrong name $closeTime' Psalm error --- src/sale/SaleInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sale/SaleInterface.php b/src/sale/SaleInterface.php index 843104db..ef2727b1 100644 --- a/src/sale/SaleInterface.php +++ b/src/sale/SaleInterface.php @@ -67,11 +67,11 @@ public function getCloseTime(): ?DateTimeImmutable; public function getData(): ?array; /** - * @param DateTimeImmutable $time + * @param DateTimeImmutable $closeTime * @throws InvariantException * @throws ConstraintException */ - public function close(DateTimeImmutable $time): void; + public function close(DateTimeImmutable $closeTime): void; public function cancelClosing(): void; } From 35f7742ad878b3937f2f0d0eb862c00ba745823f Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:05:28 +0300 Subject: [PATCH 56/79] HP-2116: fixing 'UndefinedClass: Class, interface or enum named Laminas\Code\Reflection\Exception\InvalidArgumentException does not exist' Psalm error --- src/Money/MultipliedMoney.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Money/MultipliedMoney.php b/src/Money/MultipliedMoney.php index 8fd3f6c6..3cc10b9c 100644 --- a/src/Money/MultipliedMoney.php +++ b/src/Money/MultipliedMoney.php @@ -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; From 830571b1aabc8ebe4e8f09a869f50e8d7a2d048b Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:10:35 +0300 Subject: [PATCH 57/79] HP-2116: fixing 'Method hiqdev\php\billing\charge\ChargeInterface::releaseEvents does not exist' Psalm error --- src/charge/modifiers/FullCombination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/charge/modifiers/FullCombination.php b/src/charge/modifiers/FullCombination.php index 5e8e7d54..5b5ba510 100644 --- a/src/charge/modifiers/FullCombination.php +++ b/src/charge/modifiers/FullCombination.php @@ -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) { @@ -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)) { @@ -108,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) { From 37c4e46bb3cae9b7ba876b03fad62557a9707b8e Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:12:31 +0300 Subject: [PATCH 58/79] HP-2116: fixing 'Argument 1 of hiqdev\php\billing\charge\modifiers\Installment::till has wrong name $dummy, expecting $time' Psalm error --- src/charge/modifiers/Installment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charge/modifiers/Installment.php b/src/charge/modifiers/Installment.php index 2aff7cb6..efedd09a 100644 --- a/src/charge/modifiers/Installment.php +++ b/src/charge/modifiers/Installment.php @@ -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'); } From 9933e9e026712d9f7fcd5a074f42ecbe1a6203cc Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:14:11 +0300 Subject: [PATCH 59/79] HP-2116: fixing 'Method hiqdev\php\billing\charge\ChargeInterface::recordThat does not exist' Psalm error --- src/charge/modifiers/Installment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charge/modifiers/Installment.php b/src/charge/modifiers/Installment.php index efedd09a..dcfe6a10 100644 --- a/src/charge/modifiers/Installment.php +++ b/src/charge/modifiers/Installment.php @@ -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)); From e10f3d878194043f4b7a30f6fdc325beb237163a Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:15:37 +0300 Subject: [PATCH 60/79] HP-2116: fixing 'Argument 1 of hiqdev\php\billing\charge\modifiers\addons\DayPeriod::addTo has wrong name $since' Psalm error --- src/charge/modifiers/addons/Period.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charge/modifiers/addons/Period.php b/src/charge/modifiers/addons/Period.php index 9849b49a..5eb9adf0 100644 --- a/src/charge/modifiers/addons/Period.php +++ b/src/charge/modifiers/addons/Period.php @@ -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; } From dcbddc4b62fb1b935d9abcc7a20ddf2193813a9b Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:34:18 +0300 Subject: [PATCH 61/79] HP-2116: fixing 'UndefinedClass: Class, interface or enum named hiqdev\DataMapper\Query\Specification does not exist' Psalm error --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index da92c883..0b821b83 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "hiqdev/hidev-php": "dev-master", "hiqdev/hidev-behat": "dev-master", "hiqdev/hidev-hiqdev": "dev-master", + "hiqdev/php-data-mapper": "dev-master", "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" From 633210c5357a87c46bb5b702429b370f5b809e4a Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:37:09 +0300 Subject: [PATCH 62/79] HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 0b821b83..a9f322ed 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "hiqdev/hidev-behat": "dev-master", "hiqdev/hidev-hiqdev": "dev-master", "hiqdev/php-data-mapper": "dev-master", + "hiqdev/hiapi": "dev-master", "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" From 5c26c5ca28f6728457dfccc32e3af20ae58c2dcb Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:42:14 +0300 Subject: [PATCH 63/79] HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index a9f322ed..2dc027f9 100644 --- a/composer.json +++ b/composer.json @@ -61,6 +61,7 @@ "hiqdev/hidev-hiqdev": "dev-master", "hiqdev/php-data-mapper": "dev-master", "hiqdev/hiapi": "dev-master", + "advancedhosters/billing-hiapi": "dev-master", "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" From ec4d5a8983f150a5efadff40d84c67e3846217cb Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:44:40 +0300 Subject: [PATCH 64/79] HP-2116: fixing 'hiqdev\php\billing\price\PriceInvalidArgumentException depends on class or interface hiapi\exceptions\hiapiexception' Psalm error --- composer.json | 1 - src/price/PriceInvalidArgumentException.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 2dc027f9..8bd692a7 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,6 @@ "hiqdev/hidev-behat": "dev-master", "hiqdev/hidev-hiqdev": "dev-master", "hiqdev/php-data-mapper": "dev-master", - "hiqdev/hiapi": "dev-master", "advancedhosters/billing-hiapi": "dev-master", "vimeo/psalm": "^5.0", "cache/array-adapter": "*", diff --git a/src/price/PriceInvalidArgumentException.php b/src/price/PriceInvalidArgumentException.php index 309e5725..90a49dce 100644 --- a/src/price/PriceInvalidArgumentException.php +++ b/src/price/PriceInvalidArgumentException.php @@ -2,8 +2,8 @@ namespace hiqdev\php\billing\price; -use hiapi\exceptions\HiapiException; +use hiqdev\php\billing\Exception\RuntimeException; -class PriceInvalidArgumentException extends HiapiException +class PriceInvalidArgumentException extends RuntimeException { } From d746d59b3885f470b8647d81b8b3dc9cf7601a35 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:53:00 +0300 Subject: [PATCH 65/79] HP-2116: fixing 'Error: src/price/PriceWithSubpriceInterface.php:9:37: UndefinedClass: Class, interface or enum named hiqdev\billing\hiapi\price\SubPrices does not exist' Psalm error --- composer.json | 1 - src/price/PriceWithSubpriceInterface.php | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 src/price/PriceWithSubpriceInterface.php diff --git a/composer.json b/composer.json index 8bd692a7..0b821b83 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,6 @@ "hiqdev/hidev-behat": "dev-master", "hiqdev/hidev-hiqdev": "dev-master", "hiqdev/php-data-mapper": "dev-master", - "advancedhosters/billing-hiapi": "dev-master", "vimeo/psalm": "^5.0", "cache/array-adapter": "*", "matthiasnoback/behat-expect-exception": "^v0.3.0" diff --git a/src/price/PriceWithSubpriceInterface.php b/src/price/PriceWithSubpriceInterface.php deleted file mode 100644 index 1faf9304..00000000 --- a/src/price/PriceWithSubpriceInterface.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Fri, 20 Sep 2024 16:54:49 +0300 Subject: [PATCH 66/79] HP-2116: fixing 'ParamNameMismatch: Argument 1 of hiqdev\php\billing\plan\Plan::setParentId has wrong name $id, expecting $parentId' Psalm error --- src/plan/Plan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plan/Plan.php b/src/plan/Plan.php index 35db5a30..6f79dabf 100755 --- a/src/plan/Plan.php +++ b/src/plan/Plan.php @@ -109,9 +109,9 @@ public function getParentId(): ?int return $this->parent_id; } - public function setParentId(int $id): void + public function setParentId(int $parentId): void { - $this->parent_id = $id; + $this->parent_id = $parentId; } public function hasPrices(): bool From ef04c3d117c773a0129fdf78dd233db082721136 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:55:39 +0300 Subject: [PATCH 67/79] HP-2116: fixing 'ParamNameMismatch: Argument 1 of hiqdev\php\billing\price\SinglePrice::calculatePrice has wrong name $usage, expecting $quantity' Psalm error --- src/price/SinglePrice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/price/SinglePrice.php b/src/price/SinglePrice.php index 320f6ab2..99c1ba33 100644 --- a/src/price/SinglePrice.php +++ b/src/price/SinglePrice.php @@ -63,7 +63,7 @@ public function calculateUsage(QuantityInterface $quantity): ?QuantityInterface * {@inheritdoc} * Same price for any usage. */ - public function calculatePrice(QuantityInterface $usage): ?Money + public function calculatePrice(QuantityInterface $quantity): ?Money { return $this->price; } From 29faef7e2bee89ab08c524595ed63254cba8d2d0 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 16:56:23 +0300 Subject: [PATCH 68/79] HP-2116: fixing 'Error: src/order/Calculator.php:193:37: UnusedVariable: $actionKey is never referenced or the value is not used' Psalm error --- src/order/Calculator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/order/Calculator.php b/src/order/Calculator.php index 64b59976..68182f23 100644 --- a/src/order/Calculator.php +++ b/src/order/Calculator.php @@ -190,7 +190,7 @@ private function findPlans(OrderInterface $order) 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) { From b82839705e7a619cdaa95445e49fbbb44c692a59 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:07:29 +0300 Subject: [PATCH 69/79] HP-2116: fixing 'UndefinedMethod: Method hiqdev\php\billing\plan\Plan::offsetGet does not exist' Psalm error --- src/order/Calculator.php | 34 ++++++++++++---------------- src/sale/SaleRepositoryInterface.php | 2 +- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/order/Calculator.php b/src/order/Calculator.php index 68182f23..15d2ee57 100644 --- a/src/order/Calculator.php +++ b/src/order/Calculator.php @@ -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; @@ -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; @@ -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); + } } } @@ -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(); @@ -185,6 +177,9 @@ private function findPlans(OrderInterface $order) } else { $plans[$actionKey] = null; } + } else { + // It is ok when no sale found for upper resellers + $plans[$actionKey] = null; } } @@ -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 = []; diff --git a/src/sale/SaleRepositoryInterface.php b/src/sale/SaleRepositoryInterface.php index be469f51..310511c2 100644 --- a/src/sale/SaleRepositoryInterface.php +++ b/src/sale/SaleRepositoryInterface.php @@ -34,7 +34,7 @@ public function findById(string $id): ?object; /** * Finds suitable sales for given order. - * @return PlanInterface[] array: actionKey => plan + * @return SaleInterface[] array: actionKey => sale */ public function findByOrder(OrderInterface $order); From 3d38bf760e15dc38e304001fb6614736b9dc8a53 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:12:28 +0300 Subject: [PATCH 70/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method hiqdev\php\billing\charge\modifiers\AddonInterface::isAbsolute' Psalm error --- src/charge/modifiers/FixedDiscount.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/charge/modifiers/FixedDiscount.php b/src/charge/modifiers/FixedDiscount.php index 32f23c45..203d5283 100644 --- a/src/charge/modifiers/FixedDiscount.php +++ b/src/charge/modifiers/FixedDiscount.php @@ -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() From 94bacfebfeb4fcaf34c3bc3b5bd295e38ea5ef9e Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:16:13 +0300 Subject: [PATCH 71/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element::getExpression does not exist' Psalm error --- src/formula/Asserter.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/formula/Asserter.php b/src/formula/Asserter.php index 58d44a53..5e3b416a 100644 --- a/src/formula/Asserter.php +++ b/src/formula/Asserter.php @@ -13,6 +13,7 @@ use hiqdev\php\billing\charge\modifiers\FullCombination; use Hoa\Ruler\Context; use Hoa\Ruler\Model\Model; +use Hoa\Ruler\Model\Operator; /** * @author Andrii Vasyliev @@ -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): Operator + { + return $element->getExpression(); } } From cf2b922181808d04eb701cdfb95dc3235e386e35 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:17:34 +0300 Subject: [PATCH 72/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element::getExpression does not exist' Psalm error --- src/formula/Asserter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formula/Asserter.php b/src/formula/Asserter.php index 5e3b416a..9c4e369c 100644 --- a/src/formula/Asserter.php +++ b/src/formula/Asserter.php @@ -36,10 +36,10 @@ public function makeAnd($lhs, $rhs) public function visitModel(Model $element, &$handle = null, $eldnah = null) { - return $this->getExpression($element)->accept($this, $handle, $eldnah); + return $this->_getExpression($element)->accept($this, $handle, $eldnah); } - private function getExpression(Model $element): Operator + private function _getExpression(Model $element): Operator { return $element->getExpression(); } From 4bbedfa16782bbc5e26cff920575bf03d307311c Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:23:27 +0300 Subject: [PATCH 73/79] HP-2116: fixing 'UndefinedInterfaceMethod: Method Hoa\Visitor\Element::getExpression does not exist' Psalm error --- src/formula/Asserter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/formula/Asserter.php b/src/formula/Asserter.php index 9c4e369c..6379b2d0 100644 --- a/src/formula/Asserter.php +++ b/src/formula/Asserter.php @@ -13,7 +13,7 @@ use hiqdev\php\billing\charge\modifiers\FullCombination; use Hoa\Ruler\Context; use Hoa\Ruler\Model\Model; -use Hoa\Ruler\Model\Operator; +use Hoa\Visitor\Element; /** * @author Andrii Vasyliev @@ -36,10 +36,10 @@ public function makeAnd($lhs, $rhs) public function visitModel(Model $element, &$handle = null, $eldnah = null) { - return $this->_getExpression($element)->accept($this, $handle, $eldnah); + return $this->getExpression($element)->accept($this, $handle, $eldnah); } - private function _getExpression(Model $element): Operator + private function getExpression(Model $element): Element { return $element->getExpression(); } From 6632a24d5012ce26ff38202ce23862800a5d716d Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:25:39 +0300 Subject: [PATCH 74/79] HP-2116: updated it to the latest version, actions/checkout@v3 --- .github/workflows/psalm-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/psalm-analysis.yml b/.github/workflows/psalm-analysis.yml index 697955a5..0c74e9cd 100644 --- a/.github/workflows/psalm-analysis.yml +++ b/.github/workflows/psalm-analysis.yml @@ -16,7 +16,7 @@ jobs: name: PHP ${{ matrix.php }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 From 108caa29f9e40388c68176f25b14ad59b1e70b68 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 17:26:10 +0300 Subject: [PATCH 75/79] HP-2116: updated it to the latest version, actions/cache@v3 --- .github/workflows/psalm-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/psalm-analysis.yml b/.github/workflows/psalm-analysis.yml index 0c74e9cd..e0b766da 100644 --- a/.github/workflows/psalm-analysis.yml +++ b/.github/workflows/psalm-analysis.yml @@ -28,7 +28,7 @@ jobs: - name: Cache Composer packages id: composer-cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: vendor key: ${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} From e3a63cd463ef4e5a151cf2ccbe09c0c560c8e715 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 18:04:49 +0300 Subject: [PATCH 76/79] HP-2116: trying to upload phpunit result to Scrutinizer --- .github/workflows/phpunit-tests.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 71075746..cc7683f4 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -38,9 +38,21 @@ jobs: - name: Composer install if: steps.composer-cache.outputs.cache-hit != 'true' - run: composer install -n + run: | + composer install -n + composer require scrutinizer/ocular --no-update --no-interaction - name: PHPUnit - run: vendor/bin/phpunit + run: vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text --coverage-html=coverage env: XDEBUG_MODE: coverage + + - name: Archive Code Coverage Results + uses: codecov/codecov-action@v4 + with: + files: ./coverage.xml + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload Code Coverage To Scrutinizer + run: vendor/bin/ocular code-coverage:upload --format=php-clover coverage.xml \ No newline at end of file From 7371905b087ef5ea82f18584b46bdf4feab4d9ed Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 18:15:03 +0300 Subject: [PATCH 77/79] HP-2116: fixing "@covers ChargeDerivativeQuery" is invalid error --- tests/unit/charge/derivative/ChargeDerivativeQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php b/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php index afbb2733..4a48aee0 100644 --- a/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php +++ b/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php @@ -20,7 +20,7 @@ * Class ChargeDerivativeQueryTest * * @author Dmytro Naumenko - * @covers ChargeDerivativeQuery + * @covers \hiqdev\php\billing\charge\derivative\ChargeDerivativeQuery */ class ChargeDerivativeQueryTest extends TestCase { From bf06b47dccd3b8dc185bc1e660762a3e7f0e35c5 Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 18:21:08 +0300 Subject: [PATCH 78/79] HP-2116: fixing Upload Code Coverage To Scrutinizer --- .github/workflows/phpunit-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index cc7683f4..e9245d6e 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -38,9 +38,9 @@ jobs: - name: Composer install if: steps.composer-cache.outputs.cache-hit != 'true' - run: | - composer install -n + run: | composer require scrutinizer/ocular --no-update --no-interaction + composer update --prefer-dist --no-progress --prefer-${{ matrix.setup }} --ignore-platform-req=php - name: PHPUnit run: vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text --coverage-html=coverage From dd4553d5f52b19154b1b1b25c834bde6e2a19a9e Mon Sep 17 00:00:00 2001 From: Vadym Hrechukha Date: Fri, 20 Sep 2024 18:56:30 +0300 Subject: [PATCH 79/79] HP-2116: removed Upload Code Coverage To Scrutinizer --- .github/workflows/phpunit-tests.yml | 16 ++-------------- .../derivative/ChargeDerivativeQueryTest.php | 2 +- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index e9245d6e..71075746 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -38,21 +38,9 @@ jobs: - name: Composer install if: steps.composer-cache.outputs.cache-hit != 'true' - run: | - composer require scrutinizer/ocular --no-update --no-interaction - composer update --prefer-dist --no-progress --prefer-${{ matrix.setup }} --ignore-platform-req=php + run: composer install -n - name: PHPUnit - run: vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-text --coverage-html=coverage + run: vendor/bin/phpunit env: XDEBUG_MODE: coverage - - - name: Archive Code Coverage Results - uses: codecov/codecov-action@v4 - with: - files: ./coverage.xml - disable_search: true - token: ${{ secrets.CODECOV_TOKEN }} - - - name: Upload Code Coverage To Scrutinizer - run: vendor/bin/ocular code-coverage:upload --format=php-clover coverage.xml \ No newline at end of file diff --git a/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php b/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php index 4a48aee0..afbb2733 100644 --- a/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php +++ b/tests/unit/charge/derivative/ChargeDerivativeQueryTest.php @@ -20,7 +20,7 @@ * Class ChargeDerivativeQueryTest * * @author Dmytro Naumenko - * @covers \hiqdev\php\billing\charge\derivative\ChargeDerivativeQuery + * @covers ChargeDerivativeQuery */ class ChargeDerivativeQueryTest extends TestCase {