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

Fix division without bcmath and using the precision parameter #19

Merged
merged 8 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
153 changes: 115 additions & 38 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,123 @@
name: PHP

on: [push, pull_request]

jobs:
build:
php-cs-fixer:
name: PHP CS Fixer
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.0
with:
access_token: ${{ github.token }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: bcmath

- uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache Composer Directory
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Validate composer config
run: composer validate --strict

- name: Composer Install
run: composer install

- name: Run PHPCSFixer
run: ./vendor/bin/php-cs-fixer fix --dry-run --diff

phpstan:
name: PHP Static Analysis
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.0
with:
access_token: ${{ github.token }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
extensions: bcmath

- uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache Composer Directory
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Composer Install
run: composer install

- name: Run phpstan
run: ./vendor/bin/phpstan analyse -c tests/phpstan/phpstan.neon

phpunit:
name: PHPUnit
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
#, '8.0', '8.1'
php: ['7.2', '7.3', '7.4', '8.0']
PierreRambaud marked this conversation as resolved.
Show resolved Hide resolved
fail-fast: false
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug
extensions: bcmath

- uses: actions/checkout@v2

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --no-interaction

- name: PHPUnit
run: ./vendor/bin/phpunit --coverage-clover build/clover.xml

- name: Upload coverage results to Coveralls
if: matrix.php-versions == '7.1'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
chmod +x php-coveralls.phar
php php-coveralls.phar --coverage_clover=build/clover.xml --json_path=build/coveralls-upload.json -vvv
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.0
with:
access_token: ${{ github.token }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath

- uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache Composer Directory
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Composer Install
run: composer install

- name: Run phpunit (without DB)
run: vendor/bin/phpunit --coverage-text --coverage-clover build/clover.xml
env:
SYMFONY_DEPRECATIONS_HELPER: disabled
XDEBUG_MODE: coverage

- name: Upload coverage results to Coveralls
if: matrix.php-versions == '7.4'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
chmod +x php-coveralls.phar
php php-coveralls.phar --coverage_clover=build/clover.xml --json_path=build/coveralls-upload.json -vvv
35 changes: 3 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
# IntelliJ - PhpStorm and PyCharm
.idea
*.iml
*.ipr
*.iws

# Netbeans
nbproject
.nbproject
.nbproject/*
nbproject/*
nbproject/private/
build/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

# Mac OSX
.DS_Store
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes

# SublimeText project files
/*.sublime-project
*.sublime-workspace

build
composer.lock
docs
vendor
vendor
.php_cs.cache
.phpunit.result.cache
11 changes: 11 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$config = new PrestaShop\CodingStandards\CsFixer\Config();

$config
->setUsingCache(true)
->getFinder()
->in(__DIR__)
->exclude('vendor');

return $config;
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
{
"name": "PrestaShop SA",
"email": "contact@prestashop.com"
},{
"name": "Pablo Borowicz",
"email": "pablo.borowicz@prestashop.com"
}
],
"require": {
"php" : ">=5.4"
"php" : ">=7.2"
},
"require-dev": {
"phpunit/phpunit" : "4.*"
"phpunit/phpunit" : "8.*",
"codacy/coverage": "dev-master",
matks marked this conversation as resolved.
Show resolved Hide resolved
"prestashop/php-dev-tools": "^4.1",
"phpstan/phpstan": "^0.12.99"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 17 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Decimal Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/clover.xml"/>
</logging>
<testsuites>
<testsuite name="Decimal Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap" />
<log type="junit" target="build/report.junit.xml" />
<log type="coverage-html" target="build/coverage" />
<log type="coverage-text" target="build/coverage.txt" />
<log type="coverage-clover" target="build/clover.xml" />
</logging>
</phpunit>
13 changes: 3 additions & 10 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@

namespace PrestaShop\Decimal;

use PrestaShop\Decimal\DecimalNumber;


/**
* Builds Number instances
*/
class Builder
{

/**
* Pattern for most numbers
*/
Expand All @@ -37,9 +33,7 @@ class Builder
public static function parseNumber($number)
{
if (!self::itLooksLikeANumber($number, $numberParts)) {
throw new \InvalidArgumentException(
sprintf('"%s" cannot be interpreted as a number', print_r($number, true))
);
throw new \InvalidArgumentException(sprintf('"%s" cannot be interpreted as a number', print_r($number, true)));
}

$integerPart = '';
Expand Down Expand Up @@ -89,13 +83,12 @@ public static function parseNumber($number)
*/
private static function itLooksLikeANumber($number, &$numberParts)
{
return (
return
strlen((string) $number) > 0
&& (
preg_match(self::NUMBER_PATTERN, $number, $numberParts)
|| preg_match(self::INT_EXPONENTIAL_PATTERN, $number, $numberParts)
)
);
;
}

}
Loading