From 2288928c13258d0ecc27da4394acaa80456d6258 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Tue, 26 Aug 2025 08:13:17 +0530 Subject: [PATCH 01/17] Adds PHPStan to Slack plugin --- .git-hooks-matomo/pre-push | 105 ++++++++++++++++++++++++++++++++++ .github/workflows/phpstan.yml | 83 +++++++++++++++++++++++++++ phpstan.neon | 19 ++++++ phpstan/phpstan.created.neon | 5 ++ phpstan/phpstan.modified.neon | 5 ++ 5 files changed, 217 insertions(+) create mode 100644 .git-hooks-matomo/pre-push create mode 100644 .github/workflows/phpstan.yml create mode 100644 phpstan.neon create mode 100644 phpstan/phpstan.created.neon create mode 100644 phpstan/phpstan.modified.neon diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push new file mode 100644 index 0000000..00d9ae8 --- /dev/null +++ b/.git-hooks-matomo/pre-push @@ -0,0 +1,105 @@ +#!/bin/bash + +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# + + + +### Check we're running in the context of a plugin and get helpful dir variables ### + +REPO_DIR="$(git rev-parse --show-toplevel)" +echo "Running pre-commit hook in repo: $REPO_DIR" + +if [[ "$REPO_DIR" =~ /plugins/(.*) ]]; then + PLUGIN_PATH="plugins/${BASH_REMATCH[1]}" +else + echo "Not a plugin, not running any further checks" + exit 1 +fi +MATOMO_DIR=$(echo "$REPO_DIR" | sed -E 's|/plugins/.*$||') + + + +### Figure out how to run PHPStan - ddev or not. ### + +COMMAND="" +# Use local PHP if setup +if command -v php >/dev/null 2>&1; then + if "${MATOMO_DIR}/vendor/bin/phpstan" -v 2>&1 > /dev/null; then + COMMAND="${MATOMO_DIR}/vendor/bin/phpstan" + fi +fi +# Use ddev if setup (overridding local setup) +if command -v ddev >/dev/null 2>&1; then + if [ -d "$MATOMO_DIR/.ddev" ]; then + cd "$MATOMO_DIR" || exit 1 + if ddev status 2>&1 > /dev/null; then + COMMAND="ddev exec phpstan" + fi + fi +fi +# If no command, exit +if [[ -z "$COMMAND" ]]; then + echo "No way to run phpstan found." + exit 1 +fi + + + +# Basic setup +cd "$REPO_DIR" +STATUS=0 + + + + +### Run PHPStan on newly created files. ### + +PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon +if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then + CHANGED_FILES=$(git diff --name-only 5.x-dev...HEAD --diff-filter=A | grep '\.php$' || true) + if [ -z "$CHANGED_FILES" ]; then + echo "No created PHP files" + else + echo "Running PHPstan at a very high level on new files" + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 + fi +fi + + + +### Run PHPStan on modified files. ### +PHPSTAN_MODIFIED_CONFIG=phpstan/phpstan.modified.neon +if [[ -f "$PHPSTAN_MODIFIED_CONFIG" ]]; then + CHANGED_FILES=$(git diff --name-only 5.x-dev...HEAD --diff-filter=CM | grep '\.php$' || true) + if [ -z "$CHANGED_FILES" ]; then + echo "No changed PHP files" + else + echo "Running PHPstan on modified files" + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_MODIFIED_CONFIG} || STATUS=1 + fi +fi + +# Don't bother running the full check, as we check changes files already, and +# can assume that the unchanged files don't need rechecking. +# +# Github will check this anyway. +# +# PHPSTAN_BASE_CONFIG=phpstan.neon +# if [[ -f "$PHPSTAN_BASE_CONFIG" ]]; then +# echo "Running PHPstan at a base level on all plugin files" +# $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_BASE_CONFIG} || STATUS=1 +# fi + +exit $STATUS \ No newline at end of file diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..acb9bf9 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,83 @@ +name: PHPStan check + +on: pull_request + +permissions: + actions: read + checks: read + contents: read + deployments: none + issues: read + packages: none + pull-requests: read + repository-projects: none + security-events: none + statuses: read + +env: + PLUGIN_NAME: Slack + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: false + persist-credentials: false + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.2' + + - name: Check out github-action-tests repository + uses: actions/checkout@v4 + with: + repository: matomo-org/github-action-tests + ref: main + path: github-action-tests + + - name: checkout matomo for plugin builds + shell: bash + run: ${{ github.workspace }}/github-action-tests/scripts/bash/checkout_matomo.sh + env: + PLUGIN_NAME: ${{ env.PLUGIN_NAME }} + WORKSPACE: ${{ github.workspace }} + ACTION_PATH: ${{ github.workspace }}/github-action-tests + MATOMO_TEST_TARGET: maximum_supported_matomo + + - name: prepare setup + shell: bash + run: | + cd ${{ github.workspace }}/matomo + echo -e "composer install" + composer install --ignore-platform-reqs + + - name: checkout additional plugins + if: ${{ env.DEPENDENT_PLUGINS != '' }} + shell: bash + working-directory: ${{ github.workspace }}/matomo + run: ${{ github.workspace }}/github-action-tests/scripts/bash/checkout_dependent_plugins.sh + + env: + GITHUB_USER_TOKEN: ${{ secrets.TESTS_ACCESS_TOKEN || secrets.GITHUB_TOKEN }} + + - name: "Restore result cache" + uses: actions/cache/restore@v4 + with: + path: /tmp/phpstan # same as in phpstan.neon + key: "phpstan-result-cache-${{ github.run_id }}" + restore-keys: | + phpstan-result-cache- + + - name: PHPStan whole repo + id: phpstan-all + run: cd ${{ github.workspace }}/matomo && composer run phpstan -- -vvv -c plugins/${{ env.PLUGIN_NAME }}/phpstan.neon + + - name: "Save result cache" + uses: actions/cache/save@v4 + if: ${{ !cancelled() }} + with: + path: /tmp/phpstan # same as in phpstan.neon + key: "phpstan-result-cache-${{ github.run_id }}" \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ce8b1af --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,19 @@ +parameters: + level: 0 + phpVersion: 70200 + tmpDir: /tmp/phpstan/CustomReports/main + paths: + - . + excludePaths: + - tests/* + bootstrapFiles: + - ../../bootstrap-phpstan.php + universalObjectCratesClasses: + - Piwik\Config + - Piwik\View + - Piwik\ViewDataTable\Config + scanDirectories: + # ../../ does not actually seem to give us anything + # that ../plugins/ does not, but including it for + # completeness. It does not seem to slow down performance. + - ../../ \ No newline at end of file diff --git a/phpstan/phpstan.created.neon b/phpstan/phpstan.created.neon new file mode 100644 index 0000000..20d8866 --- /dev/null +++ b/phpstan/phpstan.created.neon @@ -0,0 +1,5 @@ +includes: + - ../phpstan.neon +parameters: + level: 9 + tmpDir: /tmp/phpstan/CustomReports/created \ No newline at end of file diff --git a/phpstan/phpstan.modified.neon b/phpstan/phpstan.modified.neon new file mode 100644 index 0000000..4906daf --- /dev/null +++ b/phpstan/phpstan.modified.neon @@ -0,0 +1,5 @@ +includes: + - ../phpstan.neon +parameters: + level: 1 + tmpDir: /tmp/phpstan/CustomReports/modified \ No newline at end of file From 1811a5782a6f4851e52216d6c45e6d68748162ae Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Tue, 26 Aug 2025 08:33:26 +0530 Subject: [PATCH 02/17] Changed the level to 8 --- phpstan.neon | 2 +- phpstan/phpstan.created.neon | 4 ++-- phpstan/phpstan.modified.neon | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ce8b1af..aacb517 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: level: 0 phpVersion: 70200 - tmpDir: /tmp/phpstan/CustomReports/main + tmpDir: /tmp/phpstan/Slack/main paths: - . excludePaths: diff --git a/phpstan/phpstan.created.neon b/phpstan/phpstan.created.neon index 20d8866..235ef79 100644 --- a/phpstan/phpstan.created.neon +++ b/phpstan/phpstan.created.neon @@ -1,5 +1,5 @@ includes: - ../phpstan.neon parameters: - level: 9 - tmpDir: /tmp/phpstan/CustomReports/created \ No newline at end of file + level: 8 + tmpDir: /tmp/phpstan/Slack/created \ No newline at end of file diff --git a/phpstan/phpstan.modified.neon b/phpstan/phpstan.modified.neon index 4906daf..31de735 100644 --- a/phpstan/phpstan.modified.neon +++ b/phpstan/phpstan.modified.neon @@ -2,4 +2,4 @@ includes: - ../phpstan.neon parameters: level: 1 - tmpDir: /tmp/phpstan/CustomReports/modified \ No newline at end of file + tmpDir: /tmp/phpstan/Slack/modified \ No newline at end of file From 079d54e574ca315990e3568b4a76d9ecaa87d30b Mon Sep 17 00:00:00 2001 From: James Hill Date: Wed, 27 Aug 2025 09:51:57 +1200 Subject: [PATCH 03/17] Bumped phpstan level up to 5 Can bump the level that high with (almost) no errors. --- ScheduleReportSlack.php | 4 ---- phpstan.neon | 5 +++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ScheduleReportSlack.php b/ScheduleReportSlack.php index 594cdb5..d0a5aff 100644 --- a/ScheduleReportSlack.php +++ b/ScheduleReportSlack.php @@ -37,10 +37,6 @@ class ScheduleReportSlack */ private $token; - /** - * @var string - */ - public function __construct( string $subject, string $fileName, diff --git a/phpstan.neon b/phpstan.neon index aacb517..4403469 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 0 + level: 5 phpVersion: 70200 tmpDir: /tmp/phpstan/Slack/main paths: @@ -16,4 +16,5 @@ parameters: # ../../ does not actually seem to give us anything # that ../plugins/ does not, but including it for # completeness. It does not seem to slow down performance. - - ../../ \ No newline at end of file + - ../../ + From eff2eee291134347152ff4e8704b4ee1419c4842 Mon Sep 17 00:00:00 2001 From: James Hill Date: Wed, 27 Aug 2025 09:55:49 +1200 Subject: [PATCH 04/17] Don't check github action with phpstan --- phpstan.neon | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon b/phpstan.neon index 4403469..3506067 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,7 @@ parameters: - . excludePaths: - tests/* + - github-action-tests bootstrapFiles: - ../../bootstrap-phpstan.php universalObjectCratesClasses: From 8696772a4dcdf9dde035c9b55d2c28130ee5a7ad Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 07:46:17 +0530 Subject: [PATCH 05/17] Test changes for multiple channels --- SlackApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SlackApi.php b/SlackApi.php index 696d3a5..d47d8f4 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channel_id' => $channel, + 'channels' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] From 60c76ae4ae865a22e5d0cdff393ab64dd07c7e4e Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 07:47:37 +0530 Subject: [PATCH 06/17] Reverted changes --- SlackApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SlackApi.php b/SlackApi.php index d47d8f4..696d3a5 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channels' => $channel, + 'channel_id' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] From ca92325a593ced80228d8f7c62d253d0dd778c58 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 07:48:20 +0530 Subject: [PATCH 07/17] Adds the multiple channel logic back --- .git-hooks-matomo/pre-push | 0 SlackApi.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 .git-hooks-matomo/pre-push diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push old mode 100644 new mode 100755 diff --git a/SlackApi.php b/SlackApi.php index 696d3a5..d47d8f4 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channel_id' => $channel, + 'channels' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] From 700046d853d1cbbbdd282b8f398a21db5f5cea1a Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 09:35:57 +0530 Subject: [PATCH 08/17] Fixes for pre-push hook to work locally --- .git-hooks-matomo/pre-push | 6 +++--- SlackApi.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index 00d9ae8..a4781be 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -64,15 +64,15 @@ STATUS=0 ### Run PHPStan on newly created files. ### -PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon +PHPSTAN_CREATED_CONFIG=${MATOMO_DIR}/phpstan/phpstan.created.neon if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then CHANGED_FILES=$(git diff --name-only 5.x-dev...HEAD --diff-filter=A | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No created PHP files" else echo "Running PHPstan at a very high level on new files" - CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` - echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${MATOMO_DIR}/${PLUGIN_PATH}/{}"` + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${MATOMO_DIR}/${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 fi fi diff --git a/SlackApi.php b/SlackApi.php index d47d8f4..696d3a5 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channels' => $channel, + 'channel_id' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] From ad666c0425e14d63fa06d8e87463cde1c8fa3cf9 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 11:58:12 +0530 Subject: [PATCH 09/17] Changes to work on all branches and reduced the phpstan level to 5 for both created and updated --- .git-hooks-matomo/pre-push | 13 ++++++------- phpstan/phpstan.created.neon | 2 +- phpstan/phpstan.modified.neon | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index a4781be..c716298 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -20,7 +20,7 @@ REPO_DIR="$(git rev-parse --show-toplevel)" echo "Running pre-commit hook in repo: $REPO_DIR" if [[ "$REPO_DIR" =~ /plugins/(.*) ]]; then - PLUGIN_PATH="plugins/${BASH_REMATCH[1]}" + PLUGIN_PATH=${REPO_DIR} else echo "Not a plugin, not running any further checks" exit 1 @@ -64,15 +64,15 @@ STATUS=0 ### Run PHPStan on newly created files. ### -PHPSTAN_CREATED_CONFIG=${MATOMO_DIR}/phpstan/phpstan.created.neon +PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon +BRANCH_NAME=$(git branch --show-current) if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then - CHANGED_FILES=$(git diff --name-only 5.x-dev...HEAD --diff-filter=A | grep '\.php$' || true) + CHANGED_FILES=$(git diff --name-only ${BRANCH_NAME} --diff-filter=A | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No created PHP files" else echo "Running PHPstan at a very high level on new files" - CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${MATOMO_DIR}/${PLUGIN_PATH}/{}"` - echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${MATOMO_DIR}/${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 fi fi @@ -81,12 +81,11 @@ fi ### Run PHPStan on modified files. ### PHPSTAN_MODIFIED_CONFIG=phpstan/phpstan.modified.neon if [[ -f "$PHPSTAN_MODIFIED_CONFIG" ]]; then - CHANGED_FILES=$(git diff --name-only 5.x-dev...HEAD --diff-filter=CM | grep '\.php$' || true) + CHANGED_FILES=$(git diff --name-only ${BRANCH_NAME} --diff-filter=CM | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No changed PHP files" else echo "Running PHPstan on modified files" - CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_MODIFIED_CONFIG} || STATUS=1 fi fi diff --git a/phpstan/phpstan.created.neon b/phpstan/phpstan.created.neon index 235ef79..ee4a72a 100644 --- a/phpstan/phpstan.created.neon +++ b/phpstan/phpstan.created.neon @@ -1,5 +1,5 @@ includes: - ../phpstan.neon parameters: - level: 8 + level: 5 tmpDir: /tmp/phpstan/Slack/created \ No newline at end of file diff --git a/phpstan/phpstan.modified.neon b/phpstan/phpstan.modified.neon index 31de735..981c06f 100644 --- a/phpstan/phpstan.modified.neon +++ b/phpstan/phpstan.modified.neon @@ -1,5 +1,5 @@ includes: - ../phpstan.neon parameters: - level: 1 + level: 5 tmpDir: /tmp/phpstan/Slack/modified \ No newline at end of file From 72b9ff11b78825a24605ae1b23d126b741371666 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 12:04:15 +0530 Subject: [PATCH 10/17] Force to 8 to ensure github action is working --- SlackApi.php | 2 +- phpstan/phpstan.modified.neon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SlackApi.php b/SlackApi.php index 696d3a5..d47d8f4 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channel_id' => $channel, + 'channels' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] diff --git a/phpstan/phpstan.modified.neon b/phpstan/phpstan.modified.neon index 981c06f..c13b573 100644 --- a/phpstan/phpstan.modified.neon +++ b/phpstan/phpstan.modified.neon @@ -1,5 +1,5 @@ includes: - ../phpstan.neon parameters: - level: 5 + level: 8 tmpDir: /tmp/phpstan/Slack/modified \ No newline at end of file From aa194b2fce1f65e511c7eb5eb63eba67b4607375 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 12:17:55 +0530 Subject: [PATCH 11/17] test for GH action --- SlackApi.php | 2 +- phpstan.neon | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SlackApi.php b/SlackApi.php index d47d8f4..696d3a5 100644 --- a/SlackApi.php +++ b/SlackApi.php @@ -119,7 +119,7 @@ public function completeUploadExternal(string $channel, string $subject): bool [ 'token' => $this->token, 'files' => json_encode([['id' => $this->fileID]]), - 'channels' => $channel, + 'channel_id' => $channel, 'initial_comment' => $subject ], ['Content-Type' => 'multipart/form-data'] diff --git a/phpstan.neon b/phpstan.neon index 3506067..2aa8189 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 8 phpVersion: 70200 tmpDir: /tmp/phpstan/Slack/main paths: From a24df9c4c629a12b47733645ae1d990d6f041da2 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 12:32:45 +0530 Subject: [PATCH 12/17] More fixes around pre-push and reverted to level 5 --- .git-hooks-matomo/pre-push | 4 ++-- phpstan.neon | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index c716298..5f23d49 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -34,7 +34,7 @@ MATOMO_DIR=$(echo "$REPO_DIR" | sed -E 's|/plugins/.*$||') COMMAND="" # Use local PHP if setup if command -v php >/dev/null 2>&1; then - if "${MATOMO_DIR}/vendor/bin/phpstan" -v 2>&1 > /dev/null; then + if [ -f "${MATOMO_DIR}/vendor/bin/phpstan" ]; then COMMAND="${MATOMO_DIR}/vendor/bin/phpstan" fi fi @@ -101,4 +101,4 @@ fi # $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_BASE_CONFIG} || STATUS=1 # fi -exit $STATUS \ No newline at end of file +exit $STATUS diff --git a/phpstan.neon b/phpstan.neon index 2aa8189..3506067 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 8 + level: 5 phpVersion: 70200 tmpDir: /tmp/phpstan/Slack/main paths: From 4be146a58133bd26aff79c8f2f14a37bf2339672 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Wed, 27 Aug 2025 13:10:31 +0530 Subject: [PATCH 13/17] Changed level to 5 for update --- phpstan/phpstan.modified.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan/phpstan.modified.neon b/phpstan/phpstan.modified.neon index c13b573..981c06f 100644 --- a/phpstan/phpstan.modified.neon +++ b/phpstan/phpstan.modified.neon @@ -1,5 +1,5 @@ includes: - ../phpstan.neon parameters: - level: 8 + level: 5 tmpDir: /tmp/phpstan/Slack/modified \ No newline at end of file From 83122ca13f583e1c3ab44c41f0dac8e97b1bdd78 Mon Sep 17 00:00:00 2001 From: James Hill Date: Fri, 29 Aug 2025 16:07:13 +1200 Subject: [PATCH 14/17] Get correct branch for comparison --- .git-hooks-matomo/pre-push | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index 5f23d49..29a7bd9 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -65,9 +65,9 @@ STATUS=0 ### Run PHPStan on newly created files. ### PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon -BRANCH_NAME=$(git branch --show-current) +MAIN_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD) if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then - CHANGED_FILES=$(git diff --name-only ${BRANCH_NAME} --diff-filter=A | grep '\.php$' || true) + CHANGED_FILES=$(git diff --name-only ${MAIN_BRANCH} --diff-filter=A | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No created PHP files" else @@ -81,7 +81,7 @@ fi ### Run PHPStan on modified files. ### PHPSTAN_MODIFIED_CONFIG=phpstan/phpstan.modified.neon if [[ -f "$PHPSTAN_MODIFIED_CONFIG" ]]; then - CHANGED_FILES=$(git diff --name-only ${BRANCH_NAME} --diff-filter=CM | grep '\.php$' || true) + CHANGED_FILES=$(git diff --name-only ${MAIN_BRANCH} --diff-filter=CM | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No changed PHP files" else From 592fb1ffbbbec873a2ca285a7c12f3c59edd6757 Mon Sep 17 00:00:00 2001 From: James Hill Date: Fri, 29 Aug 2025 16:19:07 +1200 Subject: [PATCH 15/17] PHPStan work correctly with DDEV --- .git-hooks-matomo/pre-push | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index 29a7bd9..8d54e0d 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -20,7 +20,7 @@ REPO_DIR="$(git rev-parse --show-toplevel)" echo "Running pre-commit hook in repo: $REPO_DIR" if [[ "$REPO_DIR" =~ /plugins/(.*) ]]; then - PLUGIN_PATH=${REPO_DIR} + PLUGIN_PATH="plugins/${BASH_REMATCH[1]}" else echo "Not a plugin, not running any further checks" exit 1 @@ -35,7 +35,7 @@ COMMAND="" # Use local PHP if setup if command -v php >/dev/null 2>&1; then if [ -f "${MATOMO_DIR}/vendor/bin/phpstan" ]; then - COMMAND="${MATOMO_DIR}/vendor/bin/phpstan" + COMMAND="cd ${MATOMO_DIR} && vendor/bin/phpstan" fi fi # Use ddev if setup (overridding local setup) @@ -72,6 +72,7 @@ if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then echo "No created PHP files" else echo "Running PHPstan at a very high level on new files" + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 fi fi @@ -86,6 +87,7 @@ if [[ -f "$PHPSTAN_MODIFIED_CONFIG" ]]; then echo "No changed PHP files" else echo "Running PHPstan on modified files" + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_MODIFIED_CONFIG} || STATUS=1 fi fi From 4d1a6dbf8e048dbcff138353e361bba1cf04cdb4 Mon Sep 17 00:00:00 2001 From: James Hill Date: Fri, 29 Aug 2025 16:24:07 +1200 Subject: [PATCH 16/17] Fixed context of cd for non ddev phpstan --- .git-hooks-matomo/pre-push | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index 8d54e0d..283859a 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -34,8 +34,9 @@ MATOMO_DIR=$(echo "$REPO_DIR" | sed -E 's|/plugins/.*$||') COMMAND="" # Use local PHP if setup if command -v php >/dev/null 2>&1; then - if [ -f "${MATOMO_DIR}/vendor/bin/phpstan" ]; then - COMMAND="cd ${MATOMO_DIR} && vendor/bin/phpstan" + cd "${MATOMO_DIR}" + if [ -f "vendor/bin/phpstan" ]; then + COMMAND="vendor/bin/phpstan" fi fi # Use ddev if setup (overridding local setup) From 3194ae4f73a30cff8766963db2e1601b666f94dd Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Fri, 29 Aug 2025 11:07:52 +0530 Subject: [PATCH 17/17] Changes for pre-push to work for non-dev --- .git-hooks-matomo/pre-push | 18 +++++++++--------- phpstan.neon | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.git-hooks-matomo/pre-push b/.git-hooks-matomo/pre-push index 283859a..61d26af 100755 --- a/.git-hooks-matomo/pre-push +++ b/.git-hooks-matomo/pre-push @@ -20,7 +20,7 @@ REPO_DIR="$(git rev-parse --show-toplevel)" echo "Running pre-commit hook in repo: $REPO_DIR" if [[ "$REPO_DIR" =~ /plugins/(.*) ]]; then - PLUGIN_PATH="plugins/${BASH_REMATCH[1]}" + PLUGIN_PATH="plugins/${BASH_REMATCH[1]}/" else echo "Not a plugin, not running any further checks" exit 1 @@ -34,9 +34,9 @@ MATOMO_DIR=$(echo "$REPO_DIR" | sed -E 's|/plugins/.*$||') COMMAND="" # Use local PHP if setup if command -v php >/dev/null 2>&1; then - cd "${MATOMO_DIR}" - if [ -f "vendor/bin/phpstan" ]; then - COMMAND="vendor/bin/phpstan" + if [ -f "${MATOMO_DIR}/vendor/bin/phpstan" ]; then + COMMAND="${MATOMO_DIR}/vendor/bin/phpstan" + PLUGIN_PATH='' fi fi # Use ddev if setup (overridding local setup) @@ -66,15 +66,15 @@ STATUS=0 ### Run PHPStan on newly created files. ### PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon -MAIN_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD) +MAIN_BRANCH='5.x-dev' if [[ -f "$PHPSTAN_CREATED_CONFIG" ]]; then CHANGED_FILES=$(git diff --name-only ${MAIN_BRANCH} --diff-filter=A | grep '\.php$' || true) if [ -z "$CHANGED_FILES" ]; then echo "No created PHP files" else echo "Running PHPstan at a very high level on new files" - CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` - echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_CREATED_CONFIG} || STATUS=1 + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}{}"` + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}${PHPSTAN_CREATED_CONFIG} || STATUS=1 fi fi @@ -88,8 +88,8 @@ if [[ -f "$PHPSTAN_MODIFIED_CONFIG" ]]; then echo "No changed PHP files" else echo "Running PHPstan on modified files" - CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}/{}"` - echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}/${PHPSTAN_MODIFIED_CONFIG} || STATUS=1 + CHANGED_FILES=`echo "$CHANGED_FILES" | sed -e 's/^\(.*\)$/"\1"/' | xargs -I{} echo "${PLUGIN_PATH}{}"` + echo "$CHANGED_FILES" | xargs $COMMAND analyse -c ${PLUGIN_PATH}${PHPSTAN_MODIFIED_CONFIG} || STATUS=1 fi fi diff --git a/phpstan.neon b/phpstan.neon index 3506067..fbc5b99 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -17,5 +17,5 @@ parameters: # ../../ does not actually seem to give us anything # that ../plugins/ does not, but including it for # completeness. It does not seem to slow down performance. - - ../../ + - .