From a6d5752748dd75ac56e0597dc1df3557926ae55a Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 21 Oct 2021 15:11:00 +0100 Subject: [PATCH] [TOOLS][PHPStan] Make a standalone phpstan executable, which executes inside the docker container --- .dir-locals.el | 4 ++-- Makefile | 3 +-- bin/phpstan | 11 +++++++++++ docker/tooling/phpstan.sh | 11 ++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100755 bin/phpstan diff --git a/.dir-locals.el b/.dir-locals.el index f69c8d5a3d..e93940ec15 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,3 +1,3 @@ ((nil . ((php-project-root . auto) - (phpstan-config-file . (root . "phpstan.neon")) - (phpstan-memory-limit . "2G")))) + (phpstan-executable . (root . "bin/phpstan")) + ) diff --git a/Makefile b/Makefile index 5520b854f4..839e1be73e 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,6 @@ DIR=$(strip $(notdir $(CURDIR))) # Seems a bit hack-ish, but `basename` works di translate-container-name = $$(if docker container inspect $(1) > /dev/null 2>&1; then echo $(1); else echo $(1) | sed 'y/_/-/' ; fi) - .PHONY: @if ! docker info > /dev/null; then echo "Docker does not seem to be running"; exit 1; fi @@ -37,7 +36,7 @@ doc-check: bin/php-doc-check src components plugins phpstan: tooling-docker - docker exec $(call translate-container-name,tooling_php_1) /var/tooling/phpstan.sh + bin/phpstan stop-tooling: .PHONY cd docker/tooling && docker-compose down diff --git a/bin/phpstan b/bin/phpstan new file mode 100755 index 0000000000..ba74be5cfc --- /dev/null +++ b/bin/phpstan @@ -0,0 +1,11 @@ +#!/bin/sh + +translate_container_name () { + if docker container inspect "$1" > /dev/null 2>&1; then + echo "$1" + else + echo "$1" | sed 'y/_/-/' + fi +} + +docker exec "$(translate_container_name tooling_php_1)" /var/tooling/phpstan.sh "$@" diff --git a/docker/tooling/phpstan.sh b/docker/tooling/phpstan.sh index 0f28694e9e..47f1a87f23 100755 --- a/docker/tooling/phpstan.sh +++ b/docker/tooling/phpstan.sh @@ -2,6 +2,15 @@ cd /var/www/social || exit 1 + +ARGS=$(echo "$*" | sed 's#\(/[^/]\+\)*/phpstan\.neon#phpstan.neon#') # Remove absolute path to config file + rm -rf /var/www/social/var/cache/* -PHPSTAN_BOOT_KERNEL=1 vendor/bin/phpstan --ansi --no-interaction --memory-limit=2G analyse + +if [ "$#" -eq 0 ]; then + PHPSTAN_BOOT_KERNEL=1 vendor/bin/phpstan --ansi --no-interaction --memory-limit=2G analyse +else + PHPSTAN_BOOT_KERNEL=1 vendor/bin/phpstan $ARGS +fi + rm -rf /var/www/social/var/cache/*