Skip to content

Conversation

@AltamashShaikh
Copy link
Contributor

Description:

Adds PHPStan to Slack plugin

Review

@AltamashShaikh AltamashShaikh added the Needs Review For pull requests that need a code review. label Aug 26, 2025
@AltamashShaikh AltamashShaikh requested a review from a team August 26, 2025 02:45
Copy link
Contributor

@james-hill-matomo james-hill-matomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Given this is a brand new plugin, could we have a higher level as base?

Can bump the level that high with (almost) no errors.
@james-hill-matomo james-hill-matomo force-pushed the PG-4491-phpstan branch 11 times, most recently from 2a2cda8 to 1ddee14 Compare August 26, 2025 22:35
@james-hill-matomo
Copy link
Contributor

@AltamashShaikh Can you add the git hooks and check that they work with your non ddev setup? They should run successfully on git pushing so long as you've modified or created a php file.

git config core.hooksPath .git-hooks-matomo

I've bumped the base level up to 5 as I was able to do so with minimal code fixes (see commit).

Copy link
Contributor

@james-hill-matomo james-hill-matomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AltamashShaikh Happy to merge if you're OK with my changes, and can you confirm that the pre-push git hook works for you?

@AltamashShaikh
Copy link
Contributor Author

@AltamashShaikh Can you add the git hooks and check that they work with your non ddev setup? They should run successfully on git pushing so long as you've modified or created a php file.

git config core.hooksPath .git-hooks-matomo

I've bumped the base level up to 5 as I was able to do so with minimal code fixes (see commit).

@james-hill-matomo I gave execute permission to pre-push file chmod +x .git-hooks-matomo/pre-push and updated the pre-push file to make git push work.

@AltamashShaikh
Copy link
Contributor Author

@james-hill-matomo I updated the pre-push file, earlier it was running only for 5.x-dev branch corrected to pick the current branch and changes around plugin_path, please check on DDEV for me its working fine.

echo "Running pre-commit hook in repo: $REPO_DIR"

if [[ "$REPO_DIR" =~ /plugins/(.*) ]]; then
PLUGIN_PATH=${REPO_DIR}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to get plugin_path

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 ${BRANCH_NAME} --diff-filter=A | grep '\.php$' || true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added branch name. earlier it was referring to 5.x-dev

if [ -z "$CHANGED_FILES" ]; then
echo "No created PHP files"
else
echo "Running PHPstan at a very high level on new files"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed filtering of changed files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That adds the plugin path, and is needed for it to work in ddev. I hope I fixed it for non ddev by putting a "cd" at the start of the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because of cd

### 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added branch name here

if [ -z "$CHANGED_FILES" ]; then
echo "No changed PHP files"
else
echo "Running PHPstan on modified files"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed filtering of files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That adds the plugin path, and is needed for it to work in ddev. I hope I fixed it for non ddev by putting a "cd" at the start of the script.

phpstan.neon Outdated
# ../../ 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.
- ../../
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo Is this needed ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be getting everything we need from ../../bootstrap-phpstan.php (for core) and ../plugins/ for non core plugins we include.

Including ../../ is maybe not necessary, but it doesn't seem to slow things down either.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo Was getting recursive error after recent change
image I changed to below

Suggested change
- ../../
- .

@james-hill-matomo
Copy link
Contributor

@AltamashShaikh Ddev broke for me, so I tweaked the files again - can you test on your local and let me know? We can do screenshare if that's easier.

@james-hill-matomo
Copy link
Contributor

@james-hill-matomo I updated the pre-push file, earlier it was running only for 5.x-dev branch corrected to pick the current branch and changes around plugin_path, please check on DDEV for me its working fine.

That branch change didn't work for me - the idea is that the system always compares your current branch with 5.x-dev .

I've taken your change and made it so that it figures out the default branch, to save us some time when 6.x comes out.

### Run PHPStan on newly created files. ###

PHPSTAN_CREATED_CONFIG=phpstan/phpstan.created.neon
MAIN_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo getting this error when running MAIN_BRANCH=$(git symbolic-ref --short refs/remotes/origin/HEAD)
fatal: ref refs/remotes/origin/HEAD is not a symbolic ref

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can hardcode it, we need to change only once in future for 6.x

if command -v php >/dev/null 2>&1; then
cd "${MATOMO_DIR}"
if [ -f "vendor/bin/phpstan" ]; then
COMMAND="vendor/bin/phpstan"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo This should have full path

Suggested change
COMMAND="vendor/bin/phpstan"
COMMAND="${MATOMO_DIR}/vendor/bin/phpstan"

Copy link
Contributor Author

@AltamashShaikh AltamashShaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-hill-matomo I made few tweaks to work it for non-ddev, can you check again with ddev ?

@james-hill-matomo
Copy link
Contributor

@AltamashShaikh Works for me too !

@james-hill-matomo james-hill-matomo merged commit ebbbc48 into PG-4491-schedule-report-slack Aug 31, 2025
8 checks passed
@james-hill-matomo james-hill-matomo deleted the PG-4491-phpstan branch August 31, 2025 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review For pull requests that need a code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants