From 23da8f005388d1939612a44e37858eaf93018a50 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 12 Jan 2026 23:18:27 -0300 Subject: [PATCH 1/5] refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity. --- .gitattributes | 1 - .github/workflows/ci.yml | 51 +++++++++++++-- Makefile | 60 ++++++++++++----- composer.json | 30 +++++---- phpmd.xml | 65 ------------------- .../Mappers/Collection/ValueMapper.php | 6 +- .../Object/Casters/CollectionCaster.php | 2 +- .../Mappers/Object/Casters/DefaultCaster.php | 2 +- src/Internal/Mappers/Object/Reflector.php | 4 +- 9 files changed, 114 insertions(+), 107 deletions(-) delete mode 100644 phpmd.xml diff --git a/.gitattributes b/.gitattributes index 4126d6c..a4a3fb8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,6 @@ /README.md export-ignore /LICENSE export-ignore /Makefile export-ignore -/phpmd.xml export-ignore /phpunit.xml export-ignore /phpstan.neon.dist export-ignore /infection.json.dist export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 158b78a..1697dfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,9 +11,39 @@ env: COMPOSER_ROOT_VERSION: '1.2.0' jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 + + - name: Validate composer.json + run: composer validate --no-interaction + + - name: Install dependencies + run: composer install --no-progress --optimize-autoloader --prefer-dist --no-interaction + + - name: Upload vendor and composer.lock as artifact + uses: actions/upload-artifact@v6 + with: + name: vendor-artifact + path: | + vendor + composer.lock + auto-review: name: Auto review runs-on: ubuntu-latest + needs: build steps: - name: Checkout @@ -23,9 +53,14 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 - - name: Install dependencies - run: composer update --no-progress --optimize-autoloader + - name: Download vendor artifact from build + uses: actions/upload-artifact@v7 + with: + name: vendor-artifact + path: . - name: Run review run: composer review @@ -33,18 +68,24 @@ jobs: tests: name: Tests runs-on: ubuntu-latest + needs: auto-review steps: - name: Checkout uses: actions/checkout@v6 - - name: Use PHP ${{ env.PHP_VERSION }} + - name: Configure PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 - - name: Install dependencies - run: composer update --no-progress --optimize-autoloader + - name: Download vendor artifact from build + uses: actions/upload-artifact@v7 + with: + name: vendor-artifact + path: . - name: Run tests run: composer tests diff --git a/Makefile b/Makefile index 96ccd27..ef9a884 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,4 @@ -ifeq ($(OS),Windows_NT) - PWD := $(shell cd) -else - PWD := $(shell pwd -L) -endif - +PWD := $(CURDIR) ARCH := $(shell uname -m) PLATFORM := @@ -11,28 +6,63 @@ 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 +DOCKER_RUN = docker run ${PLATFORM} --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.5-alpine -.PHONY: configure test test-file test-no-coverage review show-reports clean +RESET := \033[0m +GREEN := \033[0;32m +YELLOW := \033[0;33m -configure: +.DEFAULT_GOAL := help + +.PHONY: configure +configure: ## Configure development environment @${DOCKER_RUN} composer update --optimize-autoloader -test: +.PHONY: test +test: ## Run all tests with coverage @${DOCKER_RUN} composer tests -test-file: +.PHONY: test-file +test-file: ## Run tests for a specific file (usage: make test-file FILE=path/to/file) @${DOCKER_RUN} composer test-file ${FILE} -test-no-coverage: +.PHONY: test-no-coverage +test-no-coverage: ## Run all tests without coverage @${DOCKER_RUN} composer tests-no-coverage -review: +.PHONY: review +review: ## Run static code analysis @${DOCKER_RUN} composer review -show-reports: +.PHONY: show-reports +show-reports: ## Open static analysis reports (e.g., coverage, lints) in the browser @sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html -clean: +.PHONY: clean +clean: ## Remove dependencies and generated artifacts @sudo chown -R ${USER}:${USER} ${PWD} @rm -rf report vendor .phpunit.cache *.lock + +.PHONY: help +help: ## Display this help message + @echo "Usage: make [target]" + @echo "" + @echo "$$(printf '$(GREEN)')Setup$$(printf '$(RESET)')" + @grep -E '^(configure):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*? ## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Testing$$(printf '$(RESET)')" + @grep -E '^(test|test-file|test-no-coverage):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Quality$$(printf '$(RESET)')" + @grep -E '^(review):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Reports$$(printf '$(RESET)')" + @grep -E '^(show-reports):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Cleanup$$(printf '$(RESET)')" + @grep -E '^(clean):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' diff --git a/composer.json b/composer.json index c105a1d..035e872 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,11 @@ "issues": "https://github.com/tiny-blocks/mapper/issues", "source": "https://github.com/tiny-blocks/mapper" }, + "extra": { + "branch-alias": { + "dev-develop": "1.3.x-dev" + } + }, "config": { "sort-packages": true, "allow-plugins": { @@ -42,27 +47,24 @@ } }, "require": { - "php": "^8.3" + "php": "^8.5" }, "require-dev": { - "phpmd/phpmd": "^2.15", - "phpunit/phpunit": "^12.1", - "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^11.5", + "phpstan/phpstan": "^1.12", "infection/infection": "^0.32", - "tiny-blocks/collection": "^1.10", - "squizlabs/php_codesniffer": "^3.11" + "tiny-blocks/collection": "1.10.*", + "squizlabs/php_codesniffer": "^3.13" }, "scripts": { - "test": "phpunit --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-file": "phpunit --configuration phpunit.xml --no-coverage --filter", - "mutation-test": "infection --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage", - "test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests", + "test": "php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests", + "phpcs": "php ./vendor/bin/phpcs --standard=PSR12 --extensions=php ./src", + "phpstan": "php ./vendor/bin/phpstan analyse -c phpstan.neon.dist --quiet --no-progress", + "test-file": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage --filter", + "mutation-test": "php ./vendor/bin/infection --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage", + "test-no-coverage": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage tests", "review": [ "@phpcs", - "@phpmd", "@phpstan" ], "tests": [ diff --git a/phpmd.xml b/phpmd.xml deleted file mode 100644 index 44cb832..0000000 --- a/phpmd.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - PHPMD Custom rules - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Internal/Mappers/Collection/ValueMapper.php b/src/Internal/Mappers/Collection/ValueMapper.php index d47d11f..2ac6fba 100644 --- a/src/Internal/Mappers/Collection/ValueMapper.php +++ b/src/Internal/Mappers/Collection/ValueMapper.php @@ -14,9 +14,9 @@ public function map(mixed $value, KeyPreservation $keyPreservation): mixed { return match (true) { - is_a($value, UnitEnum::class) => (new EnumMapper())->map(value: $value), - is_a($value, DateTimeInterface::class) => (new DateTimeMapper())->map(value: $value), - is_object($value) => (new ArrayMapper())->map( + is_a($value, UnitEnum::class) => new EnumMapper()->map(value: $value), + is_a($value, DateTimeInterface::class) => new DateTimeMapper()->map(value: $value), + is_object($value) => new ArrayMapper()->map( value: $value, keyPreservation: $keyPreservation ), diff --git a/src/Internal/Mappers/Object/Casters/CollectionCaster.php b/src/Internal/Mappers/Object/Casters/CollectionCaster.php index 753d541..d98d01d 100644 --- a/src/Internal/Mappers/Object/Casters/CollectionCaster.php +++ b/src/Internal/Mappers/Object/Casters/CollectionCaster.php @@ -30,7 +30,7 @@ public function castValue(mixed $value): Collectible $mapped = []; foreach ($value as $item) { - $mapped[] = (new ObjectMapper())->map(iterable: $item, class: $type); + $mapped[] = new ObjectMapper()->map(iterable: $item, class: $type); } return $instance->createFrom(elements: $mapped); diff --git a/src/Internal/Mappers/Object/Casters/DefaultCaster.php b/src/Internal/Mappers/Object/Casters/DefaultCaster.php index 2fb4039..3e87f61 100644 --- a/src/Internal/Mappers/Object/Casters/DefaultCaster.php +++ b/src/Internal/Mappers/Object/Casters/DefaultCaster.php @@ -18,6 +18,6 @@ public function castValue(mixed $value): mixed return $value; } - return (new ObjectMapper())->map(iterable: $value, class: $this->class); + return new ObjectMapper()->map(iterable: $value, class: $this->class); } } diff --git a/src/Internal/Mappers/Object/Reflector.php b/src/Internal/Mappers/Object/Reflector.php index 1faec36..6290bd4 100644 --- a/src/Internal/Mappers/Object/Reflector.php +++ b/src/Internal/Mappers/Object/Reflector.php @@ -29,7 +29,7 @@ public function getParameters(): array return $this->parameters; } - public function newInstance(array $constructorArguments): mixed + public function newInstance(array $constructorArguments): ?object { $instance = $this->constructor && $this->constructor->isPrivate() ? $this->newInstanceWithoutConstructor() @@ -42,7 +42,7 @@ public function newInstance(array $constructorArguments): mixed return $instance; } - public function newInstanceWithoutConstructor(): mixed + public function newInstanceWithoutConstructor(): object { return $this->reflectionClass->newInstanceWithoutConstructor(); } From 2469232f3d68c3458e8ba90e3bde86ea956266d4 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 12 Jan 2026 23:20:25 -0300 Subject: [PATCH 2/5] refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1697dfa..137280f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ permissions: contents: read env: - PHP_VERSION: '8.3' + PHP_VERSION: '8.5' COMPOSER_ROOT_VERSION: '1.2.0' jobs: From daa5ed2f5d8b2e1d12e55a17b567e4f4a5012f84 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 12 Jan 2026 23:21:43 -0300 Subject: [PATCH 3/5] refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 137280f..44ed86c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: tools: composer:2 - name: Download vendor artifact from build - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@v6 with: name: vendor-artifact path: . @@ -82,7 +82,7 @@ jobs: tools: composer:2 - name: Download vendor artifact from build - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@v6 with: name: vendor-artifact path: . From 6b4815269595c6f0a227dd9087fae76941e3d858 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 12 Jan 2026 23:25:56 -0300 Subject: [PATCH 4/5] refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity. --- composer.json | 2 +- src/Internal/Mappers/Object/Reflector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 035e872..3bbf9ac 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ }, "require-dev": { "phpunit/phpunit": "^11.5", - "phpstan/phpstan": "^1.12", + "phpstan/phpstan": "^2.1", "infection/infection": "^0.32", "tiny-blocks/collection": "1.10.*", "squizlabs/php_codesniffer": "^3.13" diff --git a/src/Internal/Mappers/Object/Reflector.php b/src/Internal/Mappers/Object/Reflector.php index 6290bd4..a2a9435 100644 --- a/src/Internal/Mappers/Object/Reflector.php +++ b/src/Internal/Mappers/Object/Reflector.php @@ -29,7 +29,7 @@ public function getParameters(): array return $this->parameters; } - public function newInstance(array $constructorArguments): ?object + public function newInstance(array $constructorArguments): object { $instance = $this->constructor && $this->constructor->isPrivate() ? $this->newInstanceWithoutConstructor() From ed7a204d1688f7919fe831fd20fade2c1b5948c0 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Mon, 12 Jan 2026 23:29:06 -0300 Subject: [PATCH 5/5] refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity. --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44ed86c..e41c407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: tools: composer:2 - name: Download vendor artifact from build - uses: actions/upload-artifact@v6 + uses: actions/download-artifact@v7 with: name: vendor-artifact path: . @@ -82,7 +82,7 @@ jobs: tools: composer:2 - name: Download vendor artifact from build - uses: actions/upload-artifact@v6 + uses: actions/download-artifact@v7 with: name: vendor-artifact path: .