MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / collect_psr4_php_files

Function collect_psr4_php_files

src/classmap_scanner.rs:1803–1857  ·  view source on GitHub ↗

Collect all `.php` file paths under a PSR-4 directory, computing the expected FQN for each file from its relative path. Paths and expected FQNs are appended to `out`. No file content is read. Files whose path appears in `skip_paths` are excluded.

(
    base_path: &Path,
    namespace_prefix: &str,
    vendor_dir_paths: &[PathBuf],
    skip_paths: &HashSet<PathBuf>,
    out: &mut Vec<(PathBuf, String)>,
)

Source from the content-addressed store, hash-verified

1801///
1802/// Files whose path appears in `skip_paths` are excluded.
1803fn collect_psr4_php_files(
1804 base_path: &Path,
1805 namespace_prefix: &str,
1806 vendor_dir_paths: &[PathBuf],
1807 skip_paths: &HashSet<PathBuf>,
1808 out: &mut Vec<(PathBuf, String)>,
1809) {
1810 use ignore::WalkBuilder;
1811
1812 let vendor_paths: Vec<PathBuf> = vendor_dir_paths.to_vec();
1813
1814 let walker = WalkBuilder::new(base_path)
1815 .git_ignore(true)
1816 .git_global(true)
1817 .git_exclude(true)
1818 .hidden(true)
1819 .parents(true)
1820 .ignore(true)
1821 .filter_entry(move |entry| {
1822 if entry.file_type().is_some_and(|ft| ft.is_dir()) {
1823 let path = entry.path();
1824 if vendor_paths.iter().any(|vp| vp == path) {
1825 return false;
1826 }
1827 }
1828 true
1829 })
1830 .build();
1831
1832 for entry in walker.flatten() {
1833 let path = entry.path();
1834 if path.is_file() && path.extension().is_some_and(|ext| ext == "php") {
1835 let owned = path.to_path_buf();
1836 if skip_paths.contains(&owned) {
1837 continue;
1838 }
1839 // Compute expected FQN from the file path relative to the
1840 // PSR-4 base directory.
1841 let relative = match path.strip_prefix(base_path) {
1842 Ok(rel) => rel,
1843 Err(_) => continue,
1844 };
1845 let relative_str = relative.to_string_lossy();
1846 // Strip the `.php` extension
1847 let stem = match relative_str.strip_suffix(".php") {
1848 Some(s) => s,
1849 None => continue,
1850 };
1851 // Convert path separators to namespace separators
1852 let expected_fqn = format!("{}{}", namespace_prefix, stem.replace('/', "\\"));
1853
1854 out.push((owned, expected_fqn));
1855 }
1856 }
1857}
1858
1859// ─── Tests ──────────────────────────────────────────────────────────────────
1860

Callers 2

Calls 4

buildMethod · 0.80
iterMethod · 0.80
containsMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected