diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97f5fd8..dfa6a14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,31 +8,31 @@ jobs: strategy: fail-fast: true matrix: - php: [ 8.1, 8.2 ] + php: [8.1, 8.2, 8.3] dependency-version: [prefer-stable] name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} steps: - - name: Checkout code - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: mbstring, iconv - coverage: none - - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - - name: Install dependencies - run: | - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/phpunit + - name: Checkout code + uses: actions/checkout@v1 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, iconv + coverage: none + + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ~/.composer/cache/files + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Install dependencies + run: | + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/Makefile b/Makefile index 360f380..f0b0a23 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,13 @@ composer-add-dep: $(user) \ composer:latest require $(module) --ignore-platform-reqs --no-scripts +# remove PHP Dependencies via Composer - usage make composer-rm-dep module=module/namehere +composer-rm-dep: + docker run --rm --name compose-maintainence-update --interactive \ + --volume $(currentDir):/app \ + $(user) \ + composer:latest remove $(module) --ignore-platform-reqs --no-scripts + # add Dev PHP Dependencies via Composer - usage make composer-add-dep-dev module=module/namehere composer-add-dep-dev: docker run --rm --name compose-maintainence-update --interactive \ diff --git a/composer.json b/composer.json index 949d417..c40f8f8 100644 --- a/composer.json +++ b/composer.json @@ -3,12 +3,12 @@ "description": "PSR-18 compatible library to interface with the bracket generator Challonge.", "require": { "ext-json": "*", - "php": "^8.1 | ^8.2", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "psr/http-client": "^1.0", "psr/log": "^3.0", "illuminate/collections": "~9| ~10", - "spatie/data-transfer-object": "^2.5", - "nyholm/psr7": "^1.6.1" + "nyholm/psr7": "^1.6.1", + "cuyz/valinor": "^1.13" }, "require-dev": { "phpunit/phpunit": "^9.4", diff --git a/composer.lock b/composer.lock index 5d3fe82..cd1e590 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,81 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c8541f84990dfb9c6062d73e13f98b96", + "content-hash": "7c0f8c459b5756d8db1526a0af545304", "packages": [ + { + "name": "cuyz/valinor", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/CuyZ/Valinor.git", + "reference": "4e0bc8b6a9ca4ce5350a8206f7c8d81664806a01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/CuyZ/Valinor/zipball/4e0bc8b6a9ca4ce5350a8206f7c8d81664806a01", + "reference": "4e0bc8b6a9ca4ce5350a8206f7c8d81664806a01", + "shasum": "" + }, + "require": { + "composer-runtime-api": "^2.0", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.4", + "infection/infection": "^0.27", + "marcocesarato/php-conventional-changelog": "^1.12", + "mikey179/vfsstream": "^1.6.10", + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^10.5", + "rector/rector": "^1.0", + "vimeo/psalm": "^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "CuyZ\\Valinor\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Romain Canon", + "email": "romain.hydrocanon@gmail.com", + "homepage": "https://github.com/romm" + } + ], + "description": "Library that helps to map any input into a strongly-typed value object structure.", + "homepage": "https://github.com/CuyZ/Valinor", + "keywords": [ + "array", + "conversion", + "hydrator", + "json", + "mapper", + "mapping", + "object", + "tree", + "yaml" + ], + "support": { + "issues": "https://github.com/CuyZ/Valinor/issues", + "source": "https://github.com/CuyZ/Valinor/tree/1.13.0" + }, + "funding": [ + { + "url": "https://github.com/romm", + "type": "github" + } + ], + "time": "2024-09-02T12:57:33+00:00" + }, { "name": "illuminate/collections", "version": "v10.13.5", @@ -592,70 +665,6 @@ "source": "https://github.com/php-fig/simple-cache/tree/3.0.0" }, "time": "2021-10-29T13:26:27+00:00" - }, - { - "name": "spatie/data-transfer-object", - "version": "2.8.4", - "source": { - "type": "git", - "url": "https://github.com/spatie/data-transfer-object.git", - "reference": "167ebbe56ead65ef23abcfae7b75f932afd496a4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/spatie/data-transfer-object/zipball/167ebbe56ead65ef23abcfae7b75f932afd496a4", - "reference": "167ebbe56ead65ef23abcfae7b75f932afd496a4", - "shasum": "" - }, - "require": { - "php": "^7.4|^8.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.0" - }, - "suggest": { - "phpstan/phpstan": "Take advantage of checkUninitializedProperties with \\Spatie\\DataTransferObject\\PHPstan\\PropertiesAreAlwaysInitializedExtension" - }, - "type": "library", - "autoload": { - "psr-4": { - "Spatie\\DataTransferObject\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Brent Roose", - "email": "brent@spatie.be", - "homepage": "https://spatie.be", - "role": "Developer" - } - ], - "description": "Data transfer objects with batteries included", - "homepage": "https://github.com/spatie/data-transfer-object", - "keywords": [ - "data-transfer-object", - "spatie" - ], - "support": { - "issues": "https://github.com/spatie/data-transfer-object/issues", - "source": "https://github.com/spatie/data-transfer-object/tree/2.8.4" - }, - "funding": [ - { - "url": "https://spatie.be/open-source/support-us", - "type": "custom" - }, - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "abandoned": "spatie/laravel-data", - "time": "2021-12-07T05:41:11+00:00" } ], "packages-dev": [ @@ -3772,8 +3781,8 @@ "prefer-lowest": false, "platform": { "ext-json": "*", - "php": "^8.0 | ^8.1 | ^8.2" + "php": "~8.1.0 || ~8.2.0 || ~8.3.0" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Challonge/DTO/MatchDto.php b/src/Challonge/DTO/MatchDto.php index 41e6573..e7ca974 100644 --- a/src/Challonge/DTO/MatchDto.php +++ b/src/Challonge/DTO/MatchDto.php @@ -3,18 +3,11 @@ namespace Reflex\Challonge\DTO; use Reflex\Challonge\DtoClientTrait; -use Spatie\DataTransferObject\DataTransferObject; -class MatchDto extends DataTransferObject +class MatchDto { use DtoClientTrait; - /** - * Due to Challonge not locking their API and constantly adding new fields... - * @var bool - */ - protected bool $ignoreMissing = true; - public ?int $attachment_count; public ?string $completed_at; public string $created_at; diff --git a/src/Challonge/DTO/Participant.php b/src/Challonge/DTO/Participant.php index 9b3c348..a4f17dd 100644 --- a/src/Challonge/DTO/Participant.php +++ b/src/Challonge/DTO/Participant.php @@ -3,18 +3,11 @@ namespace Reflex\Challonge\DTO; use Reflex\Challonge\DtoClientTrait; -use Spatie\DataTransferObject\DataTransferObject; -class Participant extends DataTransferObject +class Participant { use DtoClientTrait; - /** - * Due to Challonge not locking their API and constantly adding new fields... - * @var bool - */ - protected bool $ignoreMissing = true; - public bool $active; public bool $check_in_open; public ?string $checked_in_at; @@ -51,6 +44,8 @@ class Participant extends DataTransferObject public bool $can_check_in; public bool $checked_in; public bool $reactivatable; + public array $groups; + public array $final; /** * Update the attributes of a tournament participant. diff --git a/src/Challonge/DTO/Tournament.php b/src/Challonge/DTO/Tournament.php index d7dac53..17b97a6 100644 --- a/src/Challonge/DTO/Tournament.php +++ b/src/Challonge/DTO/Tournament.php @@ -6,18 +6,11 @@ use Reflex\Challonge\DtoClientTrait; use Reflex\Challonge\Exceptions\StillRunningException; use Reflex\Challonge\Exceptions\AlreadyStartedException; -use Spatie\DataTransferObject\DataTransferObject; -class Tournament extends DataTransferObject +class Tournament { use DtoClientTrait; - /** - * Due to Challonge not locking their API and constantly adding new fields... - * @var bool - */ - protected bool $ignoreMissing = true; - public int $id; public string $name; public string $url; diff --git a/src/Challonge/DtoClientTrait.php b/src/Challonge/DtoClientTrait.php index 64d8585..937f3a8 100644 --- a/src/Challonge/DtoClientTrait.php +++ b/src/Challonge/DtoClientTrait.php @@ -2,6 +2,7 @@ namespace Reflex\Challonge; +use CuyZ\Valinor\MapperBuilder; use Reflex\Challonge\DTO\BaseDto; trait DtoClientTrait @@ -16,9 +17,14 @@ trait DtoClientTrait */ public static function fromResponse(ClientWrapper $client, array $data): self { - $dto = new self($data); - $dto->setClient($client); - return $dto; + return (new MapperBuilder()) + ->enableFlexibleCasting() + // challonge doesn't lock their API, and constantly adds new fields + ->allowSuperfluousKeys() + // property types aren't documented anywhere + ->allowPermissiveTypes() + ->mapper() + ->map(self::class, [...$data, "client" => $client]); } /**