From 230a865e126e30dc36747971306809fcb6b73eda Mon Sep 17 00:00:00 2001 From: Patrik Foldes Date: Fri, 11 Feb 2022 15:01:51 +0300 Subject: [PATCH] Test new ci config (#7) * Test new ci config * fix ci config * fix ci * fix ci * Add doctrine/dbal ver 3 compat * Add support for safe v2 * Fix static analysis errors * Fix codestyle * Fix cs * Update dev packages * Add php 8.1 compat * Fix phpunit deprecated * Fix 8.1 compat --- .github/workflows/ci.yml | 339 +++++++++----------------- composer.json | 24 +- psalm.xml | 1 - src/BaseMoney.php | 34 +-- src/Exception/CannotCreateMoney.php | 2 +- src/Exception/CannotWorkWithMoney.php | 2 +- 6 files changed, 153 insertions(+), 249 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b33039c..c39ffe4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,246 +1,149 @@ -# https://help.github.com/en/categories/automating-your-workflow-with-github-actions -name: CI - +name: "CI" on: - - pull_request - - push - - + pull_request: + push: + branches: + - "master" env: - PHP_EXTENSIONS: dom, mbstring, xml, bcmath - PHP_INI_VALUES: memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On - + PHP_EXTENSIONS: "dom, mbstring, xml, bcmath" + PHP_INI_VALUES: "memory_limit=-1, assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On" jobs: unit: - name: Unit tests ${{matrix.php-versions}} - - runs-on: ubuntu-latest - + name: "Unit tests ${{matrix.php-version}}-${{matrix.operating-system}}-${{matrix.dependencies}}" + runs-on: ${{matrix.operating-system}} strategy: - fail-fast: false matrix: - operating-system: ['ubuntu-latest'] - php-versions: ['8.0'] - phpunit-versions: ['latest'] - compiler: - - default - + operating-system: + - "ubuntu-latest" + - "windows-latest" + php-version: + - "8.0" + - "8.1" + dependencies: + - "lowest" + - "highest" steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php-versions }}-composer- - - - name: Update composer - run: composer self-update - - - name: Update dependencies with composer - run: composer update --no-interaction --no-ansi --no-progress - - - name: Execute tests - run: vendor/bin/phpunit - + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install lowest dependencies" + if: ${{ matrix.dependencies == 'lowest' }} + run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" + - name: "Install highest dependencies" + if: ${{ matrix.dependencies == 'highest' }} + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute tests" + run: "vendor/bin/phpunit --fail-on-warning" psalm: - name: Psalm ${{matrix.php-versions}} - - runs-on: ubuntu-latest - + name: "Psalm" + runs-on: "ubuntu-latest" strategy: - fail-fast: false matrix: - operating-system: ['ubuntu-latest'] - php-versions: ['8.0'] - phpunit-versions: ['latest'] - compiler: - - default - + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php-versions }}-composer- - - - name: Update composer - run: composer self-update - - - name: Update dependencies with composer - run: composer update --no-interaction --no-ansi --no-progress - - - name: Execute Psalm - run: vendor/bin/psalm + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute Psalm" + run: "vendor/bin/psalm" stan: - name: PhpStan ${{matrix.php-versions}} - - runs-on: ubuntu-latest - + name: "PhpStan" + runs-on: "ubuntu-latest" strategy: - fail-fast: false matrix: - operating-system: ['ubuntu-latest'] - php-versions: ['8.0'] - phpunit-versions: ['latest'] - compiler: - - default - + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php-versions }}-composer- - - - name: Update composer - run: composer self-update - - - name: Update dependencies with composer - run: composer update --no-interaction --no-ansi --no-progress - - - name: Execute PhpStan - run: composer stan - + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute PhpStan" + run: "composer stan" code-style: - name: Code style ${{matrix.php-versions}} - - runs-on: ubuntu-latest - + name: "Code style" + runs-on: "ubuntu-latest" strategy: - fail-fast: false matrix: - operating-system: ['ubuntu-latest'] - php-versions: ['8.0'] - phpunit-versions: ['latest'] - compiler: - - default - + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php-versions }}-composer- - - - name: Update composer - run: composer self-update - - - name: Update dependencies with composer - run: composer update --no-interaction --no-ansi --no-progress - - - name: Execute PhpCs - run: composer cs - + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute PhpCs" + run: "composer cs" security: - name: Security check ${{matrix.php-versions}} - - runs-on: ubuntu-latest - + name: "Security check" + runs-on: "ubuntu-latest" strategy: - fail-fast: false matrix: - operating-system: ['ubuntu-latest'] - php-versions: ['8.0'] - phpunit-versions: ['latest'] - compiler: - - default - + operating-system: + - "ubuntu-latest" + php-version: + - "8.1" steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - extensions: ${{ env.PHP_EXTENSIONS }} - ini-values: ${{ env.PHP_INI_VALUES }} - tools: composer:v2 - coverage: none - - - name: Determine composer cache directory - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer - uses: actions/cache@v2 + - name: "Checkout" + uses: "actions/checkout@v2" + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php-versions }}-composer-${{ hashFiles('**/composer.json') }} - restore-keys: | - php${{ matrix.php-versions }}-composer- - - - name: Update composer - run: composer self-update - - - name: Update dependencies with composer - run: composer update --no-interaction --no-ansi --no-progress - - - name: Execute security check - run: composer sec \ No newline at end of file + coverage: "none" + php-version: "${{matrix.php-version}}" + extensions: "${{env.PHP_EXTENSIONS}}" + ini-values: "${{env.PHP_INI_VALUES}}" + tools: "composer:v2" + - name: "Update composer" + run: "composer self-update" + - name: "Install highest dependencies" + run: "composer update --no-interaction --no-progress --no-suggest" + - name: "Execute security check" + run: "composer sec" diff --git a/composer.json b/composer.json index 0c81560..b37a9d4 100644 --- a/composer.json +++ b/composer.json @@ -18,28 +18,30 @@ } ], "require": { - "php": "~8.0", + "php": "^8.0|^8.1", "ext-bcmath": "*", - "doctrine/dbal": "^2", - "moneyphp/money": "^4.0", - "thecodingmachine/safe": "^1.3" + "doctrine/dbal": "^2|^3", + "moneyphp/money": "^4.0.3", + "thecodingmachine/safe": "^1.3|^2" }, "require-dev": { "doctrine/coding-standard": "^9.0", - "phpstan/phpstan": "^0.12", - "phpunit/phpunit": "^9.5", - "roave/no-floaters": "^1.4", - "sensiolabs/security-checker": "^6.0", + "phpstan/phpstan": "^1.4", + "phpunit/phpunit": "^9.5.5", + "roave/no-floaters": "^1.5", "squizlabs/php_codesniffer": "^3.6", - "thecodingmachine/phpstan-safe-rule": "^1.0", - "vimeo/psalm": "^4.10" + "thecodingmachine/phpstan-safe-rule": "^1.1|^1.2", + "vimeo/psalm": "^4.20" }, "minimum-stability": "stable", "config": { "preferred-install": { "*": "dist" }, - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "autoload": { "psr-4": { diff --git a/psalm.xml b/psalm.xml index d7f7ed9..cf93af5 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,7 +3,6 @@ totallyTyped="true" resolveFromConfigFile="true" useDocblockTypes="true" - allowPhpStormGenerics="true" ignoreInternalFunctionFalseReturn="false" ignoreInternalFunctionNullReturn="false" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" diff --git a/src/BaseMoney.php b/src/BaseMoney.php index 335563d..a60342d 100644 --- a/src/BaseMoney.php +++ b/src/BaseMoney.php @@ -16,9 +16,9 @@ use function bcdiv; use function bcmul; use function Safe\preg_match; -use function Safe\substr; use function str_pad; use function strpos; +use function substr; use const STR_PAD_RIGHT; @@ -69,7 +69,7 @@ final private function __construct(string $amount, string $currency) ); } - $this->amount = static::toSubunits($amount); + $this->amount = self::toSubunits($amount); $this->currency = $currency; } @@ -121,7 +121,7 @@ final public static function create(string $amount, Currency $currency): self final public static function createFromMoney(self $money): self { - static::assertSameSubUnit($money, __FUNCTION__); + self::assertSameSubUnit($money, __FUNCTION__); return static::create($money->getAmount(), $money->getCurrency()); } @@ -143,42 +143,42 @@ final public function isSameCurrency(self $other): bool final public function equals(self $other): bool { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->equals($other->getLibMoney()); } final public function compare(self $other): int { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->compare($other->getLibMoney()); } final public function greaterThan(self $other): bool { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->greaterThan($other->getLibMoney()); } final public function greaterThanOrEqual(self $other): bool { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->greaterThanOrEqual($other->getLibMoney()); } final public function lessThan(self $other): bool { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->lessThan($other->getLibMoney()); } final public function lessThanOrEqual(self $other): bool { - static::assertSameSubUnit($other, __FUNCTION__); + self::assertSameSubUnit($other, __FUNCTION__); return $this->getLibMoney()->lessThanOrEqual($other->getLibMoney()); } @@ -188,7 +188,7 @@ final public function lessThanOrEqual(self $other): bool */ final public function getAmount(): string { - return $this->formatAmount(static::fromSubunits($this->amount)); + return $this->formatAmount(self::fromSubunits($this->amount)); } /** @@ -226,7 +226,7 @@ final public function add(self ...$addends): self $this->getLibMoney()->add( ...array_map( static function (self $addend): LibMoney { - static::assertSameSubUnit($addend, 'add'); + self::assertSameSubUnit($addend, 'add'); return $addend->getLibMoney(); }, @@ -242,7 +242,7 @@ final public function subtract(self ...$subtrahends): self $this->getLibMoney()->subtract( ...array_map( static function (self $subtrahend): LibMoney { - static::assertSameSubUnit($subtrahend, 'subtract'); + self::assertSameSubUnit($subtrahend, 'subtract'); return $subtrahend->getLibMoney(); }, @@ -276,7 +276,7 @@ final public function divide(int|string $divisor, int $roundingMode = LibMoney:: final public function mod(self $divisor): self { - static::assertSameSubUnit($divisor, __FUNCTION__); + self::assertSameSubUnit($divisor, __FUNCTION__); return self::createFromLibMoney( $this->getLibMoney()->mod($divisor->getLibMoney()) @@ -316,7 +316,7 @@ function (LibMoney $money): self { final public function ratioOf(self $money): string { - static::assertSameSubUnit($money, __FUNCTION__); + self::assertSameSubUnit($money, __FUNCTION__); return $this->getLibMoney()->ratioOf($money->getLibMoney()); } @@ -484,7 +484,7 @@ private static function fromSubunits(string $amount): string * * @phpstan-ignore-next-line */ - return bcdiv($amount, static::getSubunitMultiplier(), static::classSubunits()); + return bcdiv($amount, self::getSubunitMultiplier(), static::classSubunits()); } /** @@ -494,13 +494,13 @@ private static function fromSubunits(string $amount): string */ private static function toSubunits(string $amount): string { - return bcmul($amount, static::getSubunitMultiplier(), 0); + return bcmul($amount, self::getSubunitMultiplier(), 0); } private function createFromLibMoney(LibMoney $money): self { return self::create( - static::fromSubunits($money->getAmount()), + self::fromSubunits($money->getAmount()), Currency::create($money->getCurrency()->getCode()) ); } diff --git a/src/Exception/CannotCreateMoney.php b/src/Exception/CannotCreateMoney.php index 8cab2c3..869f6b7 100644 --- a/src/Exception/CannotCreateMoney.php +++ b/src/Exception/CannotCreateMoney.php @@ -4,7 +4,7 @@ namespace OnMoon\Money\Exception; -use function Safe\sprintf; +use function sprintf; final class CannotCreateMoney extends MoneyRuntimeError { diff --git a/src/Exception/CannotWorkWithMoney.php b/src/Exception/CannotWorkWithMoney.php index e8c111b..094e9f8 100644 --- a/src/Exception/CannotWorkWithMoney.php +++ b/src/Exception/CannotWorkWithMoney.php @@ -4,7 +4,7 @@ namespace OnMoon\Money\Exception; -use function Safe\sprintf; +use function sprintf; final class CannotWorkWithMoney extends MoneyLogicError {