Skip to content

Commit

Permalink
Refactor phpvmrc.js to improve findPHPVMRCFile and autoSwitchPHPVersi…
Browse files Browse the repository at this point in the history
…on functions
  • Loading branch information
Thavarshan committed Oct 6, 2024
1 parent c5a7de0 commit a4be795
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/utils/phpvmrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ const { usePHPVersion } = require('../commands/use');
function findPHPVMRCFile(startDir = process.cwd()) {
let currentDir = startDir;

while (currentDir !== '/') {
while (true) {
const phpvmrcPath = path.join(currentDir, '.phpvmrc');
if (fs.existsSync(phpvmrcPath)) {
return phpvmrcPath;
}
currentDir = path.resolve(currentDir, '..');

const parentDir = path.resolve(currentDir, '..');
if (parentDir === currentDir) break; // Stop if we've reached the root directory

currentDir = parentDir;
}

return null;
Expand All @@ -41,10 +45,10 @@ async function autoSwitchPHPVersion() {
} catch (error) {
console.error(`Failed to switch to PHP ${version}: ${error.message}`);
}
} else {
// Silent if no .phpvmrc file is found
return;
}

// Silent return when no .phpvmrc is found
return;
}

module.exports = { findPHPVMRCFile, autoSwitchPHPVersion };

0 comments on commit a4be795

Please sign in to comment.