Skip to content

Commit

Permalink
Extend annotations for Id and IdList (#67)
Browse files Browse the repository at this point in the history
* Update psalm

* Add coverage command

* Make it clear that id classes must be final

* Adapt id list

* Prevent comparison of different ids

* Revert id checks

* Fix import

* Adapt makefile

* Prepare release notes

* Test new badges

* Php version badge

* Switch to hex

* Switch to total downloads

* License

* Space in version

* Without spaces

---------

Co-authored-by: Christian Kolb <[email protected]>
  • Loading branch information
christian-kolb and Christian Kolb authored Aug 3, 2024
1 parent 3d6f05d commit dc49527
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 292 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.1

- Extend annotations for `Id` and `IdList`.

## 1.2.0

- Renamed parameter `$exception` to `$otherwiseThrow` in the guard methods of `Id` and `IdList` to make it more clear what the parameter does when using named parameters.
Expand Down
40 changes: 22 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ help: Makefile
## build Build the Docker images.
.PHONY: build
build:
docker-compose build
docker compose build

## up Start the Docker stack.
.PHONY: up
up: .up

.up:
docker-compose up -d
docker compose up -d

## down Stop the Docker stack.
.PHONY: down
down: .down

.down:
docker-compose down
docker compose down

## update Rebuild Docker images and start stack.
.PHONY: update
Expand All @@ -59,12 +59,12 @@ install: install-8.3
## install-8.2 Install PHP dependencies with PHP 8.2.
.PHONY: install-8.2
install-8.2:
docker-compose run --rm php-8.2 composer install
docker compose run --rm php-8.2 composer install

## install-8.3 Install PHP dependencies with PHP 8.3.
.PHONY: install-8.3
install-8.3:
docker-compose run --rm php-8.3 composer install
docker compose run --rm php-8.3 composer install

## php-cli Enter a shell for the default PHP version (8.3).
.PHONY: php-cli
Expand All @@ -73,12 +73,12 @@ php-cli: php-8.3-cli
## php-8.2-cli Enter a shell for PHP 8.2.
.PHONY: php-8.2-cli
php-8.2-cli:
docker-compose run --rm php-8.2 sh
docker compose run --rm php-8.2 sh

## php-8.3-cli Enter a shell for PHP 8.3.
.PHONY: php-8.3-cli
php-8.3-cli:
docker-compose run --rm php-8.3 sh
docker compose run --rm php-8.3 sh

##
## Tests and code validation
Expand All @@ -93,37 +93,41 @@ verify: php-code-validation php-tests php-mutation-testing
.PHONY: php-tests
php-tests: php-8.2-tests php-8.3-tests

## php-tests-coverage Run the tests for all relevant PHP versions including coverage report as HTML.
.PHONY: php-tests-coverage
php-tests-coverage: php-8.3-tests-html-coverage

## php-8.2-tests Run tests with PHP 8.2.
.PHONY: php-8.2-tests
php-8.2-tests:
docker-compose run --rm php-8.2 ./vendor/bin/phpunit
docker compose run --rm php-8.2 ./vendor/bin/phpunit

## php-8.3-tests Run tests with PHP 8.3.
.PHONY: php-8.3-tests
php-8.3-tests:
docker-compose run --rm php-8.3 ./vendor/bin/phpunit
docker compose run --rm php-8.3 ./vendor/bin/phpunit

## php-8.2-tests-html-coverage Run the tests with PHP 8.2 including coverage report as HTML.
.PHONY: php-8.2-tests-html-coverage
php-8.2-tests-html-coverage:
docker-compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-html ./coverage
docker compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-html ./coverage

## php-8.3-tests-html-coverage Run the tests with PHP 8.3 including coverage report as HTML.
.PHONY: php-8.3-tests-html-coverage
php-8.3-tests-html-coverage:
docker-compose run --rm php-8.3 ./vendor/bin/phpunit --coverage-html ./coverage
docker compose run --rm php-8.3 ./vendor/bin/phpunit --coverage-html ./coverage

## php-code-validation Run code fixers and linters with default PHP version (8.2).
.PHONY: php-code-validation
php-code-validation:
docker-compose run --rm php-8.2 ./vendor/bin/php-cs-fixer fix
docker-compose run --rm php-8.2 ./vendor/bin/psalm --show-info=false --no-diff
docker-compose run --rm php-8.2 ./vendor/bin/phpstan --xdebug
docker compose run --rm php-8.2 ./vendor/bin/php-cs-fixer fix
docker compose run --rm php-8.2 ./vendor/bin/psalm --show-info=false --no-diff
docker compose run --rm php-8.2 ./vendor/bin/phpstan --xdebug

## php-mutation-testing Run mutation testing with default PHP version (8.2).
.PHONY: php-mutation-testing
php-mutation-testing:
docker-compose run --rm php-8.2 ./vendor/bin/infection --show-mutations --only-covered --threads=8
docker compose run --rm php-8.2 ./vendor/bin/infection --show-mutations --only-covered --threads=8

##
## CI
Expand All @@ -133,14 +137,14 @@ php-mutation-testing:
## php-8.2-tests-ci Run the tests for PHP 8.2 for CI.
.PHONY: php-8.2-tests-ci
php-8.2-tests-ci:
docker-compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-clover ./coverage.xml
docker compose run --rm php-8.2 ./vendor/bin/phpunit --coverage-clover ./coverage.xml

## php-8.3-tests-ci Run the tests for PHP 8.3 for CI.
.PHONY: php-8.3-tests-ci
php-8.3-tests-ci:
docker-compose run --rm php-8.3 ./vendor/bin/phpunit
docker compose run --rm php-8.3 ./vendor/bin/phpunit

## php-mutation-testing-ci Run mutation testing for CI.
.PHONY: php-mutation-testing-ci
php-mutation-testing-ci:
docker-compose run --rm php-8.2 ./vendor/bin/infection --only-covered --threads=max
docker compose run --rm php-8.2 ./vendor/bin/infection --only-covered --threads=max
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ A Symfony bundle to work with id and id list value objects in Symfony. It includ

As it's a central part of an application, it's tested thoroughly (including mutation testing).

[![Latest Stable Version](http://poser.pugx.org/digital-craftsman/ids/v)](https://packagist.org/packages/digital-craftsman/ids)
[![PHP Version Require](http://poser.pugx.org/digital-craftsman/ids/require/php)](https://packagist.org/packages/digital-craftsman/ids)
[![Latest Stable Version](https://img.shields.io/badge/stable-1.2.1-blue)](https://packagist.org/packages/digital-craftsman/ids)
[![PHP Version Require](https://img.shields.io/badge/php-8.2|8.3-5b5d95)](https://packagist.org/packages/digital-craftsman/ids)
[![codecov](https://codecov.io/gh/digital-craftsman-de/ids/branch/main/graph/badge.svg?token=BL0JKZYLBG)](https://codecov.io/gh/digital-craftsman-de/ids)
[![Total Downloads](http://poser.pugx.org/digital-craftsman/ids/downloads)](https://packagist.org/packages/digital-craftsman/ids)
[![License](http://poser.pugx.org/digital-craftsman/ids/license)](https://packagist.org/packages/digital-craftsman/ids)
![Packagist Downloads](https://img.shields.io/packagist/dt/digital-craftsman/ids)
![Packagist License](https://img.shields.io/packagist/l/digital-craftsman/ids)

## Installation and configuration

Expand All @@ -24,7 +24,7 @@ It's recommended that you install the [`uuid` PHP extension](https://pecl.php.ne

### Creating a new id

The bulk of the logic is in the `Id` class. Creating a new id is as simple as creating a new class and extending from it like the following:
The bulk of the logic is in the `Id` class. Creating a new id is as simple as creating a new `final readonly class` and extending from it like the following:

```php
<?php
Expand Down Expand Up @@ -178,7 +178,7 @@ The `IdList` is immutable. Therefore, the mutation methods (like `add`, `remove`

### Creating a new id list

The bulk of the logic is in the `IdList` class. Creating a new id list is as simple as creating a new class and extending from it like the following:
The bulk of the logic is in the `IdList` class. Creating a new id list is as simple as creating a new `final readonly class` and extending from it like the following:

```php
<?php
Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade guide

## From 1.2.0 to 1.2.1

- Run Psalm to see if the new annotations find any issues know visible (make sure that all your `Id` and `IdList` classes are `final`).

## From 1.1.0 to 1.2.0

Nothing to do.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"symfony/polyfill-uuid": "^1.26"
},
"require-dev": {
"vimeo/psalm": "^5.17",
"vimeo/psalm": "^5.25",
"friendsofphp/php-cs-fixer": "^3.3",
"phpunit/phpunit": "^9.5",
"infection/infection": "^0.26.15",
Expand Down
Loading

0 comments on commit dc49527

Please sign in to comment.