Coding Standards

wakie87 wrote on Wednesday, September 07, 2016:

Hi,

Just bringing in some coding standards to get the codebase to a nice readable format. Will slowly bring in other “fixers/sniffs” to keep eberything as uniform as possible.

Just added a .editorconfig file which most major editors read and adhere to a standard.

root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

Also included .php_cs and phpcs.xml for people who are using sublime/atom/phpstorm. more information can be found here


Currently would reccomend installing these globally via composer.

Currently we are looking for and fixing the following things:

Scott

bradymiller wrote on Wednesday, September 07, 2016:

Hi Scott,

Neat to see this stuff in order to standardize the codebase a bit. Is this something that each user needs to set up or is it a tool that the project runs?

-brady
OpenEMR

wakie87 wrote on Wednesday, September 07, 2016:

Both. If we can get developers to follow these standards before submitting a pull request or commiting to the codebase, slowly we will see the changes flow through the code.
and with github (once we start looking at CI), we can use the git hooks to run on the code before its commited to the codebase.

Scott

sunsetsystems wrote on Wednesday, September 07, 2016:

I’m wondering how others feel about 2-character indent sizes instead of 4. I’ve tended to use 2 because it seems enough for the desired vidual effect, and with 4 it sometimes gets crowded on the right.

Rod
http://www.sunsetsystems.com/

robertdown wrote on Wednesday, September 07, 2016:

Strongly disagree with 2 space indentation as a default. 4 is the standard and horizontal crowding shouldn’t be an issue with today’s monitors. Most PHP code uses 4 spaces and I’ve found 2 spaces is way to clustered together. Could be worse, we could be using 8 spaces :wink:

sunsetsystems wrote on Wednesday, September 07, 2016:

OK but that begs the question, what is current accepted practice for maximum line length?

Rod
http://www.sunsetsystems.com/

robertdown wrote on Wednesday, September 07, 2016:

The PHP standards working group (http://www.php-fig.org/) suggests lines not be longer than 80 characters with a soft limit at 120 but mandates NO hard limit

matthewvita wrote on Wednesday, September 07, 2016:

2 spaces are the way to go :slight_smile:

…but the real goal here is to pick a convention and stick with it! Don’t care if it’s 2 or 4.

robertdown wrote on Wednesday, September 07, 2016:

This is likely to devolve into a flame war between tabs, spaces, and indentation levels real quick.

We should stick to what the majority of the PHP community uses, which is 4

matthewvita wrote on Wednesday, September 07, 2016:

Not disagreeing with you. I don’t care if it’s 2, 4, or 8 as long as we pick one convention and stick with it. 4 is fine.

sunsetsystems wrote on Wednesday, September 07, 2016:

That’s about the amount of consensus I expected. :slight_smile: 4 is fine, I see that mentioned most.

Rod
http://www.sunsetsystems.com/

Hi forum,
I’m not sure if our PSR2 convention is:


OR I need to look into some other document.

Running CI with updated phpcs. Had to disable ScopeClosingBrace rule

hi @robertovasquez ,

That is correct. Rec setting up your environment to do these checks for you, though. Are you using phpstorm?

-brady

I’m have being using phpstorm a little bit. I will get more in to phpstorm from now on.

1 Like

Check out this wiki page:
http://www.open-emr.org/wiki/index.php/OpenEMR_PHPStorm_Setup