Skip to content

Instantly share code, notes, and snippets.

@bendavies
Created November 20, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendavies/37a71c8aeb325acc566292ab1ec0fe27 to your computer and use it in GitHub Desktop.
Save bendavies/37a71c8aeb325acc566292ab1ec0fe27 to your computer and use it in GitHub Desktop.
update phpstan baseline
#!/usr/bin/env bash
set -eu
function os_is_darwin {
[[ $(uname -s) == "Darwin" ]]
}
function file_replace_text {
local -r original_text_regex="$1"
local -r replacement_text="$2"
local -r file="$3"
local args=()
args+=("-i")
if os_is_darwin; then
args+=("")
fi
args+=("s|$original_text_regex|$replacement_text|")
args+=("$file")
sed "${args[@]}" > /dev/null
}
function file_contains_text {
local readonly text="$1"
local readonly file="$2"
grep -q "$text" "$file"
}
function comment_out_include {
if file_contains_text "^ - phpstan-baseline.neon" phpstan.neon; then
file_replace_text " - phpstan-baseline.neon" "# - phpstan-baseline.neon" phpstan.neon
fi
}
function comment_in_include {
if file_contains_text "^# - phpstan-baseline.neon" phpstan.neon; then
file_replace_text "# - phpstan-baseline.neon" " - phpstan-baseline.neon" phpstan.neon
fi
}
function update_baseline {
vendor/bin/phpstan analyse \
--configuration phpstan.neon \
--error-format baselineNeon \
> phpstan-baseline.neon
}
trap comment_in_include EXIT
comment_out_include
update_baseline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment