Skip to content

Commit 882c334

Browse files
authored
Release/1.4.0 (#20)
* refactor: Update CI workflow, improve PHP version handling, and refactor code for clarity.
1 parent eef33fb commit 882c334

File tree

9 files changed

+114
-107
lines changed

9 files changed

+114
-107
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/README.md export-ignore
55
/LICENSE export-ignore
66
/Makefile export-ignore
7-
/phpmd.xml export-ignore
87
/phpunit.xml export-ignore
98
/phpstan.neon.dist export-ignore
109
/infection.json.dist export-ignore

.github/workflows/ci.yml

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,43 @@ permissions:
77
contents: read
88

99
env:
10-
PHP_VERSION: '8.3'
10+
PHP_VERSION: '8.5'
1111
COMPOSER_ROOT_VERSION: '1.2.0'
1212

1313
jobs:
14+
build:
15+
name: Build
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v6
21+
22+
- name: Configure PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ env.PHP_VERSION }}
26+
extensions: bcmath
27+
tools: composer:2
28+
29+
- name: Validate composer.json
30+
run: composer validate --no-interaction
31+
32+
- name: Install dependencies
33+
run: composer install --no-progress --optimize-autoloader --prefer-dist --no-interaction
34+
35+
- name: Upload vendor and composer.lock as artifact
36+
uses: actions/upload-artifact@v6
37+
with:
38+
name: vendor-artifact
39+
path: |
40+
vendor
41+
composer.lock
42+
1443
auto-review:
1544
name: Auto review
1645
runs-on: ubuntu-latest
46+
needs: build
1747

1848
steps:
1949
- name: Checkout
@@ -23,28 +53,39 @@ jobs:
2353
uses: shivammathur/setup-php@v2
2454
with:
2555
php-version: ${{ env.PHP_VERSION }}
56+
extensions: bcmath
57+
tools: composer:2
2658

27-
- name: Install dependencies
28-
run: composer update --no-progress --optimize-autoloader
59+
- name: Download vendor artifact from build
60+
uses: actions/download-artifact@v7
61+
with:
62+
name: vendor-artifact
63+
path: .
2964

3065
- name: Run review
3166
run: composer review
3267

3368
tests:
3469
name: Tests
3570
runs-on: ubuntu-latest
71+
needs: auto-review
3672

3773
steps:
3874
- name: Checkout
3975
uses: actions/checkout@v6
4076

41-
- name: Use PHP ${{ env.PHP_VERSION }}
77+
- name: Configure PHP
4278
uses: shivammathur/setup-php@v2
4379
with:
4480
php-version: ${{ env.PHP_VERSION }}
81+
extensions: bcmath
82+
tools: composer:2
4583

46-
- name: Install dependencies
47-
run: composer update --no-progress --optimize-autoloader
84+
- name: Download vendor artifact from build
85+
uses: actions/download-artifact@v7
86+
with:
87+
name: vendor-artifact
88+
path: .
4889

4990
- name: Run tests
5091
run: composer tests

Makefile

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,68 @@
1-
ifeq ($(OS),Windows_NT)
2-
PWD := $(shell cd)
3-
else
4-
PWD := $(shell pwd -L)
5-
endif
6-
1+
PWD := $(CURDIR)
72
ARCH := $(shell uname -m)
83
PLATFORM :=
94

105
ifeq ($(ARCH),arm64)
116
PLATFORM := --platform=linux/amd64
127
endif
138

14-
DOCKER_RUN = docker run ${PLATFORM} --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3
9+
DOCKER_RUN = docker run ${PLATFORM} --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.5-alpine
1510

16-
.PHONY: configure test test-file test-no-coverage review show-reports clean
11+
RESET := \033[0m
12+
GREEN := \033[0;32m
13+
YELLOW := \033[0;33m
1714

18-
configure:
15+
.DEFAULT_GOAL := help
16+
17+
.PHONY: configure
18+
configure: ## Configure development environment
1919
@${DOCKER_RUN} composer update --optimize-autoloader
2020

21-
test:
21+
.PHONY: test
22+
test: ## Run all tests with coverage
2223
@${DOCKER_RUN} composer tests
2324

24-
test-file:
25+
.PHONY: test-file
26+
test-file: ## Run tests for a specific file (usage: make test-file FILE=path/to/file)
2527
@${DOCKER_RUN} composer test-file ${FILE}
2628

27-
test-no-coverage:
29+
.PHONY: test-no-coverage
30+
test-no-coverage: ## Run all tests without coverage
2831
@${DOCKER_RUN} composer tests-no-coverage
2932

30-
review:
33+
.PHONY: review
34+
review: ## Run static code analysis
3135
@${DOCKER_RUN} composer review
3236

33-
show-reports:
37+
.PHONY: show-reports
38+
show-reports: ## Open static analysis reports (e.g., coverage, lints) in the browser
3439
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html
3540

36-
clean:
41+
.PHONY: clean
42+
clean: ## Remove dependencies and generated artifacts
3743
@sudo chown -R ${USER}:${USER} ${PWD}
3844
@rm -rf report vendor .phpunit.cache *.lock
45+
46+
.PHONY: help
47+
help: ## Display this help message
48+
@echo "Usage: make [target]"
49+
@echo ""
50+
@echo "$$(printf '$(GREEN)')Setup$$(printf '$(RESET)')"
51+
@grep -E '^(configure):.*?## .*$$' $(MAKEFILE_LIST) \
52+
| awk 'BEGIN {FS = ":.*? ## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}'
53+
@echo ""
54+
@echo "$$(printf '$(GREEN)')Testing$$(printf '$(RESET)')"
55+
@grep -E '^(test|test-file|test-no-coverage):.*?## .*$$' $(MAKEFILE_LIST) \
56+
| awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}'
57+
@echo ""
58+
@echo "$$(printf '$(GREEN)')Quality$$(printf '$(RESET)')"
59+
@grep -E '^(review):.*?## .*$$' $(MAKEFILE_LIST) \
60+
| awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}'
61+
@echo ""
62+
@echo "$$(printf '$(GREEN)')Reports$$(printf '$(RESET)')"
63+
@grep -E '^(show-reports):.*?## .*$$' $(MAKEFILE_LIST) \
64+
| awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}'
65+
@echo ""
66+
@echo "$$(printf '$(GREEN)')Cleanup$$(printf '$(RESET)')"
67+
@grep -E '^(clean):.*?## .*$$' $(MAKEFILE_LIST) \
68+
| awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}'

composer.json

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"issues": "https://github.com/tiny-blocks/mapper/issues",
2626
"source": "https://github.com/tiny-blocks/mapper"
2727
},
28+
"extra": {
29+
"branch-alias": {
30+
"dev-develop": "1.3.x-dev"
31+
}
32+
},
2833
"config": {
2934
"sort-packages": true,
3035
"allow-plugins": {
@@ -42,27 +47,24 @@
4247
}
4348
},
4449
"require": {
45-
"php": "^8.3"
50+
"php": "^8.5"
4651
},
4752
"require-dev": {
48-
"phpmd/phpmd": "^2.15",
49-
"phpunit/phpunit": "^12.1",
53+
"phpunit/phpunit": "^11.5",
5054
"phpstan/phpstan": "^2.1",
5155
"infection/infection": "^0.32",
52-
"tiny-blocks/collection": "^1.10",
53-
"squizlabs/php_codesniffer": "^3.11"
56+
"tiny-blocks/collection": "1.10.*",
57+
"squizlabs/php_codesniffer": "^3.13"
5458
},
5559
"scripts": {
56-
"test": "phpunit --configuration phpunit.xml tests",
57-
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
58-
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit",
59-
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
60-
"test-file": "phpunit --configuration phpunit.xml --no-coverage --filter",
61-
"mutation-test": "infection --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage",
62-
"test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests",
60+
"test": "php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests",
61+
"phpcs": "php ./vendor/bin/phpcs --standard=PSR12 --extensions=php ./src",
62+
"phpstan": "php ./vendor/bin/phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
63+
"test-file": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage --filter",
64+
"mutation-test": "php ./vendor/bin/infection --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage",
65+
"test-no-coverage": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage tests",
6366
"review": [
6467
"@phpcs",
65-
"@phpmd",
6668
"@phpstan"
6769
],
6870
"tests": [

phpmd.xml

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/Internal/Mappers/Collection/ValueMapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
public function map(mixed $value, KeyPreservation $keyPreservation): mixed
1515
{
1616
return match (true) {
17-
is_a($value, UnitEnum::class) => (new EnumMapper())->map(value: $value),
18-
is_a($value, DateTimeInterface::class) => (new DateTimeMapper())->map(value: $value),
19-
is_object($value) => (new ArrayMapper())->map(
17+
is_a($value, UnitEnum::class) => new EnumMapper()->map(value: $value),
18+
is_a($value, DateTimeInterface::class) => new DateTimeMapper()->map(value: $value),
19+
is_object($value) => new ArrayMapper()->map(
2020
value: $value,
2121
keyPreservation: $keyPreservation
2222
),

src/Internal/Mappers/Object/Casters/CollectionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function castValue(mixed $value): Collectible
3030
$mapped = [];
3131

3232
foreach ($value as $item) {
33-
$mapped[] = (new ObjectMapper())->map(iterable: $item, class: $type);
33+
$mapped[] = new ObjectMapper()->map(iterable: $item, class: $type);
3434
}
3535

3636
return $instance->createFrom(elements: $mapped);

src/Internal/Mappers/Object/Casters/DefaultCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function castValue(mixed $value): mixed
1818
return $value;
1919
}
2020

21-
return (new ObjectMapper())->map(iterable: $value, class: $this->class);
21+
return new ObjectMapper()->map(iterable: $value, class: $this->class);
2222
}
2323
}

src/Internal/Mappers/Object/Reflector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getParameters(): array
2929
return $this->parameters;
3030
}
3131

32-
public function newInstance(array $constructorArguments): mixed
32+
public function newInstance(array $constructorArguments): object
3333
{
3434
$instance = $this->constructor && $this->constructor->isPrivate()
3535
? $this->newInstanceWithoutConstructor()
@@ -42,7 +42,7 @@ public function newInstance(array $constructorArguments): mixed
4242
return $instance;
4343
}
4444

45-
public function newInstanceWithoutConstructor(): mixed
45+
public function newInstanceWithoutConstructor(): object
4646
{
4747
return $this->reflectionClass->newInstanceWithoutConstructor();
4848
}

0 commit comments

Comments
 (0)