Skip to content

Commit a4be795

Browse files
committed
Refactor phpvmrc.js to improve findPHPVMRCFile and autoSwitchPHPVersion functions
1 parent c5a7de0 commit a4be795

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/utils/phpvmrc.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ const { usePHPVersion } = require('../commands/use');
1111
function findPHPVMRCFile(startDir = process.cwd()) {
1212
let currentDir = startDir;
1313

14-
while (currentDir !== '/') {
14+
while (true) {
1515
const phpvmrcPath = path.join(currentDir, '.phpvmrc');
1616
if (fs.existsSync(phpvmrcPath)) {
1717
return phpvmrcPath;
1818
}
19-
currentDir = path.resolve(currentDir, '..');
19+
20+
const parentDir = path.resolve(currentDir, '..');
21+
if (parentDir === currentDir) break; // Stop if we've reached the root directory
22+
23+
currentDir = parentDir;
2024
}
2125

2226
return null;
@@ -41,10 +45,10 @@ async function autoSwitchPHPVersion() {
4145
} catch (error) {
4246
console.error(`Failed to switch to PHP ${version}: ${error.message}`);
4347
}
44-
} else {
45-
// Silent if no .phpvmrc file is found
46-
return;
4748
}
49+
50+
// Silent return when no .phpvmrc is found
51+
return;
4852
}
4953

5054
module.exports = { findPHPVMRCFile, autoSwitchPHPVersion };

0 commit comments

Comments
 (0)