Skip to content

CodingStyles

Paminger edited this page Apr 14, 2016 · 1 revision

Coding Styles

As primary standard we use PSR2. (http://www.php-fig.org/psr/psr-2/)
But with some changes and extension. For example we dont want to use a mixed use of the curved braces {}.

A detailed informatione about the FH-Complete coding style you can find in the code repository. In the "tests/codesniffer"-folder you can find the FHComplete configs for code-sniffer. (https://github.com/FH-Complete/FHC-Core/tree/master/tests/codesniffer)

Code Sniffer

Installation

You can use composer or install it over your distribution or download the phar file.

Debian based distributions
root@host:~$ apt-get install php-codesniffer

Usage

Go to the "tests/codesniffer"-folder and use following commands:

Codesniffer examples
# testing one file
user@host:~/devfolder/FHC-Core/tests/codesniffer$ phpcs --standard=FHComplete ../../application/controllers/api/v1/Example.php
# output:
# FILE: ...Complete/git/FHC-Core/application/controllers/api/v1/Example.php
# ----------------------------------------------------------------------
# FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
# ----------------------------------------------------------------------
#  46 | WARNING | Line exceeds 120 characters; contains 141 characters
# ----------------------------------------------------------------------
#
# Time: 74ms; Memory: 6.5Mb

# make a summary of a folder
user@host:~/devfolder/FHC-Core/tests/codesniffer$ phpcs --standard=FHComplete report=summary ../../application/controllers/
# output:
# PHP CODE SNIFFER REPORT SUMMARY
# ----------------------------------------------------------------------
# FILE                                                  ERRORS  WARNINGS
# ----------------------------------------------------------------------
# ...git/FHC-Core/application/controllers/Examples.php  41      7
# .../git/FHC-Core/application/controllers/DBTools.php  0       3
# ...C-Core/application/controllers/api/v1/Example.php  0       1
# ...C-Core/application/controllers/api/v1/APIAuth.php  0       7
# .../git/FHC-Core/application/controllers/Vilesci.php  0       1
# ----------------------------------------------------------------------
# A TOTAL OF 41 ERRORS AND 19 WARNINGS WERE FOUND IN 5 FILES
# ----------------------------------------------------------------------
# PHPCBF CAN FIX 26 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
# ----------------------------------------------------------------------
#
# Time: 577ms; Memory: 9.75Mb