Skip to content

Commit

Permalink
switch to valinor
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekz committed Oct 4, 2024
1 parent 397102b commit f7a1f08
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 120 deletions.
46 changes: 23 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
143 changes: 76 additions & 67 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions src/Challonge/DTO/MatchDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 3 additions & 8 deletions src/Challonge/DTO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 1 addition & 8 deletions src/Challonge/DTO/Tournament.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/Challonge/DtoClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Reflex\Challonge;

use CuyZ\Valinor\MapperBuilder;
use Reflex\Challonge\DTO\BaseDto;

trait DtoClientTrait
Expand All @@ -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]);
}

/**
Expand Down

0 comments on commit f7a1f08

Please sign in to comment.