PHP Code Sniffer Checks Reported with Local CLI but not Online

We’ve recently started working on setting up repositories to use Codacy. After a lot of frustration and struggling I finally got the Docker version of the Codacy CLI tool to be reporting the PHPCS errors that I could also see when running PHPCS locally. Our project had an existing phpcs.xml.dist file and the work I am doing, and confirmed locally, is in a forked repository. I’ve opened up a Pull Request draft to the main repository that is connected to Codacy and when the Codacy online tool runs the checks against my PR it is not reporting any of the 40 errors that actually exist when running PHPCS, ir only reports 2 open errors.

Local Codacy PHPCS Analysis (truncated for posting):

Starting analysis …
Found [Info] Missing parameter comment in inc/helpers.php:50 (PHPCS_Squiz_Commenting_FunctionComment)
Found [Info] Missing file doc comment in category.php:1 (PHPCS_Squiz_Commenting_FileComment)
Found [Info] Missing parameter comment in inc/helpers.php:49 (PHPCS_Squiz_Commenting_FunctionComment)
Found [Info] Overriding WordPress globals is prohibited. Found assignment to $post in 404.php:3 (PHPCS_WordPress_WP_GlobalVariablesOverride)
Found [Info] Variable "$timberContext" is not in valid snake_case format, try "$timber_context" in footer.php:6 (PHPCS_WordPress_NamingConventions_ValidVariableName)
Found [Info] Missing parameter comment in inc/helpers.php:47 (PHPCS_Squiz_Commenting_FunctionComment)

Found [Info] Inline comments must end in full-stops, exclamation marks, or question marks in category.php:7 (PHPCS_Squiz_Commenting_InlineComment)
Found [Info] Missing file doc comment in search.php:1 (PHPCS_Squiz_Commenting_FileComment)
Analysis complete

Hello @f1_timnolte, and welcome to the Codacy Community! :wave:

Could you please check if you have the configuration file for PHP CodeSniffer enabled on your Code patterns page of your Codacy repository? This should ensure that Codacy uses the same PHP CodeSniffer configurations that you have defined on your phpcs.xml.dist file.

Here’s the documentation page with more details:

https://docs.codacy.com/repositories-configure/code-patterns/#using-your-own-tool-configuration-files

1 Like

Hi @f1_timnolte, welcome to our community!

The analysis that our CLI performs is slightly different from the analysis that are performed on the PRs, as the CLI will analyze the full list of files that are on your repo, but each PR will only analyze its Diff.

You can check the full list of issues that were found by Codacy by going to the tab “Issues” and you can even use the filter to check only the PHP issues. Checking your repo it seems that you have around 40 PHP issues which should be the same as you got on the CLI.

Regards,
Ivo

2 Likes

So yes, that option is configured so that it uses the repository configuration file.

1 Like

OK, this helps explain a lot. Thanks!

2 Likes