Skip to content

PHP CodeSniffer for CI workflow - #3347

Open
lukasdchang wants to merge 17 commits into
aws:masterfrom
lukasdchang:phpcs-formatter
Open

lukasdchang wants to merge 17 commits into
aws:masterfrom
lukasdchang:phpcs-formatter

Conversation

@lukasdchang

@lukasdchang lukasdchang commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a Coding Standards CI job that runs PHP_CodeSniffer against changed PHP files in src/, excluding src/data.

The job compares the PR branch against master, runs PHPCS with phpcs.xml.dist, and reports formatting violations in the workflow logs. When PHPCS finds violations, the job also runs PHPCBF in the CI checkout and prints a fixed-code preview for the affected block. The output includes the local phpcbf command developers can run to apply automatic fixes.

Example:

PHPCS workflow output

Motivation

The SDK already runs static analysis in CI, but it does not currently enforce formatting. This workflow adds formatting checks without adding PHP_CodeSniffer as a package dependency for SDK consumers.

Developers still install PHPCS locally if they want automatic fixes. CI installs PHPCS only inside the GitHub Actions runner.

Possible Improvements

  • Add Reviewdog to publish PHPCS violations as PR comments.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution under the terms of your choice.

@stobrien89 stobrien89 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, just had one request and when you push up those changes, let's see how it reacts to a change in one of the middleware files (move some things around in a file such that it falls out of compliance). You can do that in the same revised commit

Comment thread .github/workflows/tests.yml Outdated

@lukasdchang lukasdchang left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created separate workflow file for coding-standards CI job

Comment thread .github/workflows/coding-standards.yml Outdated
echo ""

exit "$phpcs_exit"
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

too much code in a string, write this as a shell or php script and then invoke it with arguments from the yml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

"Run PHP_CodeSniffer" job now runs run-phpcs.sh which contains the PHPCS bash output script under a new directory for scripts: .github/scripts/.

@lukasdchang

Copy link
Copy Markdown
Contributor Author

coding-standards CI workflow job is confirmed safe from security vulnerabilities by running zizmor locally. What run-phpcs.sh does is it:

  1. Runs PHPCS on changed files and outputs the failure
  2. Outputs a preview of what each file with formatting errors would look like after PHPCBF autofixes them.
  3. Outputs a bash command to run locally to make that fix.

I'm looking to iterate on this so that the workflow job makes PR review comments for PHPCS formatting errors similar to the way smithy-lang handles incorrect changelog entries here. That way developers do not have to sift through the workflow logs to see their formatting error.

@lukasdchang
lukasdchang requested a review from kuhe September 15, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants