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

Minimal PHP version is 7.4 #7

Merged
merged 2 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
php-version: [ 7.4, 8.0, 8.1 ]
composer_flags: [ "--prefer-lowest", "" ]
steps:
- name: Checkout code
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Uploading coverage to coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make report-coveralls --no-print-directory
run: make report-coveralls --no-print-directory || true

- name: Upload Artifacts
uses: actions/upload-artifact@v2
Expand All @@ -73,7 +73,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
php-version: [ 7.4, 8.0, 8.1 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -84,8 +84,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ast
tools: composer
extensions: ast

- name: Build the Project
run: make update --no-print-directory
Expand All @@ -105,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 7.2, 7.3, 7.4, 8.0 ]
php-version: [ 7.4, 8.0, 8.1 ]
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
],

"require" : {
"php" : ">=7.2"
"php" : ">=7.4"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^3.1.0"
"jbzoo/toolbox-dev" : "^4.0.1"
},

"autoload" : {
Expand All @@ -36,8 +36,8 @@

"config" : {
"optimize-autoloader" : true,
"allow-plugins": {
"composer/package-versions-deprecated": true
"allow-plugins" : {
"composer/package-versions-deprecated" : true
}
},

Expand Down
8 changes: 4 additions & 4 deletions src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ final class Formatter
/**
* @var array
*/
protected $rules = [];
protected array $rules = [];

/**
* @var string|null
*/
protected $type = '';
protected ?string $type = '';

/**
* @var array
*/
protected $default = [];
protected array $default = [];

/**
* @param array $rules
Expand All @@ -56,7 +56,7 @@ public function __construct(array $rules = [], array $default = [], ?string $typ
$this->default = $default;

// prepare rules
$this->rules = \array_change_key_case($rules, \CASE_LOWER);
$this->rules = \array_change_key_case($rules);

foreach ($this->rules as $key => $item) {
$this->rules[$key] = \array_merge($default, (array)$item);
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ final class Parser
/**
* @var string
*/
protected $default = '';
protected string $default = '';

/**
* @var array
*/
protected $rules = [];
protected array $rules = [];

/**
* @param string $default
Expand Down
20 changes: 9 additions & 11 deletions src/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ abstract class AbstractType
/**
* @var int
*/
protected $uniqueId = 0;
protected int $uniqueId = 0;

/**
* @var string
*/
protected $type = '';
protected string $type = '';

/**
* @var float|int
Expand All @@ -60,32 +60,32 @@ abstract class AbstractType
/**
* @var string
*/
protected $default = '';
protected string $default = '';

/**
* @var Parser
*/
protected $parser;
protected Parser $parser;

/**
* @var Formatter
*/
protected $formatter;
protected Formatter $formatter;

/**
* @var array
*/
protected $logs = [];
protected array $logs = [];

/**
* @var bool
*/
protected $isDebug = false;
protected bool $isDebug = false;

/**
* @var int
*/
protected static $counter = 0;
protected static int $counter = 0;

/**
* @param string|float|int|null $value
Expand Down Expand Up @@ -318,14 +318,12 @@ protected function customConvert(string $rule, bool $addToLog = false): float
$result = $this->internalValue;
if ($from !== $target) {
if (\is_callable($ruleTo['rate']) || \is_callable($ruleFrom['rate'])) {
/** @noinspection NotOptimalIfConditionsInspection */
if (\is_callable($ruleFrom['rate'])) {
$defNorm = $ruleFrom['rate']($this->internalValue, $this->default, $from);
} else {
$defNorm = $this->internalValue * $ruleFrom['rate'] * $ruleDef['rate'];
}

/** @noinspection NotOptimalIfConditionsInspection */
if (\is_callable($ruleTo['rate'])) {
$result = $ruleTo['rate']($defNorm, $target, $this->default);
} else {
Expand Down Expand Up @@ -728,7 +726,7 @@ public function __sleep()
$propList = $reflect->getProperties();

foreach ($propList as $prop) {
if ($prop->isStatic() === true) {
if ($prop->isStatic()) {
continue;
}
$result[] = $prop->name;
Expand Down
138 changes: 69 additions & 69 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,107 +27,107 @@ public function testEmpty()
{
$empty = '0 eur';

batchEqualDumps(array(
batchEqualDumps([
// empty
array($empty),
array($empty, null),
array($empty, 0),
array($empty, ''),
[$empty],
[$empty, null],
[$empty, 0],
[$empty, ''],

// spaces
array($empty, ' '),
array($empty, ' '),
array($empty, "\t"),
array($empty, "\t "),
array($empty, " \t "),
array($empty, " \n "),
array($empty, " \n\r "),
array($empty, " \r\n "),
[$empty, ' '],
[$empty, ' '],
[$empty, "\t"],
[$empty, "\t "],
[$empty, " \t "],
[$empty, " \n "],
[$empty, " \n\r "],
[$empty, " \r\n "],

// arrays
array($empty, array()),
array($empty, array(null, null)),
array($empty, array(0)),
array($empty, array(0, '')),
array($empty, array(0, "")),
));
[$empty, []],
[$empty, [null, null]],
[$empty, [0]],
[$empty, [0, '']],
[$empty, [0, ""]],
]);
}

public function testSimple()
{
batchEqualDumps(array(
batchEqualDumps([
// int
array('1 eur', 1),
array('-1 eur', -1),
['1 eur', 1],
['-1 eur', -1],

// float
array('2 eur', 2.0),
array('3.55 eur', 3.55),
array('0.57 eur', .57),
array('-2 eur', '-2,'),
array('-3.55 eur', '-3,55'),
array('-0.57 eur', '-,57'),
['2 eur', 2.0],
['3.55 eur', 3.55],
['0.57 eur', .57],
['-2 eur', '-2,'],
['-3.55 eur', '-3,55'],
['-0.57 eur', '-,57'],

// big
array('1000000.99999 eur', '1 000 000.999 99'),
['1000000.99999 eur', '1 000 000.999 99'],

// huge
array('1.0E+18 eur', '1.0e+18'),
));
['1.0E+18 eur', '1.0e+18'],
]);
}

public function testRule()
{
batchEqualDumps(array(
array('0 eur', 'eur'),
array('1 eur', '1eur'),
array('1 eur', '1EUR'),
array('1 eur', '1eUr'),
array('1 eur', '1 eur '),
array('1 eur', '1eur '),
array('1 eur', '1 eur'),
array('1 eur', '1 eur'),
array('1 usd', "1\tusd"),
array('1.0E+18 eur', '1.0e+18 EUR '),
batchEqualDumps([
['0 eur', 'eur'],
['1 eur', '1eur'],
['1 eur', '1EUR'],
['1 eur', '1eUr'],
['1 eur', '1 eur '],
['1 eur', '1eur '],
['1 eur', '1 eur'],
['1 eur', '1 eur'],
['1 usd', "1\tusd"],
['1.0E+18 eur', '1.0e+18 EUR '],

// reverse
array('1 eur', 'eur1'),
array('1 eur', 'eur 1'),
array('1 eur', ' eur 1'),
array('1 eur', ' eur 1 '),
array('1 eur', 'eur 1 '),
));
['1 eur', 'eur1'],
['1 eur', 'eur 1'],
['1 eur', ' eur 1'],
['1 eur', ' eur 1 '],
['1 eur', 'eur 1 '],
]);
}

public function testRound()
{
batchEqualDumps(array(
array('0.1 eur', '.1'),
array('0.01 eur', '.01'),
array('0.001 eur', '.001'),
array('0.0001 eur', '.0001'),
array('1.0E-5 eur', '.00001'),
array('1.0E-6 eur', '.000001'),
array('1.0E-7 eur', '.0000001'),
array('1.0E-8 eur', '.00000001'),
array('1.0E-8 eur', '.000000009'),
array('1.0E-8 eur', '.0000000099'),
array('1.0E-8 eur', '.000000005'),
array('0 eur', '.000000001'),
array('0 eur', '.000000004'),
));
batchEqualDumps([
['0.1 eur', '.1'],
['0.01 eur', '.01'],
['0.001 eur', '.001'],
['0.0001 eur', '.0001'],
['1.0E-5 eur', '.00001'],
['1.0E-6 eur', '.000001'],
['1.0E-7 eur', '.0000001'],
['1.0E-8 eur', '.00000001'],
['1.0E-8 eur', '.000000009'],
['1.0E-8 eur', '.0000000099'],
['1.0E-8 eur', '.000000005'],
['0 eur', '.000000001'],
['0 eur', '.000000004'],
]);
}

public function testComplex()
{
batchEqualDumps(array(
array('-123.456 usd', ' - 1 2 3 . 4 5 6 usd '),
array('-123.456 usd', array(' - 1 2 3 , 4 5 6 eur', 'usd')),
array('-123.456 usd', array(' - 1 2 3 . 4 5 6 eur', 'usd')),
batchEqualDumps([
['-123.456 usd', ' - 1 2 3 . 4 5 6 usd '],
['-123.456 usd', [' - 1 2 3 , 4 5 6 eur', 'usd']],
['-123.456 usd', [' - 1 2 3 . 4 5 6 eur', 'usd']],

// insane
array('-987654321.123 eur', 'some number - 9 8 7 6 5 4 3 2 1, 1 2 3 eur '),
));
['-987654321.123 eur', 'some number - 9 8 7 6 5 4 3 2 1, 1 2 3 eur '],
]);
}

public function testUndefinedRule()
Expand Down
9 changes: 1 addition & 8 deletions tests/SimpleTypesReadmeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,5 @@
*/
class SimpleTypesReadmeTest extends AbstractReadmeTest
{
protected $packageName = 'SimpleTypes';

protected function setUp(): void
{
parent::setUp();
$this->params['strict_types'] = true;
$this->params['travis'] = false;
}
protected string $packageName = 'SimpleTypes';
}
3 changes: 1 addition & 2 deletions tests/fixtures/ConfigTestWeight.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function getRules()
return [
'kg' => [
'rate' => function ($value, $to) {

if ($to == 'gram') {
if ($to === 'gram') {
return $value * 1000;
}

Expand Down