Skip to content

Instantly share code, notes, and snippets.

@edmondscommerce
Last active August 20, 2021 08:23
Show Gist options
  • Save edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2 to your computer and use it in GitHub Desktop.
Save edmondscommerce/89695c9cd2584fefdf540fb1c528d2c2 to your computer and use it in GitHub Desktop.
Laravel PHPStan Runner
#!/usr/bin/env bash
readonly DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
cd $DIR;
set -e
set -u
set -o pipefail
standardIFS="$IFS"
IFS=$'\n\t'
echo "
===========================================
$(hostname) $0 $@
===========================================
"
readonly projectRoot=$(realpath $DIR/../../);
readonly logPath="$projectRoot/storage/logs/static-analysis.log"
cd $projectRoot
if [[ ! -f ./vendor/bin/phpstan ]]
then
composer require --dev phpstan/phpstan
fi
echo "generate IDE helper"
php artisan ide-helper:generate
sed -i 's#exit("This file should not be included, only analyzed by your IDE");#if\(class_exists\(\\\PHPStan\\\Analyser\\\Analyser::class, false\)\) exit\("This file should not be included, only analyzed by your IDE"\);#g' _ide_helper.php
echo "done"
echo "run analysis"
./vendor/bin/phpstan \
analyse \
--autoload-file=_ide_helper.php \
--level 7 \
app \
| tee $logPath;
echo "Finished, log output written to $logPath";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment