Skip to content

Commit 18dd7f1

Browse files
committed
refactor(psalm-ddev): improve project name extraction and streamline argument handling
1 parent ecfee18 commit 18dd7f1

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

booster/bin/psalm-ddev

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,26 @@
33
# Determine the project root on the host dynamically
44
HOST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
55

6-
# Extract project name from .ddev/config.yaml to determine container name dynamically
7-
PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}')
6+
# Extract project name; handle potential quotes in config.yaml
7+
PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
88
CONTAINER_NAME="ddev-${PROJECT_NAME}-web"
99

10-
# Define the project root in the container
11-
CONTAINER_ROOT="/var/www/html"
12-
1310
# Initialize an array for the new arguments
1411
NEW_ARGS=()
1512

16-
# Loop through all arguments passed to the script
1713
for arg in "$@"; do
18-
# Skip if the argument is the psalm script itself
19-
if [[ "$arg" == *"psalm.phar" ]] || [[ "$arg" == *"vendor/bin/psalm" ]]; then
20-
continue
21-
fi
22-
23-
# Skip PHP arguments passed by the extension (starting with -d or -f)
24-
if [[ "$arg" == -d* ]] || [[ "$arg" == -f* ]]; then
25-
continue
26-
fi
27-
28-
# Skip the double dash separator often used to separate options
29-
if [[ "$arg" == "--" ]]; then
30-
continue
31-
fi
32-
33-
# Check if the argument contains the host root path
34-
# if [[ "$arg" == *"$HOST_ROOT"* ]]; then
35-
# Replace the host root path with the container root path
36-
# NEW_ARGS+=("${arg//$HOST_ROOT/$CONTAINER_ROOT}")
37-
# else
38-
# Keep the argument as is
39-
NEW_ARGS+=("$arg")
40-
# fi
14+
# Skip arguments that would confuse the Psalm Phar inside the container
15+
[[ "$arg" == *"psalm.phar" ]] && continue
16+
[[ "$arg" == *"vendor/bin/psalm" ]] && continue
17+
[[ "$arg" == -d* ]] && continue
18+
[[ "$arg" == -f* ]] && continue
19+
[[ "$arg" == "--" ]] && continue
20+
21+
NEW_ARGS+=("$arg")
4122
done
4223

43-
# Execute Psalm inside the DDEV container with the modified arguments
44-
# Use docker exec for better performance than ddev exec
45-
# -i is required to keep STDIN open for the Language Server protocol
46-
docker exec -i -w /var/www/html "$CONTAINER_NAME" ./vendor/bin/psalm.phar "${NEW_ARGS[@]}"
24+
# Execute Psalm
25+
# -i: keeps STDIN open (critical for Language Server Protocol)
26+
# -w: sets the working dir to the HOST path (which is symlinked in the container)
27+
# exec: replaces the bash process with docker so signals (like SIGTERM) are passed through
28+
exec docker exec -i -w "$HOST_ROOT" "$CONTAINER_NAME" ./vendor/bin/psalm.phar "${NEW_ARGS[@]}"

0 commit comments

Comments
 (0)