Skip to content

Rewrite SDK in the economic-php-sdk style#5

Open
loevgaard wants to merge 2 commits into
2.xfrom
rewrite-sdk-economic-style
Open

Rewrite SDK in the economic-php-sdk style#5
loevgaard wants to merge 2 commits into
2.xfrom
rewrite-sdk-economic-style

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Re-architects the SDK to mirror setono/economic-php-sdk, preserving exactly the functionality already supported — no new endpoints. Targets the 2.x major.

Scope preserved: paymentGateways (list + getById), pickupPoints (search), salesOrders (list/getById/create), shipmentTemplates (list + getById), webhooks (list/create/delete/deleteAll), and the ShipmentTemplateResolver.

Architecture

  • Immutable Client — collaborators constructor-injected, sandbox: true flag (replaces setDebug() and all setters), HTTP Basic auth, host/port credential guard, match-based exception mapping. get/post/delete return decoded arrays; request() is the PSR-7 escape hatch.
  • Base-class endpoints (EndpointResourceEndpointCollectionEndpoint) replace every *EndpointInterface and capability trait.
  • Resource responses with $raw, stamped by RawStamper outside Valinor's converter pipeline (avoids the per-node reflection leak).
  • Payload requests serialized via the Valinor Normalizer (null-strip + camelCase→snake_case + DateTime→ISO; native enums in src/Enum/).
  • Header-based pagination (Collection carries the X-* header values; paginate() walks pages). pickupPoints returns a bare list<PickupPoint>; paymentGateways/shipmentTemplates look up via ?id=.
  • Typed exception hierarchy under ShipmondoException, exposing getError() for Shipmondo's {"error": "..."} body.

Tooling

  • PHP >=8.1 retained (economic's 8.4-only idioms down-adapted).
  • Psalm → PHPStan level max (+ strict-rules / phpunit / webmozart-assert).
  • cuyz/valinor pinned ^2.2.2 <2.4 — 2.4 drops PHP 8.1 (CI 8.1 matrix guards this).
  • PHPUnit ^10.5 (attribute-based tests; ScriptedHttpClient fake PSR-18, no mocking framework).
  • Dropped psr/log — consumers add logging via PSR-18 middleware.
  • README + CLAUDE.md updated for the new caching/constructor API.

Behavior changes / BC breaks (appropriate for the 2.x major)

  • New constructor signature; all setters removed.
  • get()/post()/delete() return array (was ResponseInterface).
  • pickupPoints()->search(PickupPointSearch): list<PickupPoint> (was get(): Collection).
  • Collection::first() returns null (was false); Collection gains totalCount.
  • Webhook/order-line constants → native enums; SalesOrder.orderId now required.

Verification

  • composer phpunit — 60 tests, 132 assertions (3 live tests skipped)
  • composer analyse — PHPStan level max, no errors
  • composer check-style, vendor/bin/rector --dry-run, composer validate --strict, composer normalize — clean
  • vendor/bin/infection — MSI 58% / covered 69% (thresholds 50/60)

Re-architect the SDK to mirror setono/economic-php-sdk while preserving exactly the currently supported functionality (payment gateways, pickup points, sales orders, shipment templates, webhooks + the shipment template resolver).

Highlights:
- Immutable, constructor-injected Client with a sandbox flag (replaces setters/setDebug); HTTP Basic auth; typed exception hierarchy under ShipmondoException with match-based status mapping.
- Base-class endpoints (Endpoint/ResourceEndpoint/CollectionEndpoint) replace the per-endpoint interfaces and capability traits.
- Resource responses carrying $raw (stamped by RawStamper, outside Valinor's converter pipeline); Payload requests serialized via the Valinor Normalizer (null-strip + camelCase->snake_case + date->ISO + native enums).
- Header-based Collection pagination; pickup points returns a bare list; payment gateways/shipment templates look up by ?id=.

Tooling: PHP >=8.1 retained; switch Psalm -> PHPStan level max; cuyz/valinor pinned ^2.2.2 <2.4 (2.4 drops 8.1); PHPUnit ^10.5; drop psr/log. README + CLAUDE.md updated.

Verified: PHPUnit 60 tests green, PHPStan max clean, ECS clean, Rector clean, composer validate/normalize clean, Infection MSI 58%/covered 69%.
Comment thread composer.json
"php": ">=8.1",
"cuyz/valinor": "^1.10",
"php-http/discovery": "^1.14",
"cuyz/valinor": "^2.2.2 <2.4",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"cuyz/valinor": "^2.2.2 <2.4",
"cuyz/valinor": "^2.2.2",


/**
* Takes a response and returns a Valinor Source representation
* Recursively convert snake_case array keys to camelCase so they match DTO property names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the valinor library can do this. Else the Symfony string component also has this capability I think: https://symfony.com/doc/6.4/components/string.html


abstract class ShipmondoTestCase extends TestCase
{
protected const BASE = 'https://sandbox.shipmondo.com/api/public/v3';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant