Skip to content

Commit 79b2c12

Browse files
committed
first commit
0 parents  commit 79b2c12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4109
-0
lines changed

.github/workflows/push.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Push
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
permissions:
8+
contents: read
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.url || github.run_id }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
Linux-64:
16+
name: Tests on Linux 64-bit
17+
18+
runs-on: ubuntu-24.04
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
php-version:
24+
- '8.2'
25+
- '8.3'
26+
27+
steps:
28+
- name: git checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Install PHP with extensions
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: ${{ matrix.php-version }}
35+
extensions: bcmath
36+
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
37+
tools: none
38+
39+
- name: composer install
40+
run: composer install -n --prefer-dist
41+
42+
- name: Run tests
43+
if: matrix.php-version == '8.2'
44+
run: |
45+
./vendor/bin/phpunit \
46+
--configuration phpunit.xml.dist \
47+
--testsuite=unit
48+
49+
- name: Run tests with coverage
50+
if: matrix.php-version == '8.3'
51+
run: |
52+
XDEBUG_MODE=coverage ./vendor/bin/phpunit \
53+
--configuration phpunit.xml.dist \
54+
--testsuite=unit \
55+
--coverage-clover ./coverage.xml
56+
57+
- uses: codecov/codecov-action@v5
58+
if: matrix.php-version == '8.3'
59+
with:
60+
files: ./coverage.xml
61+
token: ${{ secrets.CODECOV_TOKEN }}
62+
verbose: true

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Saki Takamachi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# BcMath\Number Polyfill
2+
3+
[![Latest Stable Version](https://poser.pugx.org/saki/bcmath-number-polyfill/v)](https://packagist.org/packages/saki/bcmath-number-polyfill)
4+
[![Push](https://github.com/SakiTakamachi/BcMath-Number-Polyfill/actions/workflows/push.yml/badge.svg)](https://github.com/SakiTakamachi/BcMath-Number-Polyfill/actions/workflows/push.yml)
5+
[![codecov](https://codecov.io/gh/SakiTakamachi/BcMath-Number-Polyfill/graph/badge.svg?token=SEYCY57LRY)](https://codecov.io/gh/SakiTakamachi/BcMath-Number-Polyfill)
6+
[![License](https://poser.pugx.org/saki/bcmath-number-polyfill/license)](https://packagist.org/packages/saki/bcmath-number-polyfill)
7+
[![PHP Version Require](https://poser.pugx.org/saki/bcmath-number-polyfill/require/php)](https://packagist.org/packages/saki/bcmath-number-polyfill)
8+
9+
## Install
10+
11+
```
12+
composer require saki/bcmath-number-polyfill
13+
```
14+
15+
This library requires the BCMath extension.
16+
Also, since this is a polyfill, it does **not support** PHP 8.4 or higher. For PHP 8.2 and 8.3 only.
17+
18+
## Description
19+
20+
This is a polyfill for `BcMath\Number` class added in PHP 8.4.
21+
It achieves the same behavior as much as possible, but does **not support** operator overloading.
22+
23+
`RoundingMode` Enum is also included. However, if it has already been defined, it will not be defined twice.
24+
25+
New functions such as `bcround()` are not included in this library.
26+
27+
## How to use
28+
29+
You can treat it like anything added in PHP 8.4.
30+
31+
```
32+
use BcMath\Number;
33+
34+
$number = new Number('1.23');
35+
$rounded = $number->round(1, RoundingMode::AwayFromZero);
36+
37+
var_dump($rounded);
38+
```
39+
40+
result:
41+
```
42+
object(BcMath\Number)#3 (2) {
43+
["value"]=>
44+
string(3) "1.3"
45+
["scale"]=>
46+
int(1)
47+
}
48+
```

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "saki/bcmath-number-polyfill",
3+
"type": "library",
4+
"license": "MIT",
5+
"autoload": {
6+
"psr-4": {
7+
"BcMath\\": "src/BcMath/",
8+
"Saki\\Number\\": "src/Number/"
9+
},
10+
"classmap": ["src/Standard/RoundingMode.php"]
11+
},
12+
"authors": [
13+
{
14+
"name": "Saki Takamachi",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"php": "^8.3 || ^8.2",
20+
"ext-bcmath": "*"
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^11.4"
24+
}
25+
}

phpunit.xml.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="unit">
5+
<directory suffix=".phpt">tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">src</directory>
11+
</include>
12+
</source>
13+
</phpunit>

0 commit comments

Comments
 (0)