Skip to content

Commit 1b0ccc9

Browse files
authored
Merge pull request #1 from fab2s/v2.x
Drop php<8.0
2 parents 0aedae3 + 0ae4280 commit 1b0ccc9

File tree

17 files changed

+872
-773
lines changed

17 files changed

+872
-773
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
on: [pull_request]
3+
jobs:
4+
tests:
5+
name: Math (PHP ${{ matrix.php-versions }} / Orchestra ${{ matrix.orchestra-versions }})
6+
runs-on: ubuntu-latest
7+
strategy:
8+
matrix:
9+
php-versions: [ '8.2', '8.1' ]
10+
orchestra-versions: [ '8.0', '9.0' ]
11+
exclude:
12+
- php-versions: 8.1
13+
orchestra-versions: 9.0
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-versions }}
23+
extensions: mbstring, dom, fileinfo, gmp, bcmath
24+
25+
- name: Get composer cache directory
26+
id: composer-cache
27+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
28+
29+
- name: Cache composer dependencies
30+
uses: actions/cache@v3
31+
with:
32+
path: ${{ steps.composer-cache.outputs.dir }}
33+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
34+
restore-keys: ${{ runner.os }}-composer-
35+
36+
- name: Remove composer.lock
37+
run: rm -f composer.lock
38+
39+
- name: Remove Pint
40+
run: composer remove "laravel/pint" --dev --no-update
41+
42+
- name: Install Orchestra ${{ matrix.orchestra-versions }}
43+
run: composer require "orchestra/testbench:^${{ matrix.orchestra-versions }}" --dev --no-update
44+
45+
- name: Install Composer dependencies
46+
run: composer install --no-progress --prefer-dist --optimize-autoloader
47+
48+
- name: Test with phpunit
49+
run: vendor/bin/phpunit

.github/workflows/qa.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: QA
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
types: [ opened, synchronize ]
8+
jobs:
9+
tests:
10+
name: Math QA
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: 8.2
21+
extensions: mbstring, dom, fileinfo, gmp, bcmath
22+
coverage: xdebug
23+
24+
- name: Get composer cache directory
25+
id: composer-cache
26+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
27+
28+
- name: Cache composer dependencies
29+
uses: actions/cache@v3
30+
with:
31+
path: ${{ steps.composer-cache.outputs.dir }}
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
33+
restore-keys: ${{ runner.os }}-composer-
34+
35+
- name: Remove composer.lock
36+
run: rm -f composer.lock
37+
38+
- name: Install Composer dependencies
39+
run: composer install --no-progress --prefer-dist --optimize-autoloader
40+
41+
- name: Check code style
42+
run: vendor/bin/pint --config pint.json --test
43+
44+
- name: Compute Coverage
45+
run: vendor/bin/phpunit --coverage-clover ./coverage.xml
46+
47+
- name: Upload coverage to Codecov
48+
uses: codecov/codecov-action@v3
49+
env:
50+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
51+
with:
52+
files: ./coverage.xml
53+
flags: unittests
54+
name: codecov-math

.php_cs

Lines changed: 0 additions & 141 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Math
22

3-
[![Build Status](https://travis-ci.com/fab2s/Math.svg?branch=master)](https://travis-ci.com/fab2s/Math) [![Total Downloads](https://poser.pugx.org/fab2s/math/downloads)](//packagist.org/packages/fab2s/math) [![Monthly Downloads](https://poser.pugx.org/fab2s/math/d/monthly)](//packagist.org/packages/fab2s/math) [![Latest Stable Version](https://poser.pugx.org/fab2s/math/v/stable)](https://packagist.org/packages/fab2s/math) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/fab2s/Math/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/fab2s/Math/?branch=master) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) [![License](https://poser.pugx.org/fab2s/math/license)](https://packagist.org/packages/fab2s/math)
3+
[![CI](https://github.com/fab2s/Math/actions/workflows/ci.yml/badge.svg)](https://github.com/fab2s/Math/actions/workflows/ci.yml) [![QA](https://github.com/fab2s/Math/actions/workflows/qa.yml/badge.svg)](https://github.com/fab2s/Math/actions/workflows/qa.yml) [![codecov](https://codecov.io/gh/fab2s/Math/graph/badge.svg?token=6JD33CQLE3)](https://codecov.io/gh/fab2s/Math) [![Total Downloads](https://poser.pugx.org/fab2s/math/downloads)](//packagist.org/packages/fab2s/math) [![Monthly Downloads](https://poser.pugx.org/fab2s/math/d/monthly)](//packagist.org/packages/fab2s/math) [![Latest Stable Version](https://poser.pugx.org/fab2s/math/v/stable)](https://packagist.org/packages/fab2s/math) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com) [![License](https://poser.pugx.org/fab2s/math/license)](https://packagist.org/packages/fab2s/math)
44

55
A fluent [bcmath](https://php.net/bcmath) based _Helper_ to handle high precision calculus in base 10 with a rather strict approach (want precision for something right?).
66
It does not try to be smart and just fails without `bcmath`, but it does auto detect [GMP](https://php.net/GMP) for faster base conversions.
@@ -19,7 +19,7 @@ composer require "fab2s/math"
1919

2020
## Prerequisites
2121

22-
`Math` requires [bcmath](https://php.net/bcmath), [GMP](https://php.net/GMP) is auto detected and used when available for faster base conversions (up to 62).
22+
`Math` requires [bcmath](https://php.net/bcmath), [GMP](https://php.net/GMP) is auto-detected and used when available for faster base conversions (up to 62).
2323

2424
## In practice
2525

@@ -109,8 +109,8 @@ Doing so is actually faster than casting a pre-existing instance to string becau
109109

110110
Arguments should be string or `Math`, but it is _ok_ to use integers up to `INT_(32|64)`.
111111

112-
**DO NOT** use `floats` as casting them to `string` may result in local dependent format, such as using a coma instead of a dot for decimals or just turn them exponential notation which is not supported by bcmath.
113-
The way floats are handled in general and by PHP in particular is the very the reason why `bcmath` exists, so even if you trust your locale settings, using floats still kinda defeats the purpose of using such lib.
112+
**YOU SHOULD NOT** use `floats` as casting them to `string` may result in local dependent format, such as using a coma instead of a dot for decimals or just turn them exponential notation which is not supported by bcmath.
113+
The way floats are handled in general and by PHP in particular is the very reason why `bcmath` exists, so even if you trust your locale settings, using floats still kinda defeats the purpose of using such lib.
114114

115115
## Internal precision
116116

@@ -126,9 +126,35 @@ $number = (new Math('100'))->div('3'); // uses precision 18
126126
$number->setPrecision(14); // will use precision 14 for any further calculations
127127
```
128128

129+
## Laravel
130+
131+
For those using [Laravel](https://laravel.com/), `Math` comes with a Laravel caster: [MathCaster](./src/Laravel/MathCast.php) which you can use to directly cast your model properties.
132+
133+
````php
134+
use fab2s\Math\Laravel\MathCast;
135+
136+
class MyModel extends Model
137+
{
138+
protected $casts = [
139+
'not_nullable' => MathCast::class,
140+
'nullable' => MathCast::class . ':nullable',
141+
];
142+
}
143+
144+
$model = new MyModel;
145+
146+
$model->not_nullable = 41;
147+
$model->not_nullable->add(1)->eq(42); // true
148+
149+
$model->not_nullable = null; // throw a NotNullableException
150+
151+
$model->nullabe = null; // is ok
152+
153+
````
154+
129155
## Requirements
130156

131-
`Math` is tested against php 7.1, 7.2, 7.3, 7.4 and 8.0
157+
`Math` is tested against php 8.1 and 8.2. Additionally, MathCast is tested against Laravel 10 and 11.
132158

133159
## Contributing
134160

composer.json

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,47 @@
66
"name" : "Fabrice de Stefanis"
77
}],
88
"keywords" : [
9+
"math",
910
"PHP",
1011
"Simple",
1112
"Base10",
1213
"decimal",
1314
"BcMath",
14-
"HighPrecision"
15+
"HighPrecision",
16+
"laravel"
1517
],
1618
"license" : [
1719
"MIT"
1820
],
1921
"require" : {
20-
"php": ">=7.1",
21-
"ext-bcmath": "*"
22+
"php": "^8.1",
23+
"ext-bcmath": "*",
24+
"fab2s/context-exception": "^2.0|^3.0"
2225
},
2326
"require-dev": {
24-
"phpunit/phpunit": "~7.0|~8.0"
27+
"phpunit/phpunit": "^10.0",
28+
"laravel/pint": "^1.11",
29+
"orchestra/testbench": "^8.0|^9.0"
2530
},
2631
"autoload": {
27-
"classmap": [
28-
"src"
29-
]
32+
"psr-4": {
33+
"fab2s\\Math\\": "src"
34+
}
3035
},
3136
"autoload-dev": {
3237
"psr-4": {
33-
"fab2s\\Math\\Tests\\": "tests/"
38+
"fab2s\\Math\\Tests\\": "tests"
3439
}
3540
},
41+
"scripts": {
42+
"post-update-cmd": [
43+
"rm -rf .*.cache"
44+
],
45+
"post-install-cmd": [
46+
"rm -rf .*.cache"
47+
],
48+
"fix": "@php vendor/bin/pint --config pint.json"
49+
},
3650
"suggest": {
3751
"ext-gmp": "For faster Math::baseConvert up to base62"
3852
}

0 commit comments

Comments
 (0)