Skip to content

Commit a435ad3

Browse files
committed
refactor: improve shell sourcing logic and enhance directory change handling
1 parent f29beec commit a435ad3

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

.shellcheckrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ disable=SC2317
1919
# Some variables are used in eval or sourced contexts
2020
disable=SC2034
2121

22-
# Enable optional checks
23-
enable=quote-safe-variables
24-
enable=require-variable-braces
25-
enable=check-unassigned-uppercase
22+
# Limit output to warnings/errors to avoid noise from info/style checks
23+
severity=warning
2624

2725
# Set shell to bash
2826
shell=bash

phpvm.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ PHPVM_VERSION="1.7.0"
1212
PHPVM_TEST_MODE="${PHPVM_TEST_MODE:-false}"
1313

1414
# Fix to prevent shell crash when sourced
15-
(return 0 2>/dev/null) && return 0 || true # Allow sourcing without execution
15+
if (return 0 2>/dev/null); then
16+
return 0
17+
fi
1618

1719
PHPVM_DIR="${PHPVM_DIR:-$HOME/.phpvm}"
1820
PHPVM_VERSIONS_DIR="$PHPVM_DIR/versions"
@@ -1961,8 +1963,8 @@ EOF
19611963
mkdir -p "$HOME/project"
19621964
echo "7.4" >"$HOME/project/.phpvmrc"
19631965

1964-
# Change to the project directory
1965-
cd "$HOME/project"
1966+
# Change to the project directory
1967+
cd "$HOME/project" || return 1
19661968

19671969
# Test auto-switching
19681970
auto_switch_php_version >/dev/null
@@ -1984,8 +1986,8 @@ EOF
19841986
mkdir -p "$HOME/alias_project"
19851987
echo "default" >"$HOME/alias_project/.phpvmrc"
19861988

1987-
# Change to the project directory
1988-
cd "$HOME/alias_project"
1989+
# Change to the project directory
1990+
cd "$HOME/alias_project" || return 1
19891991

19901992
# Test auto-switching
19911993
auto_switch_php_version >/dev/null
@@ -2001,8 +2003,8 @@ EOF
20012003
mkdir -p "$HOME/bad_project"
20022004
touch "$HOME/bad_project/.phpvmrc"
20032005

2004-
# Change to the project directory
2005-
cd "$HOME/bad_project"
2006+
# Change to the project directory
2007+
cd "$HOME/bad_project" || return 1
20062008

20072009
# Test auto-switching with empty .phpvmrc
20082010
output=$(auto_switch_php_version 2>&1)
@@ -2666,7 +2668,8 @@ else
26662668

26672669
# Auto-use .phpvmrc if enabled and present
26682670
if [ "${PHPVM_AUTO_USE:-true}" = "true" ] && [ -f ".phpvmrc" ]; then
2669-
command -v auto_switch_php_version >/dev/null 2>&1 &&
2671+
if command -v auto_switch_php_version >/dev/null 2>&1; then
26702672
auto_switch_php_version 2>/dev/null || true
2673+
fi
26712674
fi
26722675
fi

0 commit comments

Comments
 (0)