-
Notifications
You must be signed in to change notification settings - Fork 21
Adds PHPStan, [no_release] #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
996ff2e
Adds PHPStan, [no_release]
AltamashShaikh d3d37dd
changed to level 1
AltamashShaikh d0e95d4
changed to level 0
AltamashShaikh a2c031c
changed to level 1
AltamashShaikh e80c1c6
fixes error
AltamashShaikh 65c3e69
Fixes
lachiebol 2f1d857
phpcs
lachiebol b135044
changed name
lachiebol 26b5acb
Fix
lachiebol e1f594e
Removed unwanted file
AltamashShaikh e195d78
Fixed
lachiebol 0b9b596
Merge branch 'add-phpstan' of https://github.com/matomo-org/plugin-Cu…
lachiebol be51fb7
changed test
lachiebol 65ebb90
Fixed docs
lachiebol 3875c49
removed redundant logic
lachiebol 8032016
Added test cases
lachiebol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #!/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: | ||
| # | ||
| # <local ref> <local oid> <remote ref> <remote oid> | ||
|
|
||
|
|
||
|
|
||
| ### 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 [ -f "${MATOMO_DIR}/vendor/bin/phpstan" ]; then | ||
| COMMAND="${MATOMO_DIR}/vendor/bin/phpstan" | ||
| PLUGIN_PATH='' | ||
| fi | ||
| elif command -v ddev >/dev/null 2>&1; then | ||
| # Use ddev if setup (overridding local setup) | ||
| 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 | ||
| 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 | ||
| 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 ${MAIN_BRANCH} --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 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: CustomAlerts | ||
|
|
||
| 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 }}" |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| parameters: | ||
| level: 1 | ||
| phpVersion: 70200 | ||
| tmpDir: /tmp/phpstan/CustomAlerts/main | ||
| paths: | ||
| - . | ||
| excludePaths: | ||
| - tests/* | ||
| - github-action-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. | ||
| - . | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| includes: | ||
| - ../phpstan.neon | ||
| parameters: | ||
| level: 5 | ||
| tmpDir: /tmp/phpstan/CustomAlerts/created |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| includes: | ||
| - ../phpstan.neon | ||
| parameters: | ||
| level: 5 | ||
| tmpDir: /tmp/phpstan/CustomAlerts/modified |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.