0% found this document useful (0 votes)
69 views1 page

Flow Coding Guidelines On One Page

The document provides coding guidelines for Flow in PHP based on PSR-2 standards. It covers namespace structure, use statements, DocBlocks, annotations, class structure, method structure, and exceptions.

Uploaded by

lutfi sulthon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views1 page

Flow Coding Guidelines On One Page

The document provides coding guidelines for Flow in PHP based on PSR-2 standards. It covers namespace structure, use statements, DocBlocks, annotations, class structure, method structure, and exceptions.

Uploaded by

lutfi sulthon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Flow Coding Guidelines (PSR-2) on one page

Namespace starts with vendor name <?php


followed by package key (name) namespace Acme\TestPackage;
and subparts as needed
/*
* This file is part of the Acme.TestPackage package.
Capture the joy of coding as you
*
create excellent web solutions.
* (c) Whoever wrote this
Enjoy coding. Enjoy Flow.
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
One use statement per line. */
One use statement per namespace.
Order statements alphabetically. use Acme\TestPackage\Service\FooGenerator;
Don't import namespaces unless you use Neos\Flow\Annotations as Flow;
use them.
/**
* Here goes the description of the class. It should explain what the main
* purpose of this class is... Description of the class. Make it as
* long as needed, feel free to explain
* @Flow\Scope(”singleton”) how to use it.
No empty line between DocComment */
and class, member var or method. class UniverseAnalyzer extends BaseClass implements SomeInterface
{ UpperCamelCase class name. Class
/** names should be nouns.
* Some injected dependency In other packages, import
Use @var tag. Optional description * \Acme\TestPackage\UniverseAnalyzer
goes in the first comment line * @Flow\Inject and refer to it as UniverseAnalyer.
followed by a blank comment line. * @var FooGenerator
*/
List @Flow\* before other tags:
protected $someDependency = null;
@var, @param, @return, @throws,
@api, @since, @deprecated
/**
* @var bool
*/
static protected $addictedToFlow = true;
Prefer relative namespaces, unless
Fully Qualified Namespace is more /**
readable * Shows if you are a fan of Flow Description of the method. Make it
* as long as needed.
* @var bool
*/
protected $fanOfFlow;

/**
* 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.

/** Write what went wrong, give helpful


* This is a setter for the fanOfFlow property. details and give a hint for a possible
* solution.
* @param boolean $isFan Pass true to mark a fan, false for a Zend follower
* @return bool
@return tag with type, even if it is */
“void”. Only __construct() has no public function setFanOfFlow($isFan)
return tag. {
$this->fanOfFlow = $isFan; Setter methods should start with
} “set”.

/**
* 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;
}

Full PSR-2 Coding standard } https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md


Also check out the latest documentation: http://flowframework.readthedocs.org/en/stable/TheDefinitiveGuide/PartV/CodingGuideLines/index.html

You might also like