Skip to content

Instantly share code, notes, and snippets.

@rrazor
Created April 12, 2021 05:03
Show Gist options
  • Save rrazor/98d0874e73e6169f8bac5dd976b39b9c to your computer and use it in GitHub Desktop.
Save rrazor/98d0874e73e6169f8bac5dd976b39b9c to your computer and use it in GitHub Desktop.
PHP wrapper to remove PhpStorm's XDebug command-line argument when PCov is in use
#!/bin/bash
# This script wraps php to help PhpStorm avoid loading XDebug when all we want
# is a PCov-enabled code coverage report (XDebug makes things very slow).
#
# We detect an argument that looks like -dzend_extension...xdebug.so and omit it
# if we _also_ detect a -dpcov.enabled=1 argument. All other arguments are
# passed through.
set -e
POSITIONAL=()
IS_PCOV=0
XDEBUG_ARG=""
while [[ $# -gt 0 ]]
do
if [[ "$1" =~ .*xdebug\.so$ ]]
then
XDEBUG_ARG="$1"
elif [[ "$1" == "-dpcov.enabled=1" ]]
then
IS_PCOV=1
POSITIONAL+=("$1")
else
POSITIONAL+=("$1")
fi
shift
done
# Only add the XDebug arg back in when we aren't using PCov.
if [[ "$IS_PCOV" == "0" && "$XDEBUG_ARG" != "" ]]
then
# Either php or PhpStorm is sensitive to argument order; extension first!
POSITIONAL=("$XDEBUG_ARG" "${POSITIONAL[@]}")
fi
# Pass through our filtered arguments to PHP.
php "${POSITIONAL[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment