From 60ead67121637ca3e17d3c4a5077068ac9c16b34 Mon Sep 17 00:00:00 2001 From: Denis Smet Date: Sun, 28 Jan 2024 15:16:50 +0400 Subject: [PATCH 1/4] Update PHP version to 8.3 and bump jbzoo dependencies to ^7.1 --- .github/workflows/main.yml | 6 +++--- composer.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8b5214d..dbf8532 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,7 @@ jobs: JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }} strategy: matrix: - php-version: [ 8.1, 8.2 ] + php-version: [ 8.1, 8.2, 8.3 ] coverage: [ xdebug, none ] composer_flags: [ "--prefer-lowest", "" ] steps: @@ -77,7 +77,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [ 8.1, 8.2 ] + php-version: [ 8.1, 8.2, 8.3 ] steps: - name: Checkout code uses: actions/checkout@v3 @@ -111,7 +111,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: [ 8.1, 8.2 ] + php-version: [ 8.1, 8.2, 8.3 ] steps: - name: Checkout code uses: actions/checkout@v3 diff --git a/composer.json b/composer.json index 4fa5e60..0dac850 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,11 @@ "require" : { "php" : "^8.1", - "jbzoo/utils" : "^7.0" + "jbzoo/utils" : "^7.1" }, "require-dev" : { - "jbzoo/toolbox-dev" : "^7.0" + "jbzoo/toolbox-dev" : "^7.1" }, "autoload" : { From 13779e5398337f5b792678d97f9386a59e283d0b Mon Sep 17 00:00:00 2001 From: Denis Smet Date: Sun, 28 Jan 2024 15:17:05 +0400 Subject: [PATCH 2/4] Standardize null type position in union types across codebase --- src/Parser.php | 2 +- src/Type/AbstractType.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 626e40e..d2bb5b5 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -102,7 +102,7 @@ public function removeRule(string $rule): bool return false; } - public static function cleanValue(float|int|string|null $value): float + public static function cleanValue(null|float|int|string $value): float { $result = \trim((string)$value); diff --git a/src/Type/AbstractType.php b/src/Type/AbstractType.php index ebf0815..05386fc 100644 --- a/src/Type/AbstractType.php +++ b/src/Type/AbstractType.php @@ -47,7 +47,7 @@ abstract class AbstractType protected Parser $parser; protected Formatter $formatter; - public function __construct(float|int|string|array|null $value = null, ?AbstractConfig $config = null) + public function __construct(null|array|float|int|string $value = null, ?AbstractConfig $config = null) { $this->prepareObject($value, $config); } @@ -290,7 +290,7 @@ public function getClone(): self * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function compare( - self|float|int|string|null|array $value, + null|array|float|int|self|string $value, string $mode = '==', int $round = Formatter::ROUND_DEFAULT, ): bool { @@ -339,12 +339,12 @@ public function setEmpty(bool $getClone = false): self return $this->modifier(0.0, 'Set empty', $getClone); } - public function add(self|float|int|string|null|array $value, bool $getClone = false): self + public function add(null|array|float|int|self|string $value, bool $getClone = false): self { return $this->customAdd($value, $getClone); } - public function subtract(self|float|int|string|null|array $value, bool $getClone = false): self + public function subtract(null|array|float|int|self|string $value, bool $getClone = false): self { return $this->customAdd($value, $getClone, true); } @@ -438,7 +438,7 @@ public function customFunc(\Closure $function, bool $getClone = false): self return $this->modifier($this->internalValue, '<-- Function finished', $getClone); } - public function set(self|float|int|string|null|array $value, bool $getClone = false): self + public function set(null|array|float|int|self|string $value, bool $getClone = false): self { $value = $this->getValidValue($value); @@ -463,7 +463,7 @@ public function round(int $roundValue, string $mode = Formatter::ROUND_CLASSIC): return $this; } - public function getValidValue(self|float|int|string|null|array $value): self + public function getValidValue(null|array|float|int|self|string $value): self { if ($value instanceof self) { $thisClass = \strtolower(static::class); @@ -608,7 +608,7 @@ protected function customConvert(string $rule, bool $addToLog = false): float } protected function customAdd( - self|float|int|string|null|array $value, + null|array|float|int|self|string $value, bool $getClone = false, bool $isSubtract = false, ): self { @@ -655,7 +655,7 @@ protected function modifier(float $newValue, ?string $logMessage = null, bool $g return $this; } - private function prepareObject(float|int|string|array|null $value = null, ?AbstractConfig $config = null): void + private function prepareObject(null|array|float|int|string $value = null, ?AbstractConfig $config = null): void { // $this->type = Str::class \strtolower(\str_replace(__NAMESPACE__ . '\\', '', static::class)); $this->type = Str::getClassName(static::class, true) ?? 'UndefinedType'; From f078d9ca5d80eeec368b47bed38caed7828775fd Mon Sep 17 00:00:00 2001 From: Denis Smet Date: Sun, 28 Jan 2024 15:19:57 +0400 Subject: [PATCH 3/4] Fix roundType check using bool utility and remove redundant docblock --- src/Formatter.php | 4 +++- src/Type/AbstractType.php | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Formatter.php b/src/Formatter.php index f329675..da53bc2 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -16,6 +16,8 @@ namespace JBZoo\SimpleTypes; +use function JBZoo\Utils\bool; + final class Formatter { public const ROUND_DEFAULT = 8; @@ -140,7 +142,7 @@ public function round(float $value, string $rule, array $params = []): float $roundType = $params['roundType']; $roundValue = $params['roundValue']; - if (!$roundType) { + if (!bool($roundType)) { $roundType = \array_key_exists('round_type', $format) ? $format['round_type'] : self::ROUND_NONE; } diff --git a/src/Type/AbstractType.php b/src/Type/AbstractType.php index 05386fc..c273bc4 100644 --- a/src/Type/AbstractType.php +++ b/src/Type/AbstractType.php @@ -52,9 +52,6 @@ public function __construct(null|array|float|int|string $value = null, ?Abstract $this->prepareObject($value, $config); } - /** - * @psalm-suppress MethodSignatureMustProvideReturnType - */ public function __toString() { $this->log('__toString() called'); From d27d05d8097d699838c56a159a6dc9f60750ce66 Mon Sep 17 00:00:00 2001 From: Denis Smet Date: Sun, 28 Jan 2024 16:20:56 +0400 Subject: [PATCH 4/4] Remove unused bool function import and refine null check in Formatter --- src/Formatter.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Formatter.php b/src/Formatter.php index da53bc2..bf75dc8 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -16,8 +16,6 @@ namespace JBZoo\SimpleTypes; -use function JBZoo\Utils\bool; - final class Formatter { public const ROUND_DEFAULT = 8; @@ -142,7 +140,7 @@ public function round(float $value, string $rule, array $params = []): float $roundType = $params['roundType']; $roundValue = $params['roundValue']; - if (!bool($roundType)) { + if ($roundType === null) { $roundType = \array_key_exists('round_type', $format) ? $format['round_type'] : self::ROUND_NONE; }