Skip to content

Commit 37abf68

Browse files
authored
Merge pull request #15 from tiny-blocks/release/2.3.0
2 parents 43c156a + 859875c commit 37abf68

19 files changed

+93
-92
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,49 @@
11
name: CI
22

33
on:
4-
push:
54
pull_request:
65

76
permissions:
87
contents: read
98

9+
env:
10+
PHP_VERSION: '8.3'
11+
1012
jobs:
1113
auto-review:
1214
name: Auto review
1315
runs-on: ubuntu-latest
1416

1517
steps:
1618
- name: Checkout
17-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1820

19-
- name: Use PHP 8.2
21+
- name: Configure PHP
2022
uses: shivammathur/setup-php@v2
2123
with:
22-
php-version: '8.2'
24+
php-version: ${{ env.PHP_VERSION }}
2325

2426
- name: Install dependencies
2527
run: composer update --no-progress --optimize-autoloader
2628

27-
- name: Run phpcs
28-
run: composer phpcs
29-
30-
- name: Run phpmd
31-
run: composer phpmd
29+
- name: Run review
30+
run: composer review
3231

3332
tests:
3433
name: Tests
3534
runs-on: ubuntu-latest
3635

3736
steps:
3837
- name: Checkout
39-
uses: actions/checkout@v3
38+
uses: actions/checkout@v4
4039

41-
- name: Use PHP 8.2
40+
- name: Use PHP ${{ env.PHP_VERSION }}
4241
uses: shivammathur/setup-php@v2
4342
with:
44-
php-version: '8.2'
43+
php-version: ${{ env.PHP_VERSION }}
4544

4645
- name: Install dependencies
4746
run: composer update --no-progress --optimize-autoloader
4847

49-
- name: Run unit tests
50-
env:
51-
XDEBUG_MODE: coverage
52-
run: composer test
53-
54-
- name: Run mutation tests
55-
run: composer test-mutation
48+
- name: Run tests
49+
run: composer tests

Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1-
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.2
1+
DOCKER_RUN = docker run --rm -it --net=host -v ${PWD}:/app -w /app gustavofreze/php:8.3
22

3-
.PHONY: configure test test-file test-no-coverage review fix-style show-reports clean
3+
.PHONY: configure test test-no-coverage review show-reports clean
44

55
configure:
66
@${DOCKER_RUN} composer update --optimize-autoloader
77

88
test:
99
@${DOCKER_RUN} composer tests
1010

11-
test-file:
12-
@${DOCKER_RUN} composer tests-file-no-coverage ${FILE}
13-
1411
test-no-coverage:
1512
@${DOCKER_RUN} composer tests-no-coverage
1613

1714
review:
1815
@${DOCKER_RUN} composer review
1916

20-
fix-style:
21-
@${DOCKER_RUN} composer fix-style
22-
2317
show-reports:
2418
@sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html
2519

2620
clean:
2721
@sudo chown -R ${USER}:${USER} ${PWD}
28-
@rm -rf report vendor
22+
@rm -rf report vendor .phpunit.cache .lock

composer.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,33 @@
4040
}
4141
},
4242
"require": {
43-
"php": "^8.2",
43+
"php": "^8.3",
4444
"tiny-blocks/value-object": "^3"
4545
},
4646
"require-dev": {
4747
"phpmd/phpmd": "^2.15",
4848
"phpstan/phpstan": "^1",
4949
"phpunit/phpunit": "^11",
50-
"infection/infection": "^0.29",
51-
"squizlabs/php_codesniffer": "^3.10"
50+
"infection/infection": "^0",
51+
"squizlabs/php_codesniffer": "^3"
5252
},
5353
"scripts": {
54+
"test": "phpunit --configuration phpunit.xml tests",
5455
"phpcs": "phpcs --standard=PSR12 --extensions=php ./src",
5556
"phpmd": "phpmd ./src text phpmd.xml --suffixes php --exclude /src/Alpha2Code.php,/src/Alpha3Code.php --ignore-violations-on-exit",
5657
"phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress",
57-
"test": "phpunit --log-junit=report/coverage/junit.xml --coverage-xml=report/coverage/coverage-xml --coverage-html=report/coverage/coverage-html tests",
58-
"test-mutation": "infection --only-covered --logger-html=report/coverage/mutation-report.html --coverage=report/coverage --min-msi=100 --min-covered-msi=100 --threads=4",
59-
"test-no-coverage": "phpunit --no-coverage",
60-
"test-mutation-no-coverage": "infection --only-covered --min-msi=100 --threads=4",
58+
"mutation-test": "infection --only-covered --threads=max --logger-html=report/coverage/mutation-report.html --coverage=report/coverage",
59+
"test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests",
6160
"review": [
6261
"@phpcs",
6362
"@phpmd",
6463
"@phpstan"
6564
],
6665
"tests": [
6766
"@test",
68-
"@test-mutation"
67+
"@mutation-test"
6968
],
7069
"tests-no-coverage": [
71-
"@test-no-coverage",
72-
"@test-mutation-no-coverage"
73-
],
74-
"tests-file-no-coverage": [
7570
"@test-no-coverage"
7671
]
7772
}

infection.json.dist

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
{
2-
"timeout": 10,
3-
"testFramework": "phpunit",
2+
"logs": {
3+
"text": "report/infection/logs/infection-text.log",
4+
"summary": "report/infection/logs/infection-summary.log"
5+
},
46
"tmpDir": "report/infection/",
7+
"minMsi": 100,
8+
"timeout": 30,
59
"source": {
610
"directories": [
711
"src"
812
]
913
},
10-
"logs": {
11-
"text": "report/infection/logs/infection-text.log",
12-
"summary": "report/infection/logs/infection-summary.log"
13-
},
14-
"mutators": {
15-
"@default": true,
16-
"PublicVisibility": false
17-
},
1814
"phpUnit": {
1915
"configDir": "",
2016
"customPath": "./vendor/bin/phpunit"
21-
}
17+
},
18+
"mutators": {
19+
"@default": true
20+
},
21+
"minCoveredMsi": 100,
22+
"testFramework": "phpunit"
2223
}

phpunit.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
failOnRisky="true"
77
failOnWarning="true"
88
cacheDirectory=".phpunit.cache"
9+
executionOrder="random"
910
beStrictAboutOutputDuringTests="true">
1011

1112
<source>
@@ -22,14 +23,15 @@
2223

2324
<coverage>
2425
<report>
26+
<xml outputDirectory="report/coverage/coverage-xml"/>
27+
<html outputDirectory="report/coverage/coverage-html"/>
2528
<text outputFile="report/coverage.txt"/>
26-
<html outputDirectory="report/html/"/>
2729
<clover outputFile="report/coverage-clover.xml"/>
2830
</report>
2931
</coverage>
3032

3133
<logging>
32-
<junit outputFile="report/execution-result.xml"/>
34+
<junit outputFile="report/coverage/junit.xml"/>
3335
</logging>
3436

3537
</phpunit>

src/Alpha2Code.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TinyBlocks\Country;
66

7-
use TinyBlocks\Country\Internal\AlphaCode;
87
use TinyBlocks\Country\Internal\AlphaCodeMapper;
98

109
/**
@@ -17,6 +16,8 @@ enum Alpha2Code: string implements AlphaCode
1716
{
1817
use AlphaCodeMapper;
1918

19+
public const int CODE_LENGTH = 2;
20+
2021
case AFGHANISTAN = 'AF';
2122
case ALAND_ISLANDS = 'AX';
2223
case ALBANIA = 'AL';
@@ -259,6 +260,11 @@ enum Alpha2Code: string implements AlphaCode
259260
case ZIMBABWE = 'ZW';
260261
case PALESTINE = 'PS';
261262

263+
public function getName(): string
264+
{
265+
return $this->name;
266+
}
267+
262268
public function toAlpha3(): Alpha3Code
263269
{
264270
$value = $this->getBy(name: $this->name, alphaCodes: Alpha3Code::cases())->value;

src/Alpha3Code.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TinyBlocks\Country;
66

7-
use TinyBlocks\Country\Internal\AlphaCode;
87
use TinyBlocks\Country\Internal\AlphaCodeMapper;
98

109
/**
@@ -18,6 +17,8 @@ enum Alpha3Code: string implements AlphaCode
1817
{
1918
use AlphaCodeMapper;
2019

20+
public const int CODE_LENGTH = 3;
21+
2122
case AFGHANISTAN = 'AFG';
2223
case ALAND_ISLANDS = 'ALA';
2324
case ALBANIA = 'ALB';
@@ -260,6 +261,11 @@ enum Alpha3Code: string implements AlphaCode
260261
case ZIMBABWE = 'ZWE';
261262
case PALESTINE = 'PSE';
262263

264+
public function getName(): string
265+
{
266+
return $this->name;
267+
}
268+
263269
public function toAlpha2(): Alpha2Code
264270
{
265271
$value = $this->getBy(name: $this->name, alphaCodes: Alpha2Code::cases())->value;

src/AlphaCode.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TinyBlocks\Country;
6+
7+
/**
8+
* Defines the contract for classes representing alpha codes of countries.
9+
*/
10+
interface AlphaCode
11+
{
12+
/**
13+
* Gets the name associated with the alpha code.
14+
*
15+
* @return string The name of the country or region corresponding to the code.
16+
*/
17+
public function getName(): string;
18+
}

src/Country.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44

55
namespace TinyBlocks\Country;
66

7-
use TinyBlocks\Country\Internal\AlphaCode;
87
use TinyBlocks\Country\Internal\Exceptions\InvalidAlphaCode;
98
use TinyBlocks\Country\Internal\Exceptions\InvalidAlphaCodeImplementation;
109
use TinyBlocks\Country\Internal\Name;
1110
use TinyBlocks\Vo\ValueObject;
1211
use TinyBlocks\Vo\ValueObjectBehavior;
1312

14-
final class Country implements ValueObject
13+
final readonly class Country implements ValueObject
1514
{
1615
use ValueObjectBehavior;
1716

18-
private const ALPHA2_CODE_LENGTH = 2;
19-
2017
private function __construct(public string $name, public Alpha2Code $alpha2, public Alpha3Code $alpha3)
2118
{
2219
}
2320

24-
public static function from(AlphaCode $alphaCode, string|null $name = null): Country
21+
public static function from(AlphaCode $alphaCode, ?string $name = null): Country
2522
{
2623
$name = empty($name)
2724
? Name::fromAlphaCode(alphaCode: $alphaCode)->value
@@ -38,9 +35,9 @@ public static function from(AlphaCode $alphaCode, string|null $name = null): Cou
3835
throw new InvalidAlphaCodeImplementation(class: $alphaCode::class);
3936
}
4037

41-
public static function fromString(string $alphaCode, string|null $name = null): Country
38+
public static function fromString(string $alphaCode, ?string $name = null): Country
4239
{
43-
$alphaCodeFrom = strlen($alphaCode) === self::ALPHA2_CODE_LENGTH
40+
$alphaCodeFrom = strlen($alphaCode) === Alpha2Code::CODE_LENGTH
4441
? Alpha2Code::tryFrom(value: $alphaCode)
4542
: Alpha3Code::tryFrom(value: $alphaCode);
4643

src/Internal/AlphaCode.php

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

0 commit comments

Comments
 (0)