Conditions | 2 |
Paths | 2 |
Total Lines | 62 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
90 | private function exportQUnit() { |
||
91 | $out = $this->getOutput(); |
||
92 | $out->disable(); |
||
93 | |||
94 | $rl = $out->getResourceLoader(); |
||
95 | |||
96 | $query = [ |
||
97 | 'lang' => $this->getLanguage()->getCode(), |
||
98 | 'skin' => $this->getSkin()->getSkinName(), |
||
99 | 'debug' => ResourceLoader::inDebugMode() ? 'true' : 'false', |
||
100 | 'target' => 'test', |
||
101 | ]; |
||
102 | $embedContext = new ResourceLoaderContext( $rl, new FauxRequest( $query ) ); |
||
103 | $query['only'] = 'scripts'; |
||
104 | $startupContext = new ResourceLoaderContext( $rl, new FauxRequest( $query ) ); |
||
105 | |||
106 | $query['raw'] = true; |
||
107 | |||
108 | $modules = $rl->getTestModuleNames( 'qunit' ); |
||
109 | |||
110 | // Disable autostart because we load modules asynchronously. By default, QUnit would start |
||
111 | // at domready when there are no tests loaded and also fire 'QUnit.done' which then instructs |
||
112 | // Karma to end the run before the tests even started. |
||
113 | $qunitConfig = 'QUnit.config.autostart = false;' |
||
114 | . 'if (window.__karma__) {' |
||
115 | // karma-qunit's use of autostart=false and QUnit.start conflicts with ours. |
||
116 | // Hack around this by replacing 'karma.loaded' with a no-op and call it ourselves later. |
||
117 | // See <https://github.com/karma-runner/karma-qunit/issues/27>. |
||
118 | . 'window.__karma__.loaded = function () {};' |
||
119 | . '}'; |
||
120 | |||
121 | // The below is essentially a pure-javascript version of OutputPage::getHeadScripts. |
||
122 | $startup = $rl->makeModuleResponse( $startupContext, [ |
||
123 | 'startup' => $rl->getModule( 'startup' ), |
||
124 | ] ); |
||
125 | // Embed page-specific mw.config variables. |
||
126 | // The current Special page shouldn't be relevant to tests, but various modules (which |
||
127 | // are loaded before the test suites), reference mw.config while initialising. |
||
128 | $code = ResourceLoader::makeConfigSetScript( $out->getJSVars() ); |
||
129 | // Embed private modules as they're not allowed to be loaded dynamically |
||
130 | $code .= $rl->makeModuleResponse( $embedContext, [ |
||
131 | 'user.options' => $rl->getModule( 'user.options' ), |
||
132 | 'user.tokens' => $rl->getModule( 'user.tokens' ), |
||
133 | ] ); |
||
134 | // Catch exceptions (such as "dependency missing" or "unknown module") so that we |
||
135 | // always start QUnit. Re-throw so that they are caught and reported as global exceptions |
||
136 | // by QUnit and Karma. |
||
137 | $code .= '(function () {' |
||
138 | . 'var start = window.__karma__ ? window.__karma__.start : QUnit.start;' |
||
139 | . 'try {' |
||
140 | . 'mw.loader.using( ' . Xml::encodeJsVar( $modules ) . ' ).always( start );' |
||
141 | . '} catch ( e ) { start(); throw e; }' |
||
142 | . '}());'; |
||
143 | |||
144 | header( 'Content-Type: text/javascript; charset=utf-8' ); |
||
145 | header( 'Cache-Control: private, no-cache, must-revalidate' ); |
||
146 | header( 'Pragma: no-cache' ); |
||
147 | echo $qunitConfig; |
||
148 | echo $startup; |
||
149 | // The following has to be deferred via RLQ because the startup module is asynchronous. |
||
150 | echo ResourceLoader::makeLoaderConditionalScript( $code ); |
||
|
|||
151 | } |
||
152 | |||
201 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.