Professional Documents
Culture Documents
Flow Coding Guidelines On One Page
Flow Coding Guidelines On One Page
Flow Coding Guidelines On One Page
/**
* A great method which shows how to indent control structures.
*
Param tag: type, name, description. * @param MyClass $object An instance of MyClass
* @param array $someArray Some array
* @return void
Method names should be verbs.
* @throws \Exception
*/
Indent with spaces. public function analyzeUniverse(MyClass $object, array $someArray = [])
{ Use type hinting
$subObjects = $object->getSubObjects();
foreach ($subObjects as $subObject) {
/** @var $subObject MySubClass */
$subObject->doSomethingCool();
Only use inline @var annotations
}
when type can't be derived (like in
if (isset($someArray['question'])
an array of objects) to increase
&& $this->answerToEverything === 42
readability and trigger IDE auto-
Multiline conditions: || count($someArray) > 3 {
completion.
Indent them and add a extra indent $this->fanOfFlow = true;
to following code. Put the boolean } else {
operators at beginning of line. throw new \Exception('We cannot tolerate that.', 1223391710);
} UNIX timestamp at time of writing
} the throw clause.
/**
* As simple as it gets – a boolean getter.
*
* @return bool Whether a foo was detected (TRUE) or not (FALSE)
* @api Methods returning boolean values
*/ should start with “has” or “is”. Other
@api tag defines public API getters should start with “get“.
public static function isAddictedToFlow()
{
Opening brace on the next line return self::$addictedToFlow;
}