Created
November 20, 2019 10:27
-
-
Save bendavies/37a71c8aeb325acc566292ab1ec0fe27 to your computer and use it in GitHub Desktop.
update phpstan baseline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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