Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.3']
php: ['8.4']
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.3']
php: ['8.4']
coverage-driver: [pcov]
name: PHP ${{ matrix.php }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/psalm-analysis.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.3' ]
php: [ '8.4' ]
coverage-driver: [ pcov ]
name: PHP ${{ matrix.php }}
steps:
Expand Down Expand Up @@ -41,4 +41,4 @@ jobs:
run: composer install -n

- name: Run Psalm
run: vendor/bin/psalm
run: vendor/bin/psalm
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"opis/closure": "3.x-dev as 3.6.x-dev",
"cache/array-adapter": "*",
"matthiasnoback/behat-expect-exception": "^v0.3.0",
"behat/gherkin": "~v4.11.0"
"behat/gherkin": "~v4.11.0",
"rector/rector": "dev-main"
},
"suggest": {
"ext-intl": "intl extension is required for formula support",
Expand Down
80 changes: 80 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\ChangeNestedIfsToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;

/**
* How to run:
*
* ```bash
* composer require rector/rector --dev
* ./vendor/bin/rector process
* ```
*/
return RectorConfig::configure()
->withAutoloadPaths([
file_exists(__DIR__ . '/../../autoload.php') ? __DIR__ . '/../../autoload.php' : null,
file_exists(__DIR__ . '/vendor/autoload.php') ? __DIR__ . '/vendor/autoload.php' : null,
])
->withCache(__DIR__ . '/../../../runtime/cache/rector', FileCacheStorage::class)
->withPreparedSets(deadCode: true, codeQuality: true)
->withPhpSets(php83: true, php84: true)
->withPhpVersion(\Rector\ValueObject\PhpVersion::PHP_84)
->withoutParallel()
->withPaths([
__DIR__ . '/src',
])
->withRules([
RemoveAlwaysElseRector::class,
ChangeNestedIfsToEarlyReturnRector::class,
ChangeIfElseValueAssignToEarlyReturnRector::class,
ChangeNestedForeachIfsToEarlyContinueRector::class,
])
->withSkip([
// Too many places where json_decode was used intentionally on wrong data =\
JsonThrowOnErrorRector::class,

// Frequently used for debug. Maybe, such places should be annotated with @noRector?
SimplifyUselessVariableRector::class,

// Legacy modules are full of `_doSomeShit()` methods that are likely called as `$this->_do{$operation}`
RemoveUnusedPrivateMethodRector::class,

// Does not make sense for us
SimplifyRegexPatternRector::class,

// Requires whole project autoloaded to work well
RemoveUnusedPrivateClassConstantRector::class,

// don't refactor with `empty` check function
DisallowedEmptyRuleFixerRector::class,
SimplifyEmptyArrayCheckRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,

// do not refactor `query` attribute like " . '$select' . " to 'SELECT $select ...'
JoinStringConcatRector::class,

// do not refactor php version id checkers
RemovePhpVersionIdCheckRector::class,
RemoveExtraParametersRector::class,

SwitchNegatedTernaryRector::class,
]);
4 changes: 3 additions & 1 deletion src/EntityInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/CannotReassignException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\Exception;

use Exception;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/EntityNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\Exception;

use hiqdev\php\billing\ExceptionInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/NotSupportedException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\Exception;

use Exception;
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/UnknownEntityException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\Exception;

use hiqdev\php\billing\ExceptionInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing;

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Money/MultipliedMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ private function __construct(

/**
* @param numeric-string $amount
* @param string $currencyCode
*/
public static function create(string $amount, string $currencyCode): MultipliedMoney
{
Expand Down Expand Up @@ -87,7 +86,7 @@ private static function calculateMultiplierToInteger(string $amount): int
}

[, $fraction] = explode('.', $amount, 2);
return (int)('1' . implode(array_fill(0, strlen($fraction), 0)));
return (int)('1' . implode('', array_fill(0, strlen($fraction), 0)));
}

/**
Expand Down
20 changes: 6 additions & 14 deletions src/action/AbstractAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
*/
abstract class AbstractAction implements \JsonSerializable, ActionInterface
{
/** @var int */
protected $id;

/** @var TypeInterface */
protected $type;

Expand All @@ -55,25 +52,21 @@
/** @var ActionInterface */
protected $parent;

protected float $fractionOfMonth = 0.0;

/**
* @param SaleInterface $sale
* @param ActionInterface $parent
* @param int $id
*/
public function __construct(
$id,
protected $id,
TypeInterface $type,
TargetInterface $target,
QuantityInterface $quantity,
CustomerInterface $customer,
DateTimeImmutable $time,
SaleInterface $sale = null,
ActionState $state = null,
ActionInterface $parent = null,
float $fractionOfMonth = 0.0
?SaleInterface $sale = null,
?ActionState $state = null,
?ActionInterface $parent = null,
protected float $fractionOfMonth = 0.0
) {
$this->id = $id;
$this->type = $type;
$this->target = $target;
$this->quantity = $quantity;
Expand All @@ -82,14 +75,13 @@
$this->sale = $sale;
$this->state = $state;
$this->parent = $parent;
$this->fractionOfMonth = $fractionOfMonth;
}

/**
* Provides unique string.
* Can be used to compare or aggregate actions.
*/
public function getUniqueString(): string

Check failure on line 84 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:84:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::getUniqueString (see https://psalm.dev/087)

Check failure on line 84 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:84:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::getUniqueString (see https://psalm.dev/087)
{
$parts = [
'buyer' => $this->customer->getUniqueId(),
Expand Down Expand Up @@ -157,7 +149,7 @@
return $this->time;
}

public function setTime(DateTimeImmutable $time)

Check failure on line 152 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:152:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setTime (see https://psalm.dev/087)

Check failure on line 152 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:152:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setTime (see https://psalm.dev/087)
{
$this->time = $time;
}
Expand All @@ -167,7 +159,7 @@
return $this->state;
}

public function setFinished(): void

Check failure on line 162 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:162:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setFinished (see https://psalm.dev/087)

Check failure on line 162 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:162:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setFinished (see https://psalm.dev/087)
{
$this->state = ActionState::finished();
}
Expand All @@ -188,7 +180,7 @@
/**
* {@inheritdoc}
*/
public function hasParent()

Check failure on line 183 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:183:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::hasParent (see https://psalm.dev/087)

Check failure on line 183 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:183:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::hasParent (see https://psalm.dev/087)
{
return $this->parent !== null;
}
Expand All @@ -198,7 +190,7 @@
return $this->id !== null;
}

public function setId($id)

Check failure on line 193 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:193:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setId (see https://psalm.dev/087)

Check failure on line 193 in src/action/AbstractAction.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/AbstractAction.php:193:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\AbstractAction::setId (see https://psalm.dev/087)
{
if ((string) $this->id === (string) $id) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/action/Action.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

use hiqdev\php\billing\price\PriceInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/action/ActionCreationDto.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/action/ActionFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

/**
Expand All @@ -21,5 +23,5 @@
* Creates action object.
* @return Action
*/
public function create(ActionCreationDto $dto);

Check failure on line 26 in src/action/ActionFactoryInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/ActionFactoryInterface.php:26:21: PossiblyUnusedMethod: Cannot find explicit calls to method hiqdev\php\billing\action\ActionFactoryInterface::create (but did find some potential callers) (see https://psalm.dev/087)

Check failure on line 26 in src/action/ActionFactoryInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/ActionFactoryInterface.php:26:21: PossiblyUnusedMethod: Cannot find explicit calls to method hiqdev\php\billing\action\ActionFactoryInterface::create (but did find some potential callers) (see https://psalm.dev/087)
}
4 changes: 3 additions & 1 deletion src/action/ActionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

use DateTimeImmutable;
Expand Down Expand Up @@ -73,7 +75,7 @@
*/
public function isFinished(): ?bool;

public function getParent(): ?ActionInterface;

Check failure on line 78 in src/action/ActionInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/ActionInterface.php:78:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\ActionInterface::getParent (see https://psalm.dev/087)

Check failure on line 78 in src/action/ActionInterface.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

PossiblyUnusedMethod

src/action/ActionInterface.php:78:21: PossiblyUnusedMethod: Cannot find any calls to method hiqdev\php\billing\action\ActionInterface::getParent (see https://psalm.dev/087)

public function getState(): ?ActionState;

Expand Down
4 changes: 3 additions & 1 deletion src/action/ActionState.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

/**
Expand Down
4 changes: 3 additions & 1 deletion src/action/TemporaryAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

use hiqdev\php\billing\customer\CustomerInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/action/TemporaryActionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* PHP Billing Library
*
Expand All @@ -7,7 +10,6 @@
* @license BSD-3-Clause
* @copyright Copyright (c) 2017-2020, HiQDev (http://hiqdev.com/)
*/

namespace hiqdev\php\billing\action;

/**
Expand Down
Loading
Loading