Skip to content

Replace Psalm with PHPStan and upgrade dependencies#8

Merged
loevgaard merged 8 commits into
masterfrom
chore/phpstan-and-dependency-upgrades
Jun 15, 2026
Merged

Replace Psalm with PHPStan and upgrade dependencies#8
loevgaard merged 8 commits into
masterfrom
chore/phpstan-and-dependency-upgrades

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Modernizes the dev toolchain and bumps the Meta SDK while keeping the library's php: >=8.1 requirement intact.

  • facebook/php-business-sdk ^22.0^25.0 (Graph API endpoint moves v22.0v25.0).
  • Code-quality-pack inlined. setono/code-quality-pack's current major requires PHP 8.2, so instead of depending on the meta-package its tools are listed directly in require-dev, each pinned to the latest version that still supports PHP 8.1 (PHPStan ^2.1, PHPUnit ^10.5, Infection ^0.29, ECS via sylius-labs/coding-standard ^4.5, Rector, composer-normalize, composer-dependency-analyser, prophecy).
  • Psalm → PHPStan (level: max). Deletes psalm.xml, adds phpstan.dist.neon (analysed against PHP 8.1), updates the analyse script, and removes the now-dead @psalm-suppress annotations.
  • Code fixes driven by level max: removed the unused responseFactory from Client, added precise iterable/array types, narrowed mixed access in ErrorResponse, and refactored Parameters::getPayload() so its array<string, mixed> contract is provable (shared filterEmptyValues() helper).
  • PHP 8.4 hygiene: made implicitly-nullable params explicit (Content, Pixel, Parameters) and migrated phpunit.xml.dist to the PHPUnit 10 schema.
  • CI: added PHP 8.4 to the test/static-analysis/dependency matrices.

Tests

25 → 39 tests; mutation MSI ~72% → ~78%. New coverage: Client error path + test_event_code, ErrorResponse parsing, Content payload, FbqGenerator init/trackCustom branches, Event::isCustom, Fbc::withCreationTime immutability.

Verified green on PHP 8.1 and 8.4: PHPStan, ECS, composer-dependency-analyser, composer validate/normalize, PHPUnit, Infection. --prefer-lowest resolves on 8.1.

🤖 Generated with Claude Code

- Bump facebook/php-business-sdk from ^22.0 to ^25.0 (Graph API v25.0)
- Replace setono/code-quality-pack with its individual dev tools pinned to
  the latest versions that still support PHP 8.1 (PHPStan ^2.1, PHPUnit
  ^10.5, Infection ^0.29, ECS via sylius-labs/coding-standard, etc.)
- Swap Psalm for PHPStan (level max): drop psalm.xml, add phpstan.dist.neon,
  update the analyse script and remove @psalm-suppress annotations
- Fix the resulting level-max findings: remove dead responseFactory from
  Client, add precise iterable/array types, narrow mixed in ErrorResponse,
  refactor getPayload() so its array<string, mixed> contract is provable
- Make implicitly-nullable params explicit (8.4 deprecation) and migrate
  phpunit.xml.dist to the PHPUnit 10 schema
- Add tests (25 -> 39): Client error path + test_event_code, ErrorResponse
  parsing, Content payload, FbqGenerator branches, Event::isCustom, Fbc
  immutable creation time
- Add PHP 8.4 to the CI matrices
- Restore Client::setResponseFactory() (removing it broke BC); make the
  companion getResponseFactory() public so the response factory is used
  and PHPStan is happy
- Type TestLogger::log()'s $context (psr/log 1.x has no value-typed
  $context, which tripped missingType.iterableValue on the lowest matrix)
- Build LiveClientTest::getTestValues() as an explicit array shape via an
  env() helper so PHPStan 2.1.x can prove the declared return type
Comment thread src/Client/Client.php Outdated
Comment thread src/Event/Parameters.php
Comment thread phpstan.dist.neon Outdated
- Client: drop the public getResponseFactory() getter; keep setResponseFactory()
  as a @deprecated no-op retained only for BC (the client never creates
  responses, so the response factory was always unused)
- Parameters: document why getPayload() iterates the mapping (to keep the
  precise array<string, mixed> return type that FbqGenerator::generateInit()
  consumes)
The static-analysis CI matrix runs on PHP 8.1-8.4, so each version is
analysed natively; the explicit phpVersion pin is redundant.
Pins the exact getPayload() output for a fully-populated object graph
(nested Parameters, lists, scalars, normalization, hashing, value objects,
custom properties, empty-value filtering). Verified to pass against both the
pre-refactor (master) and refactored getPayload() implementations, proving
the refactor is behaviour-preserving.
Resolves the TODO in ErrorResponse: besides message/type/code/fbtrace_id, Meta
may also return error_subcode, is_transient and the user-facing
error_user_title / error_user_msg fields. These optional fields are now parsed
when present, and ClientException surfaces the subcode and the user-facing
explanation in its message.
Rewrite with runnable examples covering the common cases (server events,
multiple pixels, test events, error handling, browser-side fbq() generation
with deduplication, custom events, fbc/fbp, custom HTTP client, logging,
extending events) and document the automatic normalization/hashing behaviour.
Also fixes the missing Client import in the original usage example.
@loevgaard loevgaard merged commit 8e4821d into master Jun 15, 2026
28 checks passed
@loevgaard loevgaard deleted the chore/phpstan-and-dependency-upgrades branch June 15, 2026 09:24
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