Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

User:Eloy Lafuente (stronk7)/Classes MDLSITE-6216: Difference between revisions

From MoodleDocs
No edit summary
(Add correct (as they are now) phpdocs for the class.)
Line 13: Line 13:
<code php>
<code php>
/**
/**
  * Documentation Block Here
  * 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 {
class sample_class {
Line 20: Line 26:
}
}
</code>
</code>
Note the classes PHPDoc style is defined with more detail in the [https://docs.moodle.org/dev/Coding_style#Classes_3 Documentation and comments / Classes] section in this document.

Revision as of 10:05, 19 October 2020

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.