FLOW3 Coding Guidelines

From TYPO3Wiki

Jump to: navigation, search

This article mainly summarizes the Coding Guidelines we definded for FLOW3 (and later TYPO3 v5) development

Contents

Why follow the Guidelines?

  • clean code
  • standardized code
  • easy-to-read code
  • automatic documentation
  • licence

Rules

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)

Folder structure

  • valid folder name (correct package key)
  • must contain PackageInfo.xml (??)

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

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"

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"

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

ToDo

  • compare with TYPO3 v4 CGL
  • compare with FLOW3 guide
  • create code example "FLOW3 CGL on one page"
  • finish FLOW3CGL package
This is a draft version. You're welcome to edit it.
When the content is good enough, please change the {{draft}} tag to {{review}} .


Personal tools