Skip to content

Commit

Permalink
Merge pull request #803 from ruudk/phpstan
Browse files Browse the repository at this point in the history
Switch from Psalm to PHPStan level 6
  • Loading branch information
frederikbosch authored Nov 25, 2024
2 parents e82ae81 + 37cc563 commit 51ebdac
Show file tree
Hide file tree
Showing 61 changed files with 483 additions and 514 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.neon]
indent_style = tab
4 changes: 0 additions & 4 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Remove Psalm when on PHP 8.4
if: ${{ matrix.php == '8.4' }}
run: composer remove --dev psalm/plugin-phpunit vimeo/psalm

- uses: "ramsey/composer-install@v3"

- name: Run phpbench
Expand Down
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,13 @@ jobs:
- name: Set up locales
run: ./hack/setup-locales.sh

- name: Remove Psalm when on PHP 8.4
if: ${{ matrix.php == '8.4' }}
run: composer remove --dev psalm/plugin-phpunit vimeo/psalm

- uses: "ramsey/composer-install@v3"

- name: Run tests
run: vendor/bin/phpunit

psalm:
name: Psalm
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
Expand All @@ -81,13 +77,13 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
php-version: '8.4'
extensions: bcmath, gmp, intl, dom, mbstring

- uses: "ramsey/composer-install@v3"

- name: Psalm
run: vendor/bin/psalm
- name: PHPStan
run: vendor/bin/phpstan

docs:
name: Docs
Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
"doctrine/instantiator": "^1.5.0 || ^2.0",
"florianv/exchanger": "^2.8.1",
"florianv/swap": "^4.3.0",
"moneyphp/iso-currencies": "^3.4",
"moneyphp/crypto-currencies": "^1.1.0",
"moneyphp/iso-currencies": "^3.4",
"php-http/message": "^1.16.0",
"php-http/mock-client": "^1.6.0",
"phpbench/phpbench": "^1.2.5",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5.9",
"psalm/plugin-phpunit": "^0.18.4",
"psr/cache": "^1.0.1 || ^2.0 || ^3.0",
"vimeo/psalm": "~5.20.0"
"ticketswap/phpstan-error-formatter": "^1.1"
},
"suggest": {
"ext-gmp": "Calculate without integer limits",
Expand Down Expand Up @@ -73,7 +75,8 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true,
"infection/extension-installer": true,
"php-http/discovery": false
"php-http/discovery": false,
"phpstan/extension-installer": true
},
"sort-packages": true
},
Expand All @@ -90,7 +93,7 @@
"test": [
"vendor/bin/phpbench run",
"vendor/bin/phpunit",
"vendor/bin/psalm",
"vendor/bin/phpstan",
"vendor/bin/phpcs"
],
"test-coverage": [
Expand Down
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
parameters:
level: 6
paths:
- src
- tests
errorFormat: ticketswap
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
ignoreErrors:
-
identifier: staticMethod.alreadyNarrowedType
path: tests/*
-
identifier: method.alreadyNarrowedType
path: tests/*
74 changes: 0 additions & 74 deletions psalm.xml

This file was deleted.

5 changes: 2 additions & 3 deletions resources/generate-money-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ trait MoneyFactory
* $fiveDollar = Money::USD(500);
* </code>
*
* @param array $arguments
* @psalm-param non-empty-string $method
* @psalm-param array{numeric-string|int} $arguments
* @param non-empty-string $method
* @param array{numeric-string|int} $arguments
*
* @throws InvalidArgumentException If amount is not integer(ish).
*
Expand Down
4 changes: 2 additions & 2 deletions resources/generate-teller-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ trait TellerFactory
* $teller = Teller::USD();
* </code>
*
* @param non-empty-string $method
* @param array{0?: int} $arguments
* @param non-empty-string $method
* @param array{0?: Money::ROUND_*} $arguments
*/
public static function __callStatic(string $method, array $arguments): Teller
{
Expand Down
82 changes: 41 additions & 41 deletions src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,132 +21,132 @@ interface Calculator
* Retrieves a positive value if $a > $b.
* Retrieves zero if $a == $b
*
* @psalm-param numeric-string $a
* @psalm-param numeric-string $b
* @phpstan-param numeric-string $a
* @phpstan-param numeric-string $b
*
* @psalm-pure
* @phpstan-pure
*/
public static function compare(string $a, string $b): int;

/**
* Add added to amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $addend
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $addend
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function add(string $amount, string $addend): string;

/**
* Subtract subtrahend from amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $subtrahend
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $subtrahend
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function subtract(string $amount, string $subtrahend): string;

/**
* Multiply amount with multiplier.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $multiplier
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $multiplier
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function multiply(string $amount, string $multiplier): string;

/**
* Divide amount with divisor.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $divisor
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $divisor
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @throws InvalidArgumentException when $divisor is zero.
*
* @psalm-pure
* @phpstan-pure
*/
public static function divide(string $amount, string $divisor): string;

/**
* Round number to following integer.
*
* @psalm-param numeric-string $number
* @phpstan-param numeric-string $number
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function ceil(string $number): string;

/**
* Round number to preceding integer.
*
* @psalm-param numeric-string $number
* @phpstan-param numeric-string $number
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function floor(string $number): string;

/**
* Returns the absolute value of the number.
*
* @psalm-param numeric-string $number
* @phpstan-param numeric-string $number
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function absolute(string $number): string;

/**
* Round number, use rounding mode for tie-breaker.
*
* @psalm-param numeric-string $number
* @psalm-param Money::ROUND_* $roundingMode
* @phpstan-param numeric-string $number
* @phpstan-param Money::ROUND_* $roundingMode
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function round(string $number, int $roundingMode): string;

/**
* Share amount among ratio / total portions.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $ratio
* @psalm-param numeric-string $total
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $ratio
* @phpstan-param numeric-string $total
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @psalm-pure
* @phpstan-pure
*/
public static function share(string $amount, string $ratio, string $total): string;

/**
* Get the modulus of an amount.
*
* @psalm-param numeric-string $amount
* @psalm-param numeric-string $divisor
* @phpstan-param numeric-string $amount
* @phpstan-param numeric-string $divisor
*
* @psalm-return numeric-string
* @phpstan-return numeric-string
*
* @throws InvalidArgumentException when $divisor is zero.
*
* @psalm-pure
* @phpstan-pure
*/
public static function mod(string $amount, string $divisor): string;
}
Loading

0 comments on commit 51ebdac

Please sign in to comment.