From 7256b210008c4f09ee0d0bedbc41d218363cf880 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 6 Jan 2025 21:55:11 -0300 Subject: [PATCH 1/2] fix: Fixes execution of composer scripts and updates dependencies. --- .github/workflows/auto-assign.yml | 11 +++++++---- LICENSE | 2 +- Makefile | 19 ++++++++++++++++--- composer.json | 11 ++++++----- infection.json.dist | 21 +++++++++++---------- phpunit.xml | 6 ++++-- src/Base62.php | 4 ++-- src/Internal/Decimal.php | 14 ++++++-------- src/Internal/Hexadecimal.php | 12 ++++++------ 9 files changed, 59 insertions(+), 41 deletions(-) diff --git a/.github/workflows/auto-assign.yml b/.github/workflows/auto-assign.yml index 6a9bba4..b1c4e50 100644 --- a/.github/workflows/auto-assign.yml +++ b/.github/workflows/auto-assign.yml @@ -1,9 +1,12 @@ -name: Auto assign issues +name: Auto assign issues and pull requests on: issues: types: - opened + pull_request: + types: + - opened jobs: run: @@ -12,11 +15,11 @@ jobs: issues: write pull-requests: write steps: - - name: Assign issues - uses: gustavofreze/auto-assign@1.0.0 + - name: Assign issues and pull requests + uses: gustavofreze/auto-assign@1.1.4 with: assignees: '${{ secrets.ASSIGNEES }}' github_token: '${{ secrets.GITHUB_TOKEN }}' allow_self_assign: 'true' allow_no_assignees: 'true' - assignment_options: 'ISSUE' \ No newline at end of file + assignment_options: 'ISSUE,PULL_REQUEST' \ No newline at end of file diff --git a/LICENSE b/LICENSE index 46fc4c0..6bfc7b1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2024 Tiny Blocks +Copyright (c) 2022-2025 Tiny Blocks Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 3cfd101..96ccd27 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,17 @@ -DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3 +ifeq ($(OS),Windows_NT) + PWD := $(shell cd) +else + PWD := $(shell pwd -L) +endif + +ARCH := $(shell uname -m) +PLATFORM := + +ifeq ($(ARCH),arm64) + PLATFORM := --platform=linux/amd64 +endif + +DOCKER_RUN = docker run ${PLATFORM} --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3 .PHONY: configure test test-file test-no-coverage review show-reports clean @@ -9,7 +22,7 @@ test: @${DOCKER_RUN} composer tests test-file: - @${DOCKER_RUN} composer tests-file-no-coverage ${FILE} + @${DOCKER_RUN} composer test-file ${FILE} test-no-coverage: @${DOCKER_RUN} composer tests-no-coverage @@ -22,4 +35,4 @@ show-reports: clean: @sudo chown -R ${USER}:${USER} ${PWD} - @rm -rf report vendor .phpunit.cache + @rm -rf report vendor .phpunit.cache *.lock diff --git a/composer.json b/composer.json index 6fc3550..28a2aea 100644 --- a/composer.json +++ b/composer.json @@ -47,19 +47,20 @@ "phpmd/phpmd": "^2.15", "phpunit/phpunit": "^11", "phpstan/phpstan": "^1", - "infection/infection": "^0.29", + "infection/infection": "^0", "squizlabs/php_codesniffer": "^3.11" }, "suggest": { "ext-bcmath": "Enables the extension which is an interface to the GNU implementation as a Basic Calculator utility library." }, "scripts": { + "test": "phpunit -d memory_limit=2G --configuration phpunit.xml tests", "phpcs": "phpcs --standard=PSR12 --extensions=php ./src", "phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit", "phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress", - "test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests", - "test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4", - "test-no-coverage": "phpunit --no-coverage", + "test-file": "phpunit --configuration phpunit.xml --no-coverage --filter", + "mutation-test": "infection --only-covered --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage", + "test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests", "review": [ "@phpcs", "@phpmd", @@ -67,7 +68,7 @@ ], "tests": [ "@test", - "@test-mutation" + "@mutation-test" ], "tests-no-coverage": [ "@test-no-coverage" diff --git a/infection.json.dist b/infection.json.dist index 72bef1b..db91d0f 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,15 +1,19 @@ { - "timeout": 30, - "testFramework": "phpunit", + "logs": { + "text": "report/infection/logs/infection-text.log", + "summary": "report/infection/logs/infection-summary.log" + }, "tmpDir": "report/infection/", + "minMsi": 100, + "timeout": 30, "source": { "directories": [ "src" ] }, - "logs": { - "text": "report/infection/logs/infection-text.log", - "summary": "report/infection/logs/infection-summary.log" + "phpUnit": { + "configDir": "", + "customPath": "./vendor/bin/phpunit" }, "mutators": { "@default": true, @@ -18,12 +22,9 @@ "Increment": false, "GreaterThan": false, "UnwrapSubstr": false, - "UnwrapStrToLower": false, "LogicalAndNegation": false, "LogicalAndAllSubExprNegation": false }, - "phpUnit": { - "configDir": "", - "customPath": "./vendor/bin/phpunit" - } + "minCoveredMsi": 100, + "testFramework": "phpunit" } diff --git a/phpunit.xml b/phpunit.xml index 7f080dd..40c80a2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,7 @@ failOnRisky="true" failOnWarning="true" cacheDirectory=".phpunit.cache" + executionOrder="random" beStrictAboutOutputDuringTests="true"> @@ -22,14 +23,15 @@ + + - - + diff --git a/src/Base62.php b/src/Base62.php index 1b24e24..f21f157 100644 --- a/src/Base62.php +++ b/src/Base62.php @@ -10,9 +10,9 @@ final readonly class Base62 implements Encoder { - public const int BASE62_RADIX = 62; private const int BASE62_CHARACTER_LENGTH = 1; + public const string BASE62_RADIX = '62'; private const string BASE62_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; private function __construct(private string $value) @@ -58,7 +58,7 @@ public function decode(): string return str_repeat("\x00", $bytes); } - $decimal = Decimal::fromBase62(number: $value, alphabet: self::BASE62_ALPHABET); + $decimal = Decimal::from(number: $value, alphabet: self::BASE62_ALPHABET, baseRadix: self::BASE62_RADIX); $hexadecimal = Hexadecimal::from(value: $decimal->toHexadecimal()) ->fillWithZeroIfNecessary() ->toString(); diff --git a/src/Internal/Decimal.php b/src/Internal/Decimal.php index 50dceee..3e2ad4c 100644 --- a/src/Internal/Decimal.php +++ b/src/Internal/Decimal.php @@ -4,23 +4,21 @@ namespace TinyBlocks\Encoder\Internal; -use TinyBlocks\Encoder\Base62; - final readonly class Decimal { private function __construct(private string $value) { } - public static function fromBase62(string $number, string $alphabet): Decimal + public static function from(string $number, string $alphabet, string $baseRadix): Decimal { $value = '0'; $length = strlen($number); for ($index = 0; $index < $length; $index++) { - $digit = strpos($alphabet, $number[$index]); - $value = bcmul($value, (string)Base62::BASE62_RADIX); - $value = bcadd($value, (string)$digit); + $digit = (string)strpos($alphabet, $number[$index]); + $value = bcmul($value, $baseRadix); + $value = bcadd($value, $digit); } return new Decimal(value: $value); @@ -32,8 +30,8 @@ public function toHexadecimal(): string $hexadecimalValue = ''; while (bccomp($value, '0') > 0) { - $remainder = bcmod($value, Hexadecimal::HEXADECIMAL_RADIX); - $hexadecimalValue = sprintf('%s%s', Hexadecimal::HEXADECIMAL_ALPHABET[(int)$remainder], $hexadecimalValue); + $remainder = (int)bcmod($value, Hexadecimal::HEXADECIMAL_RADIX); + $hexadecimalValue = sprintf('%s%s', Hexadecimal::HEXADECIMAL_ALPHABET[$remainder], $hexadecimalValue); $value = bcdiv($value, Hexadecimal::HEXADECIMAL_RADIX); } diff --git a/src/Internal/Hexadecimal.php b/src/Internal/Hexadecimal.php index 1b126f4..7b96c36 100644 --- a/src/Internal/Hexadecimal.php +++ b/src/Internal/Hexadecimal.php @@ -59,24 +59,24 @@ public function isEmpty(): bool return empty($this->value); } - public function toBase(int $base): string + public function toBase(string $base): string { $length = strlen($this->value); $decimalValue = '0'; for ($index = 0; $index < $length; $index++) { - $digit = strpos(self::HEXADECIMAL_ALPHABET, strtolower($this->value[$index])); + $digit = (string)strpos(self::HEXADECIMAL_ALPHABET, $this->value[$index]); $decimalValue = bcmul($decimalValue, self::HEXADECIMAL_RADIX); - $decimalValue = bcadd($decimalValue, (string)$digit); + $decimalValue = bcadd($decimalValue, $digit); } $digits = $this->alphabet; $result = ''; while (bccomp($decimalValue, '0') > 0) { - $remainder = bcmod($decimalValue, (string)$base); - $result = sprintf('%s%s', $digits[(int)$remainder], $result); - $decimalValue = bcdiv($decimalValue, (string)$base); + $remainder = (int)bcmod($decimalValue, $base); + $result = sprintf('%s%s', $digits[$remainder], $result); + $decimalValue = bcdiv($decimalValue, $base); } return $result ?: '0'; From a8770be638a62d2ef4aef9bbca16ecf176e65613 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 6 Jan 2025 21:57:25 -0300 Subject: [PATCH 2/2] fix: Fixes execution of composer scripts and updates dependencies. --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96e4a08..358ac92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,6 @@ name: CI on: - push: pull_request: permissions: