Skip to content

[Bug] Browscap Flysystem namespace scoping mismatch blocks tracking pipeline #187

@parhumm

Description

@parhumm

Problem Description

The MatthiasMullie\Scrapbook\Adapters\Flysystem adapter in src/Dependencies/ uses un-prefixed League\Flysystem\* imports, but the actual Flysystem classes have been prefixed to SlimStat\Dependencies\League\Flysystem\* by php-scoper. This type mismatch causes a fatal TypeError when the Browscap service attempts to create a cache adapter, blocking the entire tracking pipeline from inserting rows.

Impact

Severity: High — The tracking pipeline cannot complete on any pageview that triggers browser detection via Browscap. This affects all server-side tracking calls (slimtrack_server() and slimtrack()) and may silently fail on regular page loads depending on error handling configuration.

Steps to Reproduce

  1. Activate wp-slimstat v5.4.3 on a WordPress site
  2. Trigger a tracking call (e.g., via wp_slimstat::slimtrack_server() or a normal pageview)
  3. Observe the fatal error in the Browscap cache initialization

Expected Behavior

The Browscap service should successfully create a Flysystem-backed cache adapter and proceed with browser detection.

Actual Behavior

TypeError: SlimStat\Dependencies\MatthiasMullie\Scrapbook\Adapters\Flysystem::__construct():
Argument #1 ($filesystem) must be of type League\Flysystem\Filesystem,
SlimStat\Dependencies\League\Flysystem\Filesystem given,
called in src/Services/Browscap.php on line 80

The Scrapbook adapter's __construct() type-hints against the un-prefixed League\Flysystem\Filesystem, but receives the prefixed SlimStat\Dependencies\League\Flysystem\Filesystem instance created by Browscap.php.

Code References

File Lines Description
src/Dependencies/MatthiasMullie/Scrapbook/Adapters/Flysystem.php 5-10 6 un-prefixed use League\Flysystem\* imports — should be SlimStat\Dependencies\League\Flysystem\*
src/Dependencies/MatthiasMullie/Scrapbook/Adapters/Collections/Flysystem.php 5-7 3 un-prefixed use League\Flysystem\* imports — same issue
src/Services/Browscap.php 78-81 Creates new Flysystem($filesystem) — passes prefixed object to un-prefixed type hint
src/Dependencies/BrowscapPHP/Command/*.php various These files ARE correctly prefixed (e.g., use SlimStat\Dependencies\League\Flysystem\Filesystem) — shows scoper worked for BrowscapPHP but missed Scrapbook

Root Cause

php-scoper successfully prefixed the League\Flysystem\* classes and the BrowscapPHP\Command\* imports, but missed the MatthiasMullie\Scrapbook\Adapters\* files. The 9 un-prefixed imports across 2 Scrapbook adapter files need to be prefixed to SlimStat\Dependencies\League\Flysystem\*.

Suggested Fix

Replace in src/Dependencies/MatthiasMullie/Scrapbook/Adapters/Flysystem.php and src/Dependencies/MatthiasMullie/Scrapbook/Adapters/Collections/Flysystem.php:

-use League\Flysystem\Filesystem;
+use SlimStat\Dependencies\League\Flysystem\Filesystem;

(And the same for FileExistsException, FileNotFoundException, UnableToDeleteFile, UnableToReadFile, UnableToWriteFile.)

Alternatively, fix the php-scoper configuration to include the Scrapbook adapter files in the scoping pass.

Environment

Field Value
Tech Stack WordPress / PHP
Runtime PHP 8.5.0 (also reproducible on PHP 8.0)
OS macOS (Darwin 25.1.0 arm64)
Branch fix/171-server-side-tracking-api (also affects development)
Key Dependencies wp-slimstat v5.4.3, league/flysystem (scoped), matthiasmullie/scrapbook (partially scoped)

Additional Context

Discovered during E2E testing of PR #184 (server-side tracking API for issue #171). The slimtrack_server() and slimtrack() calls both reach the Browscap service and fail at the same point. The error is caught by try/catch in the broader tracking pipeline but prevents any row from being inserted into the database.

The BrowscapPHP command files (src/Dependencies/BrowscapPHP/Command/*.php) are correctly scoped, proving the scoper configuration works for that package — it's specifically the Scrapbook adapter package that was missed.


Reported via: qa-issue-report skill (jaan.to plugin)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions