diff --git a/.github/workflows/acceptance.yml b/.github/workflows/acceptance.yml index 4378918..fb04458 100644 --- a/.github/workflows/acceptance.yml +++ b/.github/workflows/acceptance.yml @@ -7,12 +7,12 @@ jobs: test: strategy: matrix: - php-versions: ["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] + php-versions: ["8.0", "8.1", "8.2", "8.3", "8.4"] runs-on: ubuntu-latest name: Unit test steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP uses: shivammathur/setup-php@v2 with: @@ -39,11 +39,11 @@ jobs: name: Code standard steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.2" + php-version: "8.3" coverage: none env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -66,11 +66,11 @@ jobs: name: Code coverage steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP uses: shivammathur/setup-php@v2 with: - php-version: "8.2" + php-version: "8.3" coverage: xdebug env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index 46ee5b8..b0fd0fd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Utility library for numerics. Float versions of `ceil()`, `floor()` and `rand()` with precision. An open minded numeric parser, formatter, plus some additional functions. -Current version supports PHP `^7.4|^8.0`. +Current version supports PHP `^8.0`. ## Installation @@ -218,7 +218,8 @@ $numerics->setLocale('sv_SE'); // Set to Swedish | Version | PHP | | | --- | --- | --- | -| `2.3` | `^7.4\|^8.0` | Precision imrovements, negative precision in format() | +| `2.4` | `^8.0` | tbc | +| `2.3` | `^7.4\|^8.0` | Precision improvements, negative precision in format() | | `2.2` | `^7.4\|^8.0` | Default locale | | `2.1` | `^7.1\|^8.0` | | | `2.0` | `^7.1` | Instanceable, `format()` method, ability to specify locale | diff --git a/composer.json b/composer.json index 39eca07..3ea935f 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,10 @@ } }, "require": { - "php": "^7.4|^8.0" + "php": "^8.0" }, "require-dev": { - "phpunit/phpunit": "^9.0|^10.0", + "phpunit/phpunit": "^9.0 | ^10.0 | ^11.0", "php-coveralls/php-coveralls": "^2.4", "squizlabs/php_codesniffer": "^3.5" } diff --git a/phpunit.xml.dist b/phpunit.xml similarity index 100% rename from phpunit.xml.dist rename to phpunit.xml diff --git a/src/Numerics.php b/src/Numerics.php index cb2d5a9..314b5d9 100644 --- a/src/Numerics.php +++ b/src/Numerics.php @@ -15,18 +15,18 @@ class Numerics { /** @var int $precision Default precision */ - private $precision; + private int|null $precision; /** @var int $digits Relevant digits for floats */ - private $digits; + private int $digits; /** @var array $localization Localization data */ - private $localization; + private array $localization; /** * Constructor for this class * @param int|null $precision Default precision * @param string|null $locale Default locale to use as string */ - public function __construct(?int $precision = null, ?string $locale = null) + public function __construct(int|null $precision = null, string|null $locale = null) { $this->precision = $precision; $this->digits = PHP_FLOAT_DIG; @@ -54,7 +54,7 @@ public function setLocale(string $locale): void * @param int|null $precision Precision to apply * @return float Return floor with precision */ - public function floor(float $number, ?int $precision = null): float + public function floor(float $number, int|null $precision = null): float { $f = pow(10, $precision ?? $this->precision ?? 0); return floor($number * $f) / $f; @@ -66,7 +66,7 @@ public function floor(float $number, ?int $precision = null): float * @param int|null $precision Precision to apply * @return float Return ceil with precision */ - public function ceil(float $number, ?int $precision = null): float + public function ceil(float $number, int|null $precision = null): float { $f = pow(10, $precision ?? $this->precision ?? 0); return ceil($number * $f) / $f; @@ -76,9 +76,9 @@ public function ceil(float $number, ?int $precision = null): float * Round function with precision. * @param float $number The number to apply round to * @param int|null $precision Precision to apply - * @return float Return round with precision + * @return float Return round with precision */ - public function round(float $number, ?int $precision = null): float + public function round(float $number, int|null $precision = null): float { return round($number, $precision ?? $this->precision ?? 0); } @@ -90,7 +90,7 @@ public function round(float $number, ?int $precision = null): float * @param int|null $precision Precision to use * @return float|null Random number with precision (null if not solvable) */ - public function rand(float $min = 0, ?float $max = null, ?int $precision = null): ?float + public function rand(float $min = 0, float|null $max = null, int|null $precision = null): float|null { $rand_max = mt_getrandmax(); $max = is_null($max) ? $rand_max : $max; @@ -131,7 +131,7 @@ public function precision(float $number, bool $wide = false): int * @param int|float|string $numeric A numeric representation to parse * @return float|null Return as float (null if parsing failed) */ - public function parse($numeric): ?float + public function parse($numeric): float|null { $ts_found = false; @@ -200,7 +200,7 @@ public function parse($numeric): ?float * @param int|null $precision Precision to use, no rounding by default * @return string Numeric string */ - public function format(float $number, ?int $precision = null): string + public function format(float $number, int|null $precision = null): string { $precision = $precision ?? $this->precision ?? $this->precision($number); return number_format(