Refactor library to PSR-4, add full unit-test coverage, and CI#6
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships v2.0.0 of the library. The pre-refactor codebase had grown around a
static
Apisingleton and a kitchen-sinkServicebase class that mixedHTTP, option storage, caching, and throttling. This PR splits those
responsibilities into focused collaborators, lays the file tree out as
PSR-4, and adds the test + CI infrastructure that has been missing.
Library refactor (v1 → v2)
DuckDev\Freemius\…—class-*.phpfilenameprefixes are gone; each class lives in a file matching its name.
Api::get_instance()/Api::get_auth_instance()are replaced by anApiFactorythat handsout fresh clients per call. This fixes a latent credential-leak bug
where two callers with different credentials could share state.
Client(unsigned HTTP),SignedClient(auth headers), and
RequestSigner(pure HMAC signing, no WP coupling).Servicebaseclass into
ActivationRepository(option-backed) andTransientCache(per-plugin scoped cache + throttle), both behind interfaces so they
can be swapped in tests.
Activationvalueobject with
with()/with_scrubbed_license()mutators. Previouslyevery service reached into the same loose string keys — a typo in any
of them silently broke licensing.
Plugin,ApiKeys,SiteIdentityintroduced as small focusedcollaborators. Hook registration moved out of constructors into
boot()so wiring the container has no side effects.Tests
src/.WP_Errorstub intests/Stubs/.failOnRisky, deprecations-as-exceptions).CI / tooling
.github/workflows/tests.yml— PHPUnit matrix on PHP 7.4, 8.0,8.1, 8.2, 8.3.
.github/workflows/phpcs.yml— WPCS lint with PR annotationsvia
cs2pr..github/workflows/release.yml— auto-generates a GitHub Releasefrom commits when a
v*tag is pushed; tags containing-(e.g.v2.0.0-beta1) are marked as pre-releases.phpcs.xml.dist— WPCS ruleset with PSR-4 exemptions(
WordPress.Files.FileName,ValidVariableName) and per-fileexclusions for
{@inheritDoc}interface methods and the HMACbase64_encodecall.composer.json— bumped to2.0.0, PSR-4 autoload +autoload-dev,dev deps for PHPUnit/Brain\Monkey/WPCS/PHPCompatibility, scripts
(
composer test,composer phpcs).Breaking changes
This is a major version bump. Host plugins need to update their
integration:
DuckDev\Freemius\Services\Service→DuckDev\Freemius\Services\AbstractService, etc.).Freemius::get_instance()keeps the same call signature but thecollaborator graph it composes is entirely new.
Apisingletons must move toApiFactory::make_public()/make_signed()/make_for_plugin()/make_for_install().Activationvalue object;reach for
->install_id(),->license_key(), etc. instead ofarray keys.
Test plan
composer test— 109/109 tests pass locally on PHP 8.xcomposer phpcs— 0 errors, 0 warningsactivate.json/deactivate.json/updates/latest.jsonendpoints
v2.0.0after merge and confirm the release workflowpublishes notes