Hello everyone,
we agreed some time ago, that we would use PSR-2 code style for xRes
development.
http://confluence.app.infra.gs.xtrav.de/display/Entwicklung/Codestyles
PSR-2 however is a very general recommendation. Many things we do
intuitively, I believe it's time to extend a little bit a list of our
rules, to make them more clear. My proposal is to partially adopt
Symfony Framework Coding Stadard, since it shares a lot of rules with
what we already do.
https://symfony.com/doc/3.3/contributing/code/standards.html
Specifically:
- Follow the standards defined in the PSR-0, PSR-1, PSR-2 and PSR-4
documents.
- Add a single space after each comma delimiter (E.g. func($a, $b, $c);
or [$a, $b, $c])
- Add a single space around binary operators (==, &&, ...).
I suggest always use spaces around concatenation as well. (E.g. $a .
$b, $a == $b)
- Place unary operators (!, --, ...) adjacent to the affected variable
(E.g. !$a, not ! $a)
- Use braces to indicate control structure body regardless of the number
of statements it contains; (E.g. if ($a) { doThis(); })
- Declare class properties before methods;
- Use parentheses when instantiating classes regardless of the number of
arguments the constructor has; (E.g. new Obj(); not new Obj;)
- Do not use spaces around [ offset accessor and before ] offset
accessor. (E.g. $a[$b[1]], not $a[ $b[1] ])
- Use camelCase, not underscores, for variable, function and method
names, arguments;
- Prefix abstract classes with Abstract
- Suffix interfaces with Interface
- Suffix traits with Trait
- Suffix exceptions with Exception
- Use alphanumeric characters and underscores for file names (Letters
and numbers, no special characters)
- For type-hinting in PHPDocs and casting, use bool (instead of boolean
or Boolean), int (instead of integer), float (instead of double or real);
- Omit the @return tag if the method does not return anything;
- The @package and @subpackage annotations are not used.
These are just, what I believe we can easily agree on without much
discussion. There are more rules in the Symfony document. If you feel
some other should also be included - please let everyone know.
Best regards
Viktoras Bezaras
--
Mit freundlichen Grüßen
Viktoras Bezaras
- Entwickler -
________________________________________________________
TraSo GmbH
Nonnenstraße 42
D-04229 Leipzig
Tel.: +49 341 355 740 44
E-Mail: v.bezaras(a)traso.de
Internet: http://www.traso.de
________________________________________________________
Geschäftsführer: Haiko Gerdes
Handelsregister: Amtsgericht Leipzig, HRB 21850