Skip to content

Commit

Permalink
PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
ruudk committed Nov 22, 2024
1 parent 51d982e commit 020474f
Show file tree
Hide file tree
Showing 55 changed files with 443 additions and 493 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
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
11 changes: 7 additions & 4 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 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: 4
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.

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 020474f

Please sign in to comment.