| Conditions | 16 |
| Paths | 578 |
| Total Lines | 69 |
| 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 |
||
| 48 | function onView() { |
||
| 49 | $this->getOutput()->disable(); |
||
| 50 | $request = $this->getRequest(); |
||
| 51 | $response = $request->response(); |
||
| 52 | $config = $this->context->getConfig(); |
||
| 53 | |||
| 54 | if ( !$request->checkUrlExtension() ) { |
||
| 55 | return; |
||
| 56 | } |
||
| 57 | |||
| 58 | if ( $this->getOutput()->checkLastModified( $this->page->getTouched() ) ) { |
||
|
|
|||
| 59 | return; // Client cache fresh and headers sent, nothing more to do. |
||
| 60 | } |
||
| 61 | |||
| 62 | $gen = $request->getVal( 'gen' ); |
||
| 63 | if ( $gen == 'css' || $gen == 'js' ) { |
||
| 64 | $this->gen = true; |
||
| 65 | } |
||
| 66 | |||
| 67 | $contentType = $this->getContentType(); |
||
| 68 | |||
| 69 | $maxage = $request->getInt( 'maxage', $config->get( 'SquidMaxage' ) ); |
||
| 70 | $smaxage = $request->getIntOrNull( 'smaxage' ); |
||
| 71 | if ( $smaxage === null ) { |
||
| 72 | if ( $contentType == 'text/css' || $contentType == 'text/javascript' ) { |
||
| 73 | // CSS/JS raw content has its own CDN max age configuration. |
||
| 74 | // Note: Title::getCdnUrls() includes action=raw for css/js pages, |
||
| 75 | // so if using the canonical url, this will get HTCP purges. |
||
| 76 | $smaxage = intval( $config->get( 'ForcedRawSMaxage' ) ); |
||
| 77 | } else { |
||
| 78 | // No CDN cache for anything else |
||
| 79 | $smaxage = 0; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | // Set standard Vary headers so cache varies on cookies and such (T125283) |
||
| 84 | $response->header( $this->getOutput()->getVaryHeader() ); |
||
| 85 | if ( $config->get( 'UseKeyHeader' ) ) { |
||
| 86 | $response->header( $this->getOutput()->getKeyHeader() ); |
||
| 87 | } |
||
| 88 | |||
| 89 | $response->header( 'Content-type: ' . $contentType . '; charset=UTF-8' ); |
||
| 90 | // Output may contain user-specific data; |
||
| 91 | // vary generated content for open sessions on private wikis |
||
| 92 | $privateCache = !User::isEveryoneAllowed( 'read' ) && |
||
| 93 | ( $smaxage == 0 || MediaWiki\Session\SessionManager::getGlobalSession()->isPersistent() ); |
||
| 94 | // Don't accidentally cache cookies if user is logged in (T55032) |
||
| 95 | $privateCache = $privateCache || $this->getUser()->isLoggedIn(); |
||
| 96 | $mode = $privateCache ? 'private' : 'public'; |
||
| 97 | $response->header( |
||
| 98 | 'Cache-Control: ' . $mode . ', s-maxage=' . $smaxage . ', max-age=' . $maxage |
||
| 99 | ); |
||
| 100 | |||
| 101 | $text = $this->getRawText(); |
||
| 102 | |||
| 103 | // Don't return a 404 response for CSS or JavaScript; |
||
| 104 | // 404s aren't generally cached and it would create |
||
| 105 | // extra hits when user CSS/JS are on and the user doesn't |
||
| 106 | // have the pages. |
||
| 107 | if ( $text === false && $contentType == 'text/x-wiki' ) { |
||
| 108 | $response->statusHeader( 404 ); |
||
| 109 | } |
||
| 110 | |||
| 111 | if ( !Hooks::run( 'RawPageViewBeforeOutput', [ &$this, &$text ] ) ) { |
||
| 112 | wfDebug( __METHOD__ . ": RawPageViewBeforeOutput hook broke raw page output.\n" ); |
||
| 113 | } |
||
| 114 | |||
| 115 | echo $text; |
||
| 116 | } |
||
| 117 | |||
| 245 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: