system
(system)
September 7, 2016, 4:42am
1
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:
<?xml version="1.0"?>
<ruleset name="OpenEMR Standard">
<description>PSR2 without namespace enforcement.</description>
<arg name="tab-width" value="4" />
<!-- PHP code MUST use only UTF-8 without BOM. -->
<rule ref="Generic.Files.ByteOrderMark" />
<!-- Checks that the opening PHP tag is the first content in a file. -->
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag" />
<!-- Makes sure that shorthand PHP open tags are not used. -->
<rule ref="Generic.PHP.DisallowShortOpenTag" />
<!-- PHP Files should end with exactly one newline. -->
<rule ref="PSR2.Files.EndFileNewline" />
<!-- There MUST NOT be more than one statement per line. -->
<rule ref="Generic.Formatting.DisallowMultipleStatements" />
<!-- Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration" />
<!-- Lines can be 120 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120" />
This file has been truncated. show original
Scott
system
(system)
September 7, 2016, 6:22am
2
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
system
(system)
September 7, 2016, 6:35am
3
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
system
(system)
September 7, 2016, 2:43pm
4
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/
system
(system)
September 7, 2016, 3:48pm
5
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
system
(system)
September 7, 2016, 3:52pm
6
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/
system
(system)
September 7, 2016, 7:40pm
7
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
system
(system)
September 7, 2016, 10:00pm
8
matthewvita wrote on Wednesday, September 07, 2016 :
2 spaces are the way to go
…but the real goal here is to pick a convention and stick with it! Don’t care if it’s 2 or 4.
system
(system)
September 7, 2016, 10:01pm
9
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
system
(system)
September 7, 2016, 10:08pm
10
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.
system
(system)
September 7, 2016, 10:12pm
11
sunsetsystems wrote on Wednesday, September 07, 2016 :
That’s about the amount of consensus I expected. 4 is fine, I see that mentioned most.
Rod
http://www.sunsetsystems.com/
Hi forum,
I’m not sure if our PSR2 convention is:
# Coding Style Guide
This guide extends and expands on [PSR-1], the basic coding standard.
The intent of this guide is to reduce cognitive friction when scanning code
from different authors. It does so by enumerating a shared set of rules and
expectations about how to format PHP code.
The style rules herein are derived from commonalities among the various member
projects. When various authors collaborate across multiple projects, it helps
to have one set of guidelines to be used among all those projects. Thus, the
benefit of this guide is not in the rules themselves, but in the sharing of
those rules.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
interpreted as described in [RFC 2119].
[RFC 2119]: http://www.ietf.org/rfc/rfc2119.txt
[PSR-0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
This file has been truncated. show original
OR I need to look into some other document.
PSR2 rules fully expanded into phpcs.xml, with all errors commented out and marked as fixable or as targets for warnings.
Removing `?>`...
changed 300 files
with 64947 additions
and 50007 deletions .
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