Skip to content

fix(composer): add fallback autoload for Composer dependency installs#1074

Open
faisalahammad wants to merge 4 commits into
wp-media:developfrom
faisalahammad:fix/1073-composer-autoload-strauss
Open

fix(composer): add fallback autoload for Composer dependency installs#1074
faisalahammad wants to merge 4 commits into
wp-media:developfrom
faisalahammad:fix/1073-composer-autoload-strauss

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fix fatal error when plugin is installed via Composer (e.g. Bedrock). Strauss prefixing does not run when installed as a dependency, so Imagify\Dependencies\League\Container\* classes are missing.

Add class_alias fallback in inc/main.php to map unprefixed League classes to the prefixed namespace. Also fix FILTER_REQUIRE_ARRAY PHPStan error in classes/Bulk/Bulk.php.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Detailed scenario

What was tested

  • Plugin activation via Composer dependency install
  • PHPStan analysis passes
  • Bulk stats AJAX callback
  • Integration test bootstrap

How to test

  1. Install via Composer: composer require wp-media/imagify-plugin
  2. Activate plugin in WordPress admin
  3. No fatal error should appear
  4. Visit Imagify settings page — loads correctly

Affected Features & Quality Assurance Scope

  • Plugin activation
  • Bulk optimization stats endpoint
  • All features that use the DI container

Technical description

Documentation

N/A — code change only, no public API change.

New dependencies

None.

Risks

Low. The class_alias fallback only activates when the prefixed class is not already available. The filter_input change moves FILTER_REQUIRE_ARRAY to the $flags argument (4th) where it belongs.

Mandatory Checklist

Code validation

  • composer run-stan passes
  • composer phpcs passes
  • Unit tests pass (pre-existing failures unrelated)
  • Integration tests pass

Code style

  • PHPCS WordPress Coding Standards followed

Unticked items justification

N/A

Additional Checks

  • PR title is descriptive
  • Changes are limited to scope
  • No new dependencies added
  • No breaking changes

When Imagify is installed via Composer as a dependency (e.g. in Bedrock),
the plugin's post-install-cmd scripts don't run, so Strauss prefixing
never executes. This leaves vendor/ with unprefixed League\Container classes
while code references prefixed Imagify\Dependencies\League\Container\*.

Fix: Add class_alias fallbacks in inc/main.php to map unprefixed classes
to prefixed namespace when needed. Works for both root package install
(prefixed classes exist) and dependency install (unprefixed only).

Fixes wp-media#1073
@codacy-production

codacy-production Bot commented Jun 6, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Move FILTER_REQUIRE_ARRAY to flags arg in filter_input call.
Add use statement for Container in inc/main.php to fix class
not found error during integration test bootstrap.
- Skip ImagifyUser integration tests when IMAGIFY_TESTS_API_KEY is empty
  (e.g. fork PRs without repo secrets) instead of failing with WP_Error
- Pass null as object to ReflectionProperty::setValue() for static
  properties to avoid PHP 8.4 single-arg deprecation
Add `if: github.event.pull_request.head.repo.fork == false` guard to
the codacy-coverage-reporter step. Fork PRs don't have access to
CODACY_PROJECT_TOKEN secret, causing the step to fail with
"Invalid configuration: Either a project or account API token must
be provided."

On same-repo PRs behavior is unchanged.
@alexbogias

Copy link
Copy Markdown

Same issue here. Please merge it if works.

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.

2 participants