Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

PHPCS output different on Bitbucket than locally?

thomas.belknap
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 31, 2020

I'm just starting to setup a pipeline that checks my code against an existing standard that is local to the project in it's own phpcs.xml.dist file. When I run phpcs locally, I get the following output:

```

-----------------------------------------------------------------------------------------

FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 4 LINES

-----------------------------------------------------------------------------------------

  9 | WARNING | Possible parse error: class missing opening or closing brace

  9 | WARNING | Possible parse error: class missing opening or closing brace

  9 | WARNING | Possible parse error: class missing opening or closing brace

11 | WARNING | Consider putting global function "__construct" in a static class

16 | WARNING | Consider putting global function "findNext" in a static class

31 | WARNING | Consider putting global function "markAsProcessing" in a static class

-----------------------------------------------------------------------------------------

```

 

My pipeline file looks like this:

pipelines:
default:
- step:
script: # Modify the commands below to build your repository.
- composer install --prefer-source --no-interaction --dev
- vendor/bin/phpcs src/

The call to phpcs is identical to how I call it locally. But the results are very different:

```

----------------------------------------------------------------------FOUND 9 ERRORS AFFECTING 7 LINES---------------------------------------------------------------------- 11 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found | | 0 14 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found | | 0 16 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found | | 0 29 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found | | 0 31 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found | | 0 32 | ERROR | [x] Opening brace indented incorrectly; expected 0 | | spaces, found 4 32 | ERROR | [x] Opening brace indented incorrectly; expected 0 | | spaces, found 4 48 | ERROR | [x] Closing brace indented incorrectly; expected 0 | | spaces, found 4 48 | ERROR | [x] Closing brace indented incorrectly; expected 0 | | spaces, found 4----------------------------------------------------------------------PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY----------------------------------------------------------------------

```

 

Any help would be greatly appreciated. 

1 answer

0 votes
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 31, 2020

Hello @thomas.belknap,

Thanks for reaching out and welcome to the Community!

I'm not familiar with phpcs, so these are only guesses:

  • Is phpcs.xml.dist under version control? Maybe it isn't checked out in Pipelines, so phpcs is checking your code some default rule set?
  • Is there anything pointing to phpcs.xml.dist? What I mean is how phpcs knows it has to read configuration from that file? Maybe you have some setup locally (maybe externally to the repository) which is not present in Pipelines?

Greatly simplified, a pipeline in Bitbucket runs your script inside a Docker container (which you specify in your YML, or in the default container), so in fact you can debug it locally by following this guide. Once you get your build Docker container up and running, you can execute the commands you have in your script and investigate the results.

Hope this helps. Let me know if you have any questions.

Cheers,
Daniil

thomas.belknap
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 31, 2020

Daniil,

Thanks so much for the reply back! For background to some of your questions: PHP CS is PHP Code Sniffer and is a code format checking app. I'm running it against my repo to ensure that all commits match our guidelines. PHP CS will detect the existence of a phpcs.xml.dist file and automatically pick it up and use it for configuration. Yes, the file is under version control.

It's a bit of a mystery as to why this happens. But I'm beginning to suspect perhaps the config file itself may be suspect: it may be that conflicting directives are being interpreted differently by the two sides. Still really not sure.

Thanks so much for the debugging info! Glad to not have to clog up my repo with testing branches. Please let me know if you think of any other advice! 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events