FLOW3 Coding Guidelines
From TYPO3Wiki
This article mainly summarizes the Coding Guidelines we definded for FLOW3 (and later TYPO3 v5) development
Contents |
[edit]
Why follow the Guidelines?
- clean code
- standardized code
- easy-to-read code
- automatic documentation
- licence
[edit]
Rules
[edit]
Naming conventions
- file: starts with F3_ (unless it doesn't belong to a complete own project -> under discussion)
- file: part after F3_ = folder structure
- file: only A-Z a-z 0-9 and _ chars are allowed
- file: UpperCamelCase (Except abbreviations like f.e. MVC)
- file: Tests in Tests directory must end with "Test.php"
- class, interface, ... name must be the same as filename
- CONSTANTS must be Uppercase, including TRUE, FALSE and NULL
- no typical nothing saying names for variables like f.e. $i or $j, better $step, $charCounter, ...
- variables: lowerCamelCase (exceptions see above)
- methods: lowerCamelCase (exceptions see above)
- methods: only A-Z a-z 0-9 allowed (_ only for constructor + magic methods)
- methods: testing methods must not start with "test_", but contain a "@test" tag* class & interface: part after F3_ = folder structure (see above)
- class & interface: starts with F3_ (see above)
- class & interface: name UpperCamelCase (see above)
- class & interface: only A-Z a-z 0-9 and _ chars are allowed
- class: Tests in Tests directory must end with "Test"
- interface: must end with "Interface". no "_" allowed before "Interface"
- abstract: last part must start with "Abstract" (example missing)
[edit]
Folder structure
- valid folder name (correct package key)
- must contain PackageInfo.xml (??)
[edit]
Documentation
- variables: use @var tag
- type hinting whereever possible
- method: use @param and @return
- interface & class: use @package tage
- file: use @package and where possible @subpackage tag
- copyright header must not start with "/**"
- file: includes licence info
- No comments after closing braces
[edit]
Indentation & whitespaces
- tabs, not spaces
- long criterias (f.e. in if constructs): more lines and indent them, following parts must be indenten one time more (example needs to be put here)
- multiline strings = multiple lines
- put if constructs without braces in one line
- dot concatenated strings: put space before and after dot
- one space after if, while, for, foreach and the opening brace
- line end = Unix style aka chr(10) aka "\n"
[edit]
Braces
- else only in this way: "} else {"
- put opening brace on same line with opening token, f.e. "class Demo {"
- put closing brace on own new line indenting with opening token if not before "else"
[edit]
Misc
- specify the type when opening files
- declare scope (public, protected, private) of member and class variables
- dont use "new", but use component manager
- file: includes UTF-8 declaration
- file: starts with <?php and ends with ?>, no breaks in the middle
[edit]
ToDo
- compare with TYPO3 v4 CGL
- compare with FLOW3 guide
- create code example "FLOW3 CGL on one page"
- finish FLOW3CGL package
