Skip to content

Closes #37: Refactor rmdir() to use public APIs instead of reflection - #42

Merged
remyperona merged 1 commit into
developfrom
enhancement/vfsstream-rmdir-public-api-37
Aug 13, 2026
Merged

Closes #37: Refactor rmdir() to use public APIs instead of reflection#42
remyperona merged 1 commit into
developfrom
enhancement/vfsstream-rmdir-public-api-37

Conversation

@remyperona

@remyperona remyperona commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🤖 AI-generated — created by an automated pipeline. Review before acting on this.

Closes #37

Description

Refactors VirtualFilesystemDirect::rmdir()'s recursive branch to eliminate reflection on vfsStream's private internals, improving maintainability and reducing coupling to vfsStream's internal implementation details.

What was done

  • Child name retrieval: Replaced reflection of private name property with the public vfsStreamAbstractContent::getName() getter.
  • Parent path derivation: Instead of reflecting vfsStream's private parentPath, the parent path is now derived from the directory's own absolute path using PHP's dirname() function.
  • Parent directory fetching: Parent directory is retrieved via the existing public-API getDir() helper and passed to removeChild() with an instanceof vfsStreamContainer type guard for safety.
  • Cleanup: Removed now-unused use TestCaseTrait; and vfsStreamAbstractContent import; added vfsStreamContainer for the type guard. TestCaseTrait::getNonPublicPropertyValue() remains unchanged and is still used elsewhere.

Files changed

  • VirtualFilesystemDirect.php
  • Tests/Unit/VirtualFilesystemDirect/rmdir.php — added 2 new tests:
    • Nested recursive removal while preserving siblings
    • Recursive removal via vfs:// URL

How to test

  • Run composer run-script test-unit — all 93 unit tests pass with 295 assertions, 0 failures
  • Public behavior of rmdir() is unchanged; only the internal implementation refactored
  • Integration suite not run locally (requires WP/MySQL environment not available; this change has no WP dependencies)

Type of change

  • Refactoring (improving code quality, structure, or maintainability without changing behavior)
  • Bug fix
  • New feature

Affected Features & Quality Assurance Scope

  • Core virtual filesystem operations (directory removal)
  • Unit test coverage for recursive directory deletion

Technical description

The refactoring replaces direct reflection into vfsStream's internal properties with calls to public APIs. Previously, the code accessed vfsStreamAbstractContent::$name and parentPath directly via TestCaseTrait::getNonPublicPropertyValue(). Now:

  1. Child name is fetched via the public getName() method
  2. Parent path is computed from the directory's absolute path using dirname()
  3. The parent directory reference is obtained via the existing getDir() public helper
  4. An instanceof vfsStreamContainer guard ensures the parent supports removeChild() before calling it

This approach is more resilient to vfsStream upgrades and improves code clarity.

VirtualFilesystemDirect::rmdir() and getParentDir() reached into vfsStream's
private name/parentPath properties via reflection, coupling the package to a
specific vfsStream layout that ^1.6 could silently break. Use the public
getName() getter and derive the parent path from the already-known directory
path instead, so a vfsStream upgrade can't break recursive delete unnoticed.

Co-Authored-By: Sonnet 5 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Aug 13, 2026
@remyperona
remyperona marked this pull request as ready for review August 13, 2026 19:54
@remyperona
remyperona merged commit a29a63c into develop Aug 13, 2026
7 checks passed
@remyperona
remyperona deleted the enhancement/vfsstream-rmdir-public-api-37 branch August 13, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rmdir() recursive branch reflects into vfsStream private internals (brittle vs ^1.6 bumps)

1 participant