With cases represented as array of given type, it's highly recommended to document them as type instead of the simpler and less informative "array" alternative (for example int or stdClass).We use short type names (bool instead of boolean, int instead of integer).void: for methods with a explicit empty "return" statement.Īlso, there are some basic rules about how to use those types:.$this: for methods returning the current instance of the class.self: for methods returning a new instance of the parent/called class.static: for methods returning a new instance of the child/caller class.PHP classes:full or relative (to current namespace) class names.PHP complex types: array, stdClass (not Array, object).PHP primitive types: int, bool, string, etc.Some of the tags below etc.) do require the specification of a valid php type and a description. We have some particular rules for using them in Moodle that you must follow: Types PHPDoc has a number of tags that can be used in different places (files, classes and functions). This helps IDEs (like Netbeans or Eclipse) work properly for Moodle developers, and also allows us to generate web documentation automatically. Moodle stays as close as possible to "standard" PHPDoc format to document our files, classes and functions. Documentation and comments Ĭode documentation explains the code flow and the purpose of functions and variables. It shouldn't be considered in other parts of the coding style unless specifically mentioned. Please note that the existence or absence of side-effects in a file only affects as explained above, at code level. strict_types declarations (declarations in general).The term side-effects refers to any global scope code not being: It is discouraged to have multiple return types This can hinder readability, in additional to breaking code if a method is later changed to return by reference. The return value must not be enclosed in parentheses. Methods inside classes must always declare their visibility by using one of the private, protected, or public modifiers.Īs with classes, the brace should always be written on same line as the function name.ĭon't leave spaces between the function name and the opening parenthesis for the arguments. Functions and methods Function and method declaration įunctions must be named according to the Moodle function naming conventions. Giving access to member variables directly by declaring them as public is permitted but discouraged in favor of accessor methods (set/get). Member variables always declare their visibility by using one of the private, protected, or public modifiers. Member variables must be named according to Moodle's variable naming conventions.Īny variables declared in a class must be listed at the top of the class, above the declaration of any methods. The classes PHPDoc style is defined with more detail in the Documentation and comments / Classes section in this document. This is where a plugin or addon can make extensive use of namespaces with noĬhance of conflict with any other plugin or api, now and forever onwards. There are no rules limiting what can be used as a level 3 namespace. \local for any other classes in a component, if the maintainer wants to organise them further (note that for most components, it's probably enough to have all their own classes in the root level1 namespace only). The classes in this namespace must either implement or use the API in some way or The second level, when used, MUST be either: All classes using namespaces in a plugin MUST be contained in this level 1 namespace or a full component name (for example \mod_forum).The first level, when used, MUST be either: Nested namespaces are used when the class implements some core API or when the plugin maintainer want to organise classes to separate namespaces within the plugin - see rules regarding the level2 for details. Just add prettier to your list of fixers.There are clear rules for what is allowable at each level of namespace. The linting plugin ALE has built-in support for prettier and its plugins. Regarding plugin support in the official plugin vim-prettier see this issue. Sublime Text support is available through Package Control and the JsPrettier plugin. Note: Just pressing save does not reformat your current file unless the file has been modified in some way,Īlternatively you can use the Prettier shortcut Ctrl+Alt+Shift+P Sublime Text Tick the On Save button, if you want your files formatting updated on file save.Import prettier from "prettier/standalone" import phpPlugin from prettier.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |