Skip to content

refactor: simplify FileLocator::listFiles()#10142

Open
paulbalandan wants to merge 1 commit intocodeigniter4:developfrom
paulbalandan:refactor-filelocator-listfiles
Open

refactor: simplify FileLocator::listFiles()#10142
paulbalandan wants to merge 1 commit intocodeigniter4:developfrom
paulbalandan:refactor-filelocator-listfiles

Conversation

@paulbalandan
Copy link
Copy Markdown
Member

Description

FileLocator::listFiles() resolved each namespace's <path> via realpath(), gated get_filenames() on is_dir(), and then guarded array_merge on a non-empty result. All three checks are redundant:

  • get_filenames() (which uses RecursiveDirectoryIterator under the hood) already wraps its iterator in try { ... } catch (Throwable) { return []; } (see system/Helpers/filesystem_helper.php), so a missing or non-directory path simply yields an empty list.
  • array_merge($files, []) is well-defined and returns a copy of $files, so the if ($tempFiles !== []) guard is a micro-optimization for a discovery-time path.

The loop body collapses to a single array_merge call.

Side benefit: dropping the realpath/is_dir gate also avoids a class of latent flakes where PHP's stat / realpath caches hold stale negative entries for a namespace's subdirectory on Linux PHP (which caches is_dir negatives and realpath() failures, unlike macOS PHP). PR #10141 papered over one such failure in CommandsTest with clearstatcache(true); with this change, that workaround is no longer load-bearing.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@paulbalandan paulbalandan added the refactor Pull requests that refactor code label Apr 25, 2026
@paulbalandan paulbalandan changed the title refactor: simplify FileLocator::listFiles() refactor: simplify FileLocator::listFiles() Apr 25, 2026
Copy link
Copy Markdown
Member

@michalsn michalsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants