Conditions | 12 |
Paths | 68 |
Total Lines | 52 |
Code Lines | 35 |
Lines | 13 |
Ratio | 25 % |
Changes | 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 |
||
133 | protected function moveInconsistentPage( $row, $title ) { |
||
134 | if ( $title->exists() || $title->getInterwiki() || !$title->canExist() ) { |
||
135 | if ( $title->getInterwiki() || !$title->canExist() ) { |
||
136 | $prior = $title->getPrefixedDBkey(); |
||
137 | } else { |
||
138 | $prior = $title->getDBkey(); |
||
139 | } |
||
140 | |||
141 | # Old cleanupTitles could move articles there. See bug 23147. |
||
142 | $ns = $row->page_namespace; |
||
143 | if ( $ns < 0 ) { |
||
144 | $ns = 0; |
||
145 | } |
||
146 | |||
147 | # Namespace which no longer exists. Put the page in the main namespace |
||
148 | # since we don't have any idea of the old namespace name. See bug 68501. |
||
149 | if ( !MWNamespace::exists( $ns ) ) { |
||
150 | $ns = 0; |
||
151 | } |
||
152 | |||
153 | $clean = 'Broken/' . $prior; |
||
154 | $verified = Title::makeTitleSafe( $ns, $clean ); |
||
155 | if ( !$verified || $verified->exists() ) { |
||
156 | $blah = "Broken/id:" . $row->page_id; |
||
157 | $this->output( "Couldn't legalize; form '$clean' exists; using '$blah'\n" ); |
||
158 | $verified = Title::makeTitleSafe( $ns, $blah ); |
||
159 | } |
||
160 | $title = $verified; |
||
161 | } |
||
162 | if ( is_null( $title ) ) { |
||
163 | $this->error( "Something awry; empty title.", true ); |
||
164 | } |
||
165 | $ns = $title->getNamespace(); |
||
166 | $dest = $title->getDBkey(); |
||
167 | |||
168 | if ( $this->dryrun ) { |
||
169 | $this->output( "DRY RUN: would rename $row->page_id ($row->page_namespace," . |
||
170 | "'$row->page_title') to ($ns,'$dest')\n" ); |
||
171 | View Code Duplication | } else { |
|
172 | $this->output( "renaming $row->page_id ($row->page_namespace," . |
||
173 | "'$row->page_title') to ($ns,'$dest')\n" ); |
||
174 | $dbw = $this->getDB( DB_MASTER ); |
||
175 | $dbw->update( 'page', |
||
176 | [ |
||
177 | 'page_namespace' => $ns, |
||
178 | 'page_title' => $dest |
||
179 | ], |
||
180 | [ 'page_id' => $row->page_id ], |
||
181 | __METHOD__ ); |
||
182 | LinkCache::singleton()->clear(); |
||
183 | } |
||
184 | } |
||
185 | } |
||
189 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.