User:Eloy Lafuente (stronk7)/Classes MDLSITE-6216: Difference between revisions
From MoodleDocs
(change applied) |
No edit summary |
||
Line 1: | Line 1: | ||
This change has been applied to the coding style already, see: | |||
- MDLSITE-6216: https://docs.moodle.org/dev/index.php?title=Coding_style&type=revision&diff=57954&oldid=57953 | |||
=== Class declarations === | === Class declarations === | ||
Line 4: | Line 8: | ||
* Classes must go under their respective "component/classes" dir to get the benefits of autoloading and [https://docs.moodle.org/dev/Coding_style#Namespaces namespacing]. There aren't such luxuries out from there. | * Classes must go under their respective "component/classes" dir to get the benefits of autoloading and [https://docs.moodle.org/dev/Coding_style#Namespaces namespacing]. There aren't such luxuries out from there. | ||
* Each php file will contain only one class (or interface, or trait...). Unless it's part of old APIs where multi-artifact files were allowed. | * Each php file will contain only one class (or interface, or trait...). Unless it's part of old APIs where multi-artifact files were allowed. | ||
* The brace should always be written on the line beside the class name. | * The brace should always be written on the line beside the class name. |
Revision as of 08:45, 23 October 2020
This change has been applied to the coding style already, see:
- MDLSITE-6216: https://docs.moodle.org/dev/index.php?title=Coding_style&type=revision&diff=57954&oldid=57953
Class declarations
- Classes must be named according to Moodle's naming conventions.
- Classes must go under their respective "component/classes" dir to get the benefits of autoloading and namespacing. There aren't such luxuries out from there.
- Each php file will contain only one class (or interface, or trait...). Unless it's part of old APIs where multi-artifact files were allowed.
- The brace should always be written on the line beside the class name.
- Every class must have a documentation block that conforms to the PHPDocumentor standard.
- All code in a class must be indented with 4 spaces.
- Placing additional code in class files is only permitted to require artifacts not provided via autoloading (old classes or libs out from the "classes" directories and not loaded by Moodle's bootstrap). In those cases, the use of the MOODLE_INTERNAL check will be required.
- An example:
/**
* Short description for class.
*
* Long description for class (if any)...
*
* @package mod_mymodule
* @copyright 2008 Kim Bloggs
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class sample_class {
// All contents of class
// must be indented 4 spaces.
}
Note the classes PHPDoc style is defined with more detail in the Documentation and comments / Classes section in this document.