Skip to content

Typed argument shapes: @phpstan-type aliases (unsealed + enum literals) for high-arity builders - #63

Merged
edpittol merged 1 commit into
mainfrom
37-typed-argument-shapes-phpstan-type-aliases-unsealed-enum-literals-for-high-arity-builders
Jul 11, 2026
Merged

Typed argument shapes: @phpstan-type aliases (unsealed + enum literals) for high-arity builders#63
edpittol merged 1 commit into
mainfrom
37-typed-argument-shapes-phpstan-type-aliases-unsealed-enum-literals-for-high-arity-builders

Conversation

@edpittol

Copy link
Copy Markdown
Member

Summary

Converts the loosely-typed array<string, mixed> overrides/criteria params on the WooCommerce Method Traits' high-arity, error-prone builders into unsealed @phpstan-type array shapes with enum literals for status/stock/discount values:

  • ProductMethods::haveProductInDatabase / haveManyProductsInDatabaseProductOverrides (nested ProductMeta, ProductStatus, ProductStockStatus, ProductTaxStatus, ProductBackorders enums).
  • CouponMethods::haveCouponInDatabase and its havePercentageCouponInDatabase/haveFixedCartCouponInDatabase/haveFixedProductCouponInDatabase/haveFreeShippingCouponInDatabase wrappers — CouponOverrides (nested CouponMeta, CouponStatus, CouponDiscountType enums).
  • OrderMethods::haveOrderInDatabase / haveManyOrdersInDatabaseOrderOverrides (OrderStatus enum, nested address/items/meta).
  • OrderMethods::haveOrderAddressInDatabase / seeOrderAddressInDatabaseOrderAddress shape + OrderAddressType enum.
  • OrderMethods::haveOrderItemInDatabase (the order-item builder) — OrderItemOverrides with an OrderItemType enum.

All shapes are unsealed (...) so the merge-defaults pass-through pattern keeps working and legitimate extra keys aren't rejected. Trivial 2-3 key criteria params (meta lookups, simple ID/field queries) were left as prose @param, per scope. No @example blocks were added or rewritten.

Two defensive runtime checks in CouponMethods and ProductMethods that tested for array/string-ness of now-strictly-typed keys were simplified, since PHPStan flagged them as always-true/always-false once the shapes made the guarantee static.

Note: issue #35 (the cold-agent eval this issue's "Blocked by" pointed at) is closed, but its failure-log Cest was never actually committed to the repo — there's no tests/acceptance/*Cest.php recording the specific hallucinated keys. The shapes here were instead derived directly from each builder's existing implementation and are validated against the Cests that do exist (ProductCest, CouponCest, OrderCest, OrderHPOSCest).

Closes #37

Test plan

  • vendor/bin/phpstan analyse — no errors (level max over src and tests)
  • vendor/bin/phpcs — clean
  • vendor/bin/codecept run unit — 32/32 passing
  • vendor/bin/codecept run acceptance (via pre-push hook, full suite) — 198/198 passing

…/criteria

Converts the loosely-typed array<string, mixed> overrides/criteria params on
ProductMethods::haveProductInDatabase/haveManyProductsInDatabase,
CouponMethods::haveCouponInDatabase and its discount-type wrappers, and
OrderMethods::haveOrderInDatabase/haveManyOrdersInDatabase/haveOrderAddressInDatabase/
seeOrderAddressInDatabase/haveOrderItemInDatabase into unsealed @phpstan-type array
shapes with enum literals for post/order status, stock status, tax status, and
discount-type values. At PHPStan level max over src and tests, these shapes now
double as the machine-readable allowed-keys map for agents and as assertions
checked against every shipped Cest on CI.

Closes #37
@edpittol edpittol self-assigned this Jul 11, 2026
@edpittol
edpittol merged commit 25955ec into main Jul 11, 2026
3 checks passed
@edpittol
edpittol deleted the 37-typed-argument-shapes-phpstan-type-aliases-unsealed-enum-literals-for-high-arity-builders branch July 11, 2026 20:44
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.

Typed argument shapes: @phpstan-type aliases (unsealed + enum literals) for high-arity builders

1 participant