onExtensionFunction uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies
of your class. This makes your code less dependent on global state and it
becomes generally more testable:
// BadclassRouter{publicfunctiongenerate($path){return$_SERVER['HOST'].$path;}}// BetterclassRouter{private$host;publicfunction__construct($host){$this->host=$host;}publicfunctiongenerate($path){return$this->host.$path;}}classController{publicfunctionmyAction(Request$request){// Instead of$page=isset($_GET['page'])?intval($_GET['page']):1;// Better (assuming you use the Symfony2 request)$page=$request->query->get('page',1);}}
Loading history...
19
if ( !\ExtensionRegistry::getInstance()->isLoaded( 'SemanticForms' ) ) {
20
die( '<b>Error:</b> <a href="https://www.mediawiki.org/wiki/Extension:SemanticFormsSelect">Semantic Forms Selects</a> is a Semantic Forms extension. You need to install <a href="https://www.mediawiki.org/wiki/Extension:Semantic_Forms">Semantic Forms</a> first.' );
The method onExtensionFunction() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you
write a short command line script.
In most cases however, using an exit expression makes the code untestable
and often causes incompatibilities with other libraries. Thus, unless you are
absolutely sure it is required here, we recommend to refactor your code to
avoid its usage.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: