Skip to content

Commit a162de9

Browse files
authored
Bump php (#2)
* Bump php * doc * strict immutable stan * benchmarks * polishing * fix ci * MathCast * polish
1 parent 1b0ccc9 commit a162de9

22 files changed

Lines changed: 2458 additions & 218 deletions

.github/workflows/ci.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
php-versions: [ '8.2', '8.1' ]
10-
orchestra-versions: [ '8.0', '9.0' ]
9+
php-versions: [ '8.4', '8.3', '8.2', '8.1' ]
10+
orchestra-versions: [ '8.0', '9.0', '10.0' ]
1111
exclude:
1212
- php-versions: 8.1
1313
orchestra-versions: 9.0
14+
- php-versions: 8.1
15+
orchestra-versions: 10.0
1416

1517
steps:
1618
- name: Checkout
17-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1820

1921
- name: Setup PHP
2022
uses: shivammathur/setup-php@v2
@@ -24,10 +26,10 @@ jobs:
2426

2527
- name: Get composer cache directory
2628
id: composer-cache
27-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
29+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2830

2931
- name: Cache composer dependencies
30-
uses: actions/cache@v3
32+
uses: actions/cache@v4
3133
with:
3234
path: ${{ steps.composer-cache.outputs.dir }}
3335
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
@@ -36,8 +38,8 @@ jobs:
3638
- name: Remove composer.lock
3739
run: rm -f composer.lock
3840

39-
- name: Remove Pint
40-
run: composer remove "laravel/pint" --dev --no-update
41+
- name: Remove Qa / bench libs
42+
run: composer remove "laravel/pint" "brick/math" --dev --no-update
4143

4244
- name: Install Orchestra ${{ matrix.orchestra-versions }}
4345
run: composer require "orchestra/testbench:^${{ matrix.orchestra-versions }}" --dev --no-update
@@ -46,4 +48,4 @@ jobs:
4648
run: composer install --no-progress --prefer-dist --optimize-autoloader
4749

4850
- name: Test with phpunit
49-
run: vendor/bin/phpunit
51+
run: composer test

.github/workflows/qa.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ jobs:
1212

1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616

1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: 8.2
20+
php-version: 8.4
2121
extensions: mbstring, dom, fileinfo, gmp, bcmath
2222
coverage: xdebug
2323

2424
- name: Get composer cache directory
2525
id: composer-cache
26-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
26+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2727

2828
- name: Cache composer dependencies
29-
uses: actions/cache@v3
29+
uses: actions/cache@v4
3030
with:
3131
path: ${{ steps.composer-cache.outputs.dir }}
3232
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
@@ -39,16 +39,18 @@ jobs:
3939
run: composer install --no-progress --prefer-dist --optimize-autoloader
4040

4141
- name: Check code style
42-
run: vendor/bin/pint --config pint.json --test
42+
run: composer fix
43+
44+
- name: PHPStan src
45+
run: composer stan
46+
47+
- name: PHPStan tests
48+
run: composer stan-tests
4349

4450
- name: Compute Coverage
4551
run: vendor/bin/phpunit --coverage-clover ./coverage.xml
4652

4753
- name: Upload coverage to Codecov
48-
uses: codecov/codecov-action@v3
49-
env:
50-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
54+
uses: codecov/codecov-action@v4
5155
with:
52-
files: ./coverage.xml
53-
flags: unittests
54-
name: codecov-math
56+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/vendor
22
.*.cache
3+
.phpstan
34
composer.lock
5+
/cov

CHANGELOG.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/).
7+
8+
## [Unreleased]
9+
10+
## [3.0.0] - 2026-02-08
11+
12+
### Changed
13+
14+
- **BREAKING:** `Math` is now immutable by default — every operation returns a new instance, leaving the original unchanged
15+
- `MathImmutable` replaced by `MathMutable` — mutability is now the explicit opt-in for performance-sensitive hot loops
16+
- `__toString()` bypasses redundant regex validation for better performance
17+
- PHPStan level 9 compliance for `src/`
18+
- GitHub Actions workflows updated to latest action versions
19+
20+
### Added
21+
22+
- `MathMutableCast` — Laravel Eloquent cast that returns `MathMutable` instances. Use `MathMutableCast::class` (with optional `:nullable`) instead of `MathCast::class` for mutable cast attributes. Separate cast classes enable proper static type resolution. **Upgrading from v2:** since `Math` is now immutable, existing Laravel models that rely on in-place mutation of cast attributes should switch from `MathCast::class` to `MathMutableCast::class` to restore the previous behavior.
23+
- `MathMutable` — mutable variant of `Math` where operations modify the instance in place. Extends `Math` and is accepted anywhere `Math` is type-hinted.
24+
- `negate()` — flip sign, zero stays zero
25+
- `clamp($min, $max)` — clip value between bounds
26+
- `quotientAndRemainder($divisor)` — returns `[$quotient, $remainder]` in one call
27+
- `isZero()` — precision-aware zero check
28+
- `isNegative()` — complement to `isPositive()`
29+
- `isEven()` / `isOdd()` — integer parity checks, return `false` for non-integers
30+
- `getScale()` — number of meaningful decimal places (normalized)
31+
- `getIntegralPart()` — part before the decimal point (normalized, `-0` becomes `0`)
32+
- `getFractionalPart()` — part after the decimal point (normalized, trailing zeros stripped)
33+
- `declare(strict_types=1)` in all source files
34+
- `phpstan-tests.neon` — dedicated PHPStan configuration for tests at level 5
35+
36+
### Fixed
37+
38+
- `toBase()` / `fromBase()` now preserve the sign of negative numbers instead of silently stripping it — `Math::number('-42')->toBase(16)` returns `'-2a'` and `Math::fromBase('-2a', 16)` returns `'-42'`
39+
- `fromBase()` now normalizes input case for bases <= 36 — `Math::fromBase('FF', 16)` works consistently with and without GMP
40+
- `format()` now works correctly with immutable default (captures `abs()` return value)
41+
- `bcDec2Base()` properly initializes result as `'0'`
42+
43+
### Removed
44+
45+
- `MathImmutable` — no longer needed, `Math` itself is now immutable
46+
47+
## [2.0.0] - 2024-04-24
48+
49+
### Added
50+
51+
- `MathCast` — Laravel Eloquent cast for `Math` instances with nullable support
52+
53+
### Changed
54+
55+
- Minimum PHP version raised to 8.1
56+
57+
### Removed
58+
59+
- PHP < 8.1 support
60+
61+
## [1.0.1] - 2021-06-16
62+
63+
### Added
64+
65+
- PHP 8.0 support
66+
67+
## [1.0.0] - 2019-07-31
68+
69+
Initial release.
70+
71+
[Unreleased]: https://github.com/fab2s/Math/compare/3.0.0...HEAD
72+
[3.0.0]: https://github.com/fab2s/Math/compare/2.0.0...3.0.0
73+
[2.0.0]: https://github.com/fab2s/Math/compare/1.0.1...2.0.0
74+
[1.0.1]: https://github.com/fab2s/Math/compare/1.0.0...1.0.1
75+
[1.0.0]: https://github.com/fab2s/Math/releases/tag/1.0.0

0 commit comments

Comments
 (0)