From 01e16f153ec74b2a69d62f7f46f382c91227e8ca Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 5 Nov 2026 11:35:20 +0100 Subject: [PATCH 1/6] Added archived on matter --- src/Model/Matter.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Model/Matter.php b/src/Model/Matter.php index 70c040b..8ec2f2f 100644 --- a/src/Model/Matter.php +++ b/src/Model/Matter.php @@ -21,6 +21,7 @@ final class Matter extends AbstractF2Item public ?string $title = null; public ?string $type = null; public ?string $accessLevel = null; + public ?bool $archived = null; public ?string $caseNumber = null; public ?\DateTimeImmutable $createdDate = null; public ?\DateTimeImmutable $modifiedDate = null; @@ -40,6 +41,7 @@ public function setFromSimpleXMLElement(\SimpleXMLElement $sxe): static $this->title = (string) $sxe->Title; $this->type = (string) $sxe->Type; $this->accessLevel = (string) $sxe->AccessLevel; + $this->archived = 'true' === (string) $sxe->Archived; $this->createdDate = $this->createDateTime($sxe->CreatedDate); $this->modifiedDate = $this->createDateTime($sxe->ModifiedDate); $this->createdBy = Party::fromSimpleXMLElement($sxe->CreatedBy); @@ -61,6 +63,7 @@ public function apiSerialize(): array 'Title' => $this->title, 'Type' => $this->type, 'AccessLevel' => $this->accessLevel, + 'Archived' => $this->archived ? 'true' : 'false', ]; } } From 87ae998f5f233e993394ff95d154b6c26c07fc1a Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 5 Nov 2026 15:10:32 +0100 Subject: [PATCH 2/6] Added helper function the handle boolean properties --- src/Model/AbstractItem.php | 10 ++++++++++ src/Model/Matter.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Model/AbstractItem.php b/src/Model/AbstractItem.php index e10f886..990c8c9 100644 --- a/src/Model/AbstractItem.php +++ b/src/Model/AbstractItem.php @@ -38,6 +38,16 @@ protected static function listOf(string $class, \SimpleXMLElement $sxe): array return $items; } + protected function parseBoolean(\SimpleXMLElement|string $value): bool + { + return 'true' === trim((string) $value); + } + + protected function formatBoolean(bool $value): string + { + return $value ? 'true' : 'false'; + } + protected function createDateTime(\SimpleXMLElement|string $value): ?\DateTimeImmutable { // @todo Adjust for time zones! diff --git a/src/Model/Matter.php b/src/Model/Matter.php index 8ec2f2f..ee80649 100644 --- a/src/Model/Matter.php +++ b/src/Model/Matter.php @@ -41,7 +41,7 @@ public function setFromSimpleXMLElement(\SimpleXMLElement $sxe): static $this->title = (string) $sxe->Title; $this->type = (string) $sxe->Type; $this->accessLevel = (string) $sxe->AccessLevel; - $this->archived = 'true' === (string) $sxe->Archived; + $this->archived = $this->parseBoolean($sxe->Archived); $this->createdDate = $this->createDateTime($sxe->CreatedDate); $this->modifiedDate = $this->createDateTime($sxe->ModifiedDate); $this->createdBy = Party::fromSimpleXMLElement($sxe->CreatedBy); From 93e33f57addeb6ae2d5b38b2aa296005fa3a2ddc Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Thu, 5 Nov 2026 15:11:05 +0100 Subject: [PATCH 3/6] Added responsible party to matter --- mago.toml | 2 +- src/Model/Matter.php | 10 ++++++++-- src/Model/Party.php | 19 +++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/mago.toml b/mago.toml index 6011871..43f5d90 100644 --- a/mago.toml +++ b/mago.toml @@ -40,7 +40,7 @@ no-boolean-flag-parameter = { enabled = false } literal-named-argument = { enabled = false } halstead = { effort-threshold = 7000, - difficulty-threshold = 22 + difficulty-threshold = 25 } # Our Model classes have a lot of constructor arguments. diff --git a/src/Model/Matter.php b/src/Model/Matter.php index ee80649..2daaebc 100644 --- a/src/Model/Matter.php +++ b/src/Model/Matter.php @@ -57,13 +57,19 @@ public function __toString(): string return sprintf('Matter %s: %s (#%d)', $this->matterNumber, $this->title, $this->id); } + #[\Override] public function apiSerialize(): array { - return [ + $serialized = [ 'Title' => $this->title, 'Type' => $this->type, 'AccessLevel' => $this->accessLevel, - 'Archived' => $this->archived ? 'true' : 'false', + 'Archived' => $this->formatBoolean($this->archived ?? false), ]; + if ($this->responsible) { + $serialized['Responsible'] = $this->responsible->apiSerialize(); + } + + return $serialized; } } diff --git a/src/Model/Party.php b/src/Model/Party.php index 9503f59..9f70274 100644 --- a/src/Model/Party.php +++ b/src/Model/Party.php @@ -8,10 +8,10 @@ final class Party extends AbstractF2Item { // @see resources/f2-rest-docs/f2-rest-docs-v13s.html#56 - public string $name; - public string $email; - public string $type; - public int $partyNumber; + public ?string $name = null; + public ?string $email = null; + public ?string $type = null; + public ?int $partyNumber = null; // @mago-ignore analysis:non-documented-property #[\Override] @@ -33,4 +33,15 @@ public function __toString(): string { return sprintf('Party: %s (%s)', $this->name, $this->type); } + + #[\Override] + public function apiSerialize(): array + { + return array_filter([ + 'name' => $this->name, + 'email' => $this->email, + 'type' => $this->type, + 'partyNumber' => $this->partyNumber, + ]); + } } From e6421bd38a7a028bab5e92615063a7d63457e8d9 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Fri, 6 Nov 2026 07:33:51 +0100 Subject: [PATCH 4/6] Added rector and some tests --- .editorconfig | 3 +++ .github/workflows/test.yaml | 25 +++++++++++++++++++++++++ Taskfile.yml | 20 ++++++++++++++++++++ composer.json | 4 +++- rector.php | 20 ++++++++++++++++++++ src/ApiClient.php | 12 +++++------- src/Model/Atom.php | 2 +- src/Model/Collection/Item.php | 2 +- src/Model/F2Item/Links.php | 2 +- tests/Model/MatterTest.php | 33 +++++++++++++++++++++++++++++++++ 10 files changed, 112 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100644 rector.php create mode 100644 tests/Model/MatterTest.php diff --git a/.editorconfig b/.editorconfig index cc08445..d912803 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ indent_size = 4 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true + +[Taskfile.yml] +indent_size = 2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..72af5fc --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,25 @@ +name: Test + +env: + COMPOSE_USER: runner + +on: + pull_request: + push: + branches: + - main + - develop + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v7 + + - run: | + docker compose run --rm phpfpm composer install + + - run: | + docker compose run --rm phpfpm php vendor/bin/phpunit tests diff --git a/Taskfile.yml b/Taskfile.yml index 03bcc57..2449b58 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -13,6 +13,13 @@ tasks: - task --list silent: true + test: + desc: Run all tests + cmd: + task: compose + vars: + TASK_ARGS: run --rm phpfpm php vendor/bin/phpunit tests + compose: cmds: - docker compose {{.TASK_ARGS}} {{.CLI_ARGS}} @@ -30,6 +37,7 @@ tasks: - task: coding-standards:markdown:apply - task: coding-standards:php:apply - task: coding-standards:php:mago:apply + - task: coding-standards:rector:apply - task: coding-standards:yaml:apply coding-standards:check: @@ -37,6 +45,7 @@ tasks: - task: coding-standards:markdown:check - task: coding-standards:php:check - task: coding-standards:php:mago:check + - task: coding-standards:rector:check - task: coding-standards:yaml:check coding-standards:composer:apply: @@ -87,6 +96,17 @@ tasks: vars: TASK_ARGS: run --rm mago lint + coding-standards:rector:apply: + - task: compose + vars: + TASK_ARGS: run --rm phpfpm php vendor/bin/rector + + coding-standards:rector:check: + - task: coding-standards:rector:apply + - task: compose + vars: + TASK_ARGS: run --rm phpfpm php vendor/bin/rector --dry-run + coding-standards:yaml:apply: - task: compose vars: diff --git a/composer.json b/composer.json index 4da87b9..4125dc5 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,9 @@ "require-dev": { "ergebnis/composer-normalize": "^2.52", "friendsofphp/php-cs-fixer": "^3.95", - "phpstan/phpstan": "^2.2" + "phpstan/phpstan": "^2.2", + "phpunit/phpunit": "^12", + "rector/rector": "^2.7" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..04e3971 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withRules([ + SafeDeclareStrictTypesRector::class, + ]) + // uncomment to reach your current PHP version + ->withPhpSets() + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/src/ApiClient.php b/src/ApiClient.php index b34ad1f..e49ba02 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -260,7 +260,7 @@ public function matterByMatterNumber(string $matterNumber): Matter public function matterCreate(Matter $matter, ?CaseFile $case = null): Matter { $linkName = self::REL_CREATE_MATTER; - $url = null !== $case ? $case->links->getUrl($linkName) : $this->getRequestUrl($linkName); + $url = $case?->links->getUrl($linkName) ?? $this->getRequestUrl($linkName); // The documentation is unclear on this POE stuff. Does it return 303 or 201? // resources/f2-rest-docs/f2-rest-docs-v13s.html#11 @@ -507,11 +507,9 @@ protected function request(string $method, string $path, array $options = []): R protected function client(): HttpClientInterface { - if (null === $this->client) { - $this->client = HttpClient::create([ - 'base_uri' => $this->options['api_uri'], - ]); - } + $this->client ??= HttpClient::create([ + 'base_uri' => $this->options['api_uri'], + ]); return $this->client; } @@ -678,7 +676,7 @@ public function log($level, \Stringable|string $message, array $context = []): v } // Psr log levels ordered from lowest to highest severity. - private const LOG_LEVELS = [ + private const array LOG_LEVELS = [ LogLevel::DEBUG, LogLevel::INFO, LogLevel::NOTICE, diff --git a/src/Model/Atom.php b/src/Model/Atom.php index 7b8e77a..31006e7 100644 --- a/src/Model/Atom.php +++ b/src/Model/Atom.php @@ -4,7 +4,7 @@ namespace ItkDev\F2ApiClient\Model; -final class Atom extends AbstractItem +final class Atom extends AbstractItem implements \Stringable { public string $id; public string $title; diff --git a/src/Model/Collection/Item.php b/src/Model/Collection/Item.php index e09d132..9a04937 100644 --- a/src/Model/Collection/Item.php +++ b/src/Model/Collection/Item.php @@ -6,7 +6,7 @@ use ItkDev\F2ApiClient\Model\AbstractItem; -final class Item extends AbstractItem +final class Item extends AbstractItem implements \Stringable { public int $id; public string $title; diff --git a/src/Model/F2Item/Links.php b/src/Model/F2Item/Links.php index abd0912..65bab9c 100644 --- a/src/Model/F2Item/Links.php +++ b/src/Model/F2Item/Links.php @@ -10,7 +10,7 @@ /** * @phpstan-type Link array{rel: string, href: string, title:string} */ -final class Links extends AbstractItem +final class Links extends AbstractItem implements \Stringable { public function __construct( /** @var array */ diff --git a/tests/Model/MatterTest.php b/tests/Model/MatterTest.php new file mode 100644 index 0000000..ef69ba2 --- /dev/null +++ b/tests/Model/MatterTest.php @@ -0,0 +1,33 @@ + null, + 'Type' => null, + 'AccessLevel' => null, + 'Archived' => 'false', + ]; + $actual = $matter->apiSerialize(); + $this->assertSame($expected, $actual); + + $matter = new Matter(); + $matter->title = 'My matter'; + $expected = [ + 'Title' => 'My matter', + 'Type' => null, + 'AccessLevel' => null, + 'Archived' => 'false', + ]; + $actual = $matter->apiSerialize(); + $this->assertSame($expected, $actual); + } +} From f6b90a9937ffeb64e1ad338e5bbee97bfc117a64 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 10 Nov 2026 13:46:14 +0100 Subject: [PATCH 5/6] Added caseByCaseNumber command --- src/Command/F2ApiClientCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Command/F2ApiClientCommand.php b/src/Command/F2ApiClientCommand.php index 9a740ad..79aeb30 100644 --- a/src/Command/F2ApiClientCommand.php +++ b/src/Command/F2ApiClientCommand.php @@ -22,6 +22,7 @@ class F2ApiClientCommand extends Command public const string ACTION_GET_SERVICE_INDEX = 'getServiceIndex'; public const string ACTION_CASE_SEARCH = 'caseSearch'; public const string ACTION_CASE_BY_ID = 'caseById'; + public const string ACTION_CASE_BY_CASE_NUMBER = 'caseByCaseNumber'; public const string ACTION_MATTER_SEARCH = 'matterSearch'; public const string ACTION_MATTER_BY_ID = 'matterById'; public const string ACTION_MATTER_BY_MATTER_NUMBER = 'matterByMatterNumber'; @@ -31,6 +32,7 @@ class F2ApiClientCommand extends Command self::ACTION_GET_SERVICE_INDEX, self::ACTION_CASE_SEARCH, self::ACTION_CASE_BY_ID, + self::ACTION_CASE_BY_CASE_NUMBER, self::ACTION_MATTER_SEARCH, self::ACTION_MATTER_BY_ID, self::ACTION_MATTER_BY_MATTER_NUMBER, @@ -45,6 +47,7 @@ public function getHelp(): string %command.name% getServiceIndex %command.name% caseSearch %command.name% caseById + %command.name% caseByCaseNumber %command.name% matterSearch %command.name% matterById %command.name% matterByMatterNumber @@ -78,6 +81,7 @@ public function __invoke( 'getServiceIndex' => $client->getServiceIndex(), 'caseSearch' => $client->caseSearch((string) $arg), 'caseById' => $client->caseById((int) $arg), + 'caseByCaseNumber' => $client->caseByCaseNumber((string) $arg), 'matterSearch' => $client->matterSearch((string) $arg), 'matterById' => $client->matterById((int) $arg), 'matterByMatterNumber' => $client->matterByMatterNumber((string) $arg), From b5f14b297c9f9ef52c663fdb2a06fe9e183fd875 Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Tue, 10 Nov 2026 14:08:20 +0100 Subject: [PATCH 6/6] PHP 8.4 --- compose.yaml | 6 +++++- composer.json | 2 +- mago.toml | 2 +- src/Model/AbstractItem.php | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/compose.yaml b/compose.yaml index ce1f8b9..f90b395 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,12 +1,16 @@ services: phpfpm: - image: itkdev/php8.3-fpm:latest + image: itkdev/php8.4-fpm:latest user: ${COMPOSE_USER:-deploy} profiles: - dev environment: - PHP_XDEBUG_MODE=${PHP_XDEBUG_MODE:-off} - PHP_IDE_CONFIG=serverName=localhost + # https://getcomposer.org/doc/06-config.md#environment-variables + - COMPOSER_POLICY_COOLDOWN_PERIOD=0 + # https://getcomposer.org/doc/03-cli.md#composer_no_blocking + - COMPOSER_NO_BLOCKING=1 volumes: - .:/app # https://docs.docker.com/compose/how-tos/environment-variables/set-environment-variables/#additional-information-1 diff --git a/composer.json b/composer.json index 4125dc5..0bf3712 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "MIT", "type": "library", "require": { - "php": "^8.3", + "php": "^8.4", "ext-simplexml": "*", "psr/cache": "^2.0 || ^3.0", "swaggest/json-diff": "^3.12", diff --git a/mago.toml b/mago.toml index 43f5d90..1054776 100644 --- a/mago.toml +++ b/mago.toml @@ -2,7 +2,7 @@ # Welcome to Mago! # For full documentation, see https://mago.carthage.software/1.42.0/en/tools/overview/ version = "1" -php-version = "8.3.0" +php-version = "8.4.0" [source] workspace = "." diff --git a/src/Model/AbstractItem.php b/src/Model/AbstractItem.php index 990c8c9..e0b5205 100644 --- a/src/Model/AbstractItem.php +++ b/src/Model/AbstractItem.php @@ -10,7 +10,7 @@ public static function fromSimpleXMLElement(\SimpleXMLElement $sxe): static { // @mago-ignore analysis:unsafe-instantiation // @phpstan-ignore new.static - return (new static())->setFromSimpleXMLElement($sxe); + return new static()->setFromSimpleXMLElement($sxe); } public function setFromSimpleXMLElement(\SimpleXMLElement $sxe): static @@ -59,7 +59,7 @@ protected function createDateTime(\SimpleXMLElement|string $value): ?\DateTimeIm return null; } - return (new \DateTimeImmutable($value, $apiTimeZone))->setTimeZone($appTimeZone); + return new \DateTimeImmutable($value, $apiTimeZone)->setTimeZone($appTimeZone); } /**