diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7f4dbd6..27cedb2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/composer.json b/composer.json index 78726bf..1a70ff2 100644 --- a/composer.json +++ b/composer.json @@ -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" : { @@ -36,8 +36,8 @@ "config" : { "optimize-autoloader" : true, - "allow-plugins": { - "composer/package-versions-deprecated": true + "allow-plugins" : { + "composer/package-versions-deprecated" : true } }, diff --git a/src/Formatter.php b/src/Formatter.php index 786413f..9f51cf7 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -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 @@ -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); diff --git a/src/Parser.php b/src/Parser.php index 963806e..ddd7040 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -26,12 +26,12 @@ final class Parser /** * @var string */ - protected $default = ''; + protected string $default = ''; /** * @var array */ - protected $rules = []; + protected array $rules = []; /** * @param string $default diff --git a/src/Type/AbstractType.php b/src/Type/AbstractType.php index e50a91a..32746e6 100644 --- a/src/Type/AbstractType.php +++ b/src/Type/AbstractType.php @@ -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 @@ -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 @@ -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 { @@ -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; diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 684a6d9..a8df40e 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -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() diff --git a/tests/SimpleTypesReadmeTest.php b/tests/SimpleTypesReadmeTest.php index 3d38779..9c816d1 100644 --- a/tests/SimpleTypesReadmeTest.php +++ b/tests/SimpleTypesReadmeTest.php @@ -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'; } diff --git a/tests/fixtures/ConfigTestWeight.php b/tests/fixtures/ConfigTestWeight.php index e097f35..c578748 100644 --- a/tests/fixtures/ConfigTestWeight.php +++ b/tests/fixtures/ConfigTestWeight.php @@ -32,8 +32,7 @@ public function getRules() return [ 'kg' => [ 'rate' => function ($value, $to) { - - if ($to == 'gram') { + if ($to === 'gram') { return $value * 1000; }