Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[Taskfile.yml]
indent_size = 2
25 changes: 25 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -30,13 +37,15 @@ 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:
- task: coding-standards:composer:check
- 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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions mago.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "."
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withRules([
SafeDeclareStrictTypesRector::class,
])
// uncomment to reach your current PHP version
->withPhpSets()
->withTypeCoverageLevel(0)
->withDeadCodeLevel(0)
->withCodeQualityLevel(0);
12 changes: 5 additions & 7 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/Command/F2ApiClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -45,6 +47,7 @@ public function getHelp(): string
%command.name% getServiceIndex
%command.name% caseSearch <search-terms>
%command.name% caseById <case-id>
%command.name% caseByCaseNumber <case-number>
%command.name% matterSearch <search-terms>
%command.name% matterById <matter-id>
%command.name% matterByMatterNumber <matter-number>
Expand Down Expand Up @@ -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),
Expand Down
14 changes: 12 additions & 2 deletions src/Model/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -49,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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Collection/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/F2Item/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Link> */
Expand Down
11 changes: 10 additions & 1 deletion src/Model/Matter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = $this->parseBoolean($sxe->Archived);
$this->createdDate = $this->createDateTime($sxe->CreatedDate);
$this->modifiedDate = $this->createDateTime($sxe->ModifiedDate);
$this->createdBy = Party::fromSimpleXMLElement($sxe->CreatedBy);
Expand All @@ -55,12 +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->formatBoolean($this->archived ?? false),
];
if ($this->responsible) {
$serialized['Responsible'] = $this->responsible->apiSerialize();
}

return $serialized;
}
}
19 changes: 15 additions & 4 deletions src/Model/Party.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
]);
}
}
33 changes: 33 additions & 0 deletions tests/Model/MatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use ItkDev\F2ApiClient\Model\Matter;
use PHPUnit\Framework\TestCase;

final class MatterTest extends TestCase
{
public function testMatterApiSerialize(): void
{
$matter = new Matter();
$expected = [
'Title' => 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);
}
}
Loading