Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick money (butchering this library for the glory of satan, and CPU cycles) #634

Merged
merged 48 commits into from
May 2, 2021
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8eda988
This patch attempts to make quick money out of `moneyphp/money`
Ocramius Apr 13, 2021
5b39800
Adapted PHPUnit tests to comply with the new PHPUnit 9.5+ signatures
Ocramius Apr 13, 2021
df44eed
Removed `symfony/phpunit-bridge`, which is just noise (always has been)
Ocramius Apr 13, 2021
d9c6238
Removed deprecation handler environment variables, now unused
Ocramius Apr 13, 2021
4eafa82
Compatibility with PHPUnit 9.5+ - if we expect deprecations to be rai…
Ocramius Apr 13, 2021
8d25eb5
Added simplistic benchmarks about money instantiation, comparison and…
Ocramius Apr 13, 2021
f004690
Added benchmarks for `Money::sum()`, `Money::min()`, `Money::max()` a…
Ocramius Apr 13, 2021
ca05b46
Added benchmarks for `Number::fromString()`, which is used a lot in n…
Ocramius Apr 13, 2021
fa42867
Run benchmarks as part of `composer test`, to avoid them bit-rotting …
Ocramius Apr 13, 2021
809b12d
Imported global functions to allow OpCache to optimize away well-know…
Ocramius Apr 13, 2021
e094533
Enforcing `Currency#__construct()` to require a `string` as argument,…
Ocramius Apr 13, 2021
b009ce2
Inlined fetching of `Calculator` inside `Money` to avoid calling `get…
Ocramius Apr 13, 2021
f16dbd3
Removed the need to create a `Number` instance in `BcMathCalculator#m…
Ocramius Apr 13, 2021
9bcc47e
Removed `newInstance` private constructor: can be inlined where relevant
Ocramius Apr 13, 2021
25602b9
Simplified `Money#equals()` to only check currency equality when amou…
Ocramius Apr 13, 2021
8c8639c
Directly checking equality of two currencies at engine level
Ocramius Apr 13, 2021
ecdce7d
Removed `func_num_args()` magic method logic, replaced by inlined `co…
Ocramius Apr 13, 2021
57bb76f
In `BcMathCalculator`, removing the need to cast to a `Number` when r…
Ocramius Apr 13, 2021
b582575
Correctly referencing `self::parseFractionalPart()` from within `Numb…
Ocramius Apr 13, 2021
1f838b7
When the engine supports an integer value, use a simple `(string) (in…
Ocramius Apr 13, 2021
8cdbb66
Removed `assertOperand()`, since we can ensure that a `numeric-string…
Ocramius Apr 13, 2021
5298583
Removed `assertRoundingMode()`, which can be enforced at type level, …
Ocramius Apr 13, 2021
48e765f
Simplified `Number::fromString()` to internally use `explode()` inste…
Ocramius Apr 13, 2021
e1e091c
Bumping to PHP 8 minimum as per convo with @frederikbosch @ https://g…
Ocramius Apr 15, 2021
7462d54
Upgraded sources to PHP 8 type declarations, reworked internal number…
Ocramius Apr 15, 2021
a2c2554
Brought type inference to 100% of the codebase (tests still missing)
Ocramius Apr 15, 2021
0d1ec59
Commit current `composer.lock` to make builds more stable
Ocramius Apr 16, 2021
f2890ba
Applied detailed type-checking to the unit test suite
Ocramius Apr 16, 2021
0c7d705
Stricter type checks around invalid operands, hunting down unused/red…
Ocramius Apr 16, 2021
796bd9c
Applied automated CS fixes, improved github actions setup to run psal…
Ocramius Apr 16, 2021
6cc8a20
Removed phpstan and phpspec dependencies that are not in use
Ocramius Apr 16, 2021
b815e26
Added `roave/infection-static-analysis-plugin` and configured a minim…
Ocramius Apr 16, 2021
6a5dcd1
Hunted down a few easy-fix mutants that were just about migrating php…
Ocramius Apr 16, 2021
2d359ac
Made calculators completely inflexible and static
Ocramius Apr 16, 2021
6504e33
Documented hat a type-checker is pretty much required when using this…
Ocramius Apr 16, 2021
6fb8f8c
Sorted `scripts` section in `composer.json` to comply with `ergebnis/…
Ocramius Apr 16, 2021
61fa7b4
Removed prophecy mocks from phpunit tests, removed `phpspec/prophecy-…
Ocramius Apr 16, 2021
0689d3c
Updated `MoneyFactory` static methods to require `numeric-string|int`…
Ocramius Apr 16, 2021
7876b8f
Restricted test coverage to individual tested units of code
Ocramius Apr 16, 2021
dc3ce62
Moved division- and modulo-by-zero exception throwing into the `Calcu…
Ocramius Apr 22, 2021
9758d5f
Removed `is_int()` check on `$amount` passed to `Money` constructor
Ocramius Apr 22, 2021
7790e52
Removed `PhpCalculator`: since we require `ext-bcmath`, there is no n…
Ocramius Apr 22, 2021
eb32c53
Removed unused `Money::fromFloat()`, since we no longer operate with …
Ocramius Apr 22, 2021
9496d09
Replaced `(float)` cast with `sprintf('%.14F', ...)`, as it is more p…
Ocramius Apr 22, 2021
91c8091
Removd test reference to `Number::fromFloat()` (no longer existing)
Ocramius Apr 22, 2021
756649c
Revert removal of `Money::fromFloat()`
Ocramius Apr 23, 2021
8e0630f
Rewrote `AggregateCurrencies` to use a rewindable `AppendIterator` in…
Ocramius Apr 23, 2021
8df0b26
Use assertions statically (since they are declared as static methods …
Ocramius Apr 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
/.php_cs.dist export-ignore
/.scrutinizer.yml export-ignore
Dockerfile export-ignore
/benchmark/ export-ignore
/hack/ export-ignore
/phpspec.ci.yml export-ignore
/phpbench.json export-ignore
/phpspec.yml.dist export-ignore
/phpstan-baseline.neon export-ignore
/phpstan.neon.dist export-ignore
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Checks

on:
push:
branches:
- master
pull_request:

jobs:
Expand All @@ -13,7 +11,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Install
uses: docker://composer
Expand All @@ -36,7 +34,7 @@ jobs:

# steps:
# - name: Checkout code
# uses: actions/checkout@v1
# uses: actions/checkout@v2

# - name: Roave BC Check
# uses: docker://nyholm/roave-bc-check-ga
72 changes: 58 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,45 @@ name: CI

on:
push:
branches:
- master
pull_request:

jobs:
build-lowest-version:
lowest-version-tests:
name: Build lowest version
runs-on: ubuntu-latest

steps:
- name: Set up PHP
uses: shivammathur/setup-php@1.7.0
uses: shivammathur/setup-php@v2
with:
php-version: '5.6'
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
php-version: '8.0'
extensions: bcmath, gmp, intl, dom, mbstring

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Set up locales
run: ./hack/setup-locales.sh

- name: Download dependencies
run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest --prefer-lowest
run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest --prefer-lowest --classmap-authoritative

- name: Run tests
run: composer test

build:
tests:
name: Build
runs-on: ubuntu-latest
strategy:
max-parallel: 10
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
php: ['8.0']

steps:
- name: Set up PHP
uses: shivammathur/setup-php@1.6.2
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, gmp, intl, dom, mbstring
Expand All @@ -52,17 +49,64 @@ jobs:
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Set up locales
run: ./hack/setup-locales.sh

- name: Download dependencies
run: composer update --no-ansi --prefer-stable --prefer-dist --no-interaction --no-progress --no-suggest
run: composer install --classmap-authoritative

- name: Run tests
run: composer test

psalm:
name: Psalm
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: bcmath, gmp, intl, dom, mbstring

- name: Download dependencies
run: composer install --classmap-authoritative

- name: Psalm
run: vendor/bin/psalm

mutation-tests:
name: Infection
runs-on: ubuntu-latest
needs:
- tests
- psalm

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: bcmath, gmp, intl, dom, mbstring
coverage: pcov

- name: Set up locales
run: ./hack/setup-locales.sh

- name: Download dependencies
run: composer install --classmap-authoritative

- name: Psalm
run: vendor/bin/roave-infection-static-analysis-plugin

docs:
name: Docs
runs-on: ubuntu-latest
Expand All @@ -74,7 +118,7 @@ jobs:
architecture: 'x64'

- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Install dependencies
run: |
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/phpstan.entrypoint

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/psalm.entrypoint

This file was deleted.

53 changes: 10 additions & 43 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,25 @@ name: Static analysis

on:
push:
branches:
- master
pull_request:

jobs:
phpstan:
name: PHPStan
phpcs:
name: PHP-CodeSniffer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Install
uses: docker://composer
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
args: install --ignore-platform-reqs --no-ansi --no-suggest
php-version: '8.0'
extensions: bcmath, gmp, intl, dom, mbstring

- name: PHPStan
uses: docker://oskarstark/phpstan-ga:0.12.28
with:
entrypoint: ./.github/workflows/phpstan.entrypoint
args: analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: PHP-CS-Fixer
uses: docker://oskarstark/php-cs-fixer-ga:2.16.3.1
with:
args: --dry-run --diff-format udiff

psalm:
name: Psalm
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Install
uses: docker://composer
with:
args: install --ignore-platform-reqs --no-ansi --no-suggest
- name: Download dependencies
run: composer install --classmap-authoritative

- name: Psalm
uses: docker://vimeo/psalm-github-actions
with:
entrypoint: ./.github/workflows/psalm.entrypoint
args: --threads=8 --diff --diff-methods
run: vendor/bin/phpcs
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/.phpbench
.php_cs
.php_cs.cache
.phpunit.result.cache
/build/
/composer.lock
Ocramius marked this conversation as resolved.
Show resolved Hide resolved
/phpspec.yml
/phpunit.xml
/vendor/
Expand Down
17 changes: 0 additions & 17 deletions .php_cs.dist

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.2-cli
FROM php:8.0-cli

RUN set -xe \
&& apt-get update \
Expand Down
53 changes: 53 additions & 0 deletions benchmark/MoneyInstantiationBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace Benchmark\Money;

use Money\Currency;
use Money\Money;
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;

/**
* @BeforeMethods({"setUp"})
*/
final class MoneyInstantiationBench
{
/** @var Currency */
private $currency;

public function setUp(): void
{
$this->currency = new Currency('EUR');
}

public function benchConstructorWithZeroIntegerAmount(): void
{
new Money(0, $this->currency);
}

public function benchConstructorWithPositiveIntegerAmount(): void
{
new Money(1234567890, $this->currency);
}

public function benchConstructorWithNegativeIntegerAmount(): void
{
new Money(-1234567890, $this->currency);
}

public function benchConstructorWithZeroStringAmount(): void
{
new Money('0', $this->currency);
}

public function benchConstructorWithPositiveStringAmount(): void
{
new Money('1234567890', $this->currency);
}

public function benchConstructorWithNegativeStringAmount(): void
{
new Money('-1234567890', $this->currency);
}
}
Loading