Skip to content

Commit

Permalink
Publishing the Phpstorm custom PSR coding style for others to reuse (…
Browse files Browse the repository at this point in the history
…and to make sure I don't lose it, since we want to apply it again (eg. every year or so))

This fixes #3895

the mass conversion was applied in: [ae4b031]
  • Loading branch information
mattab committed Apr 14, 2013
1 parent 8343de5 commit 1c41d3c
Show file tree
Hide file tree
Showing 2 changed files with 170 additions and 0 deletions.
152 changes: 152 additions & 0 deletions misc/others/phpstorm-codestyles/Piwik_codestyle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<code_scheme name="Piwik-codestyle">
<option name="RIGHT_MARGIN" value="160" />
<PHPCodeStyleSettings>
<option name="ALIGN_KEY_VALUE_PAIRS" value="true" />
<option name="LOWER_CASE_BOOLEAN_CONST" value="true" />
<option name="LOWER_CASE_NULL_CONST" value="true" />
</PHPCodeStyleSettings>
<XML>
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
</XML>
<codeStyleSettings language="JavaScript">
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="KEEP_SIMPLE_BLOCKS_IN_ONE_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
</codeStyleSettings>
<codeStyleSettings language="PHP">
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<arrangement>
<rules>
<rule>
<match>
<TYPE>CONST</TYPE>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PUBLIC</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PROTECTED</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PRIVATE</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PUBLIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PROTECTED</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>FIELD</TYPE>
<MODIFIER>PRIVATE</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<TYPE>CONSTRUCTOR</TYPE>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PUBLIC</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PROTECTED</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PRIVATE</MODIFIER>
<MODIFIER>STATIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PUBLIC</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PROTECTED</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<AND>
<TYPE>METHOD</TYPE>
<MODIFIER>PRIVATE</MODIFIER>
</AND>
</match>
</rule>
<rule>
<match>
<TYPE>TRAIT</TYPE>
</match>
</rule>
<rule>
<match>
<TYPE>INTERFACE</TYPE>
</match>
</rule>
<rule>
<match>
<TYPE>CLASS</TYPE>
</match>
</rule>
</rules>
</arrangement>
</codeStyleSettings>
</code_scheme>

18 changes: 18 additions & 0 deletions misc/others/phpstorm-codestyles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Phpstorm has an awesome feature called "Reformat code" which reformats all PHP code to follow a particular selected coding style.

Piwik uses PSR coding standard for php source code. We use a slightly customized PSR style
(because the default PSR style in Phpstorm results in some unwanted changes).

Steps:
* Use latest Phpstorm
* Copy this Piwik_codestyle.xml file in your ~/.WebIde60/config/codestyles/
* If you use Windows or Mac see which path to copy at: http://intellij-support.jetbrains.com/entries/23358108
* Restart PhpStorm.
* Select this coding in Settings>Code style.

Phpstorm can also be configured to apply the style automatically before commit.

You are now writing code that respects Piwik coding standards. Enjoy!

Reference: http://piwik.org/participate/coding-standards/

3 comments on commit 1c41d3c

@timo-bes
Copy link
Member

Choose a reason for hiding this comment

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

Awesome, awesome, AWESOME!!!!

@timo-bes
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a detailed specification for JS coding style as well?

@mattab
Copy link
Member Author

@mattab mattab commented on 1c41d3c Apr 14, 2013

Choose a reason for hiding this comment

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

it would be great! But I am not good enough Javascript ninja to have a clear opinion on the coding style. If anyone has some ideas (maybe we can use the default phpstorm provided...)

also more generally, we should think about the way Javascript should be written in Piwik (to have some kind of consistency) -- well discuss about that in a few weeks

Please sign in to comment.