Closes #37: Refactor rmdir() to use public APIs instead of reflection - #42
Merged
Merged
Conversation
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>
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.
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
nameproperty with the publicvfsStreamAbstractContent::getName()getter.parentPath, the parent path is now derived from the directory's own absolute path using PHP'sdirname()function.getDir()helper and passed toremoveChild()with aninstanceof vfsStreamContainertype guard for safety.use TestCaseTrait;andvfsStreamAbstractContentimport; addedvfsStreamContainerfor the type guard.TestCaseTrait::getNonPublicPropertyValue()remains unchanged and is still used elsewhere.Files changed
VirtualFilesystemDirect.phpTests/Unit/VirtualFilesystemDirect/rmdir.php— added 2 new tests:How to test
composer run-script test-unit— all 93 unit tests pass with 295 assertions, 0 failuresrmdir()is unchanged; only the internal implementation refactoredType of change
Affected Features & Quality Assurance Scope
Technical description
The refactoring replaces direct reflection into vfsStream's internal properties with calls to public APIs. Previously, the code accessed
vfsStreamAbstractContent::$nameandparentPathdirectly viaTestCaseTrait::getNonPublicPropertyValue(). Now:getName()methoddirname()getDir()public helperinstanceof vfsStreamContainerguard ensures the parent supportsremoveChild()before calling itThis approach is more resilient to vfsStream upgrades and improves code clarity.