| Conditions | 5 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 45 |
| 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 |
||
| 104 | private function getMockWiki() { |
||
| 105 | $mock = $this->getMockBuilder( 'Wiki' ) |
||
| 106 | ->disableOriginalConstructor() |
||
| 107 | ->getMock(); |
||
| 108 | $mock->expects( $this->any() ) |
||
| 109 | ->method( 'get_namespaces' ) |
||
| 110 | ->will( $this->returnValue( array( 0 => '', 1 => 'Talk' ) ) ); |
||
| 111 | $mock->expects( $this->any() ) |
||
| 112 | ->method( 'apiQuery' ) |
||
| 113 | ->will( |
||
| 114 | $this->returnCallback( |
||
| 115 | function ( $params ) { |
||
| 116 | if( $params['action'] === 'query' |
||
| 117 | && $params['prop'] === 'info' |
||
| 118 | && $params['inprop'] === 'protection|talkid|watched|watchers|notificationtimestamp|subjectid|url|readable|preload|displaytitle' |
||
| 119 | ) { |
||
| 120 | if( array_key_exists( 'titles', $params ) ) { |
||
| 121 | $title = $params['titles']; |
||
| 122 | $pageid = 1234; |
||
| 123 | } else { |
||
| 124 | $title = 'Foo'; |
||
| 125 | $pageid = $params['pageids']; |
||
| 126 | } |
||
| 127 | return array( |
||
| 128 | 'query' => array( |
||
| 129 | 'pages' => array( |
||
| 130 | $pageid => array( |
||
| 131 | 'pageid' => $pageid, |
||
| 132 | 'ns' => 0, |
||
| 133 | 'title' => $title, |
||
| 134 | 'contentmodel' => 'wikitext', |
||
| 135 | 'pagelanguage' => 'en', |
||
| 136 | 'touched' => '2014-01-26T01:13:44Z', |
||
| 137 | 'lastrevid' => 999, |
||
| 138 | 'counter' => '', |
||
| 139 | 'length' => 76, |
||
| 140 | 'redirect' => '', |
||
| 141 | 'protection' => array(), |
||
| 142 | 'notificationtimestamp' => '', |
||
| 143 | 'talkid' => '66654', |
||
| 144 | 'fullurl' => 'imafullurl', |
||
| 145 | 'editurl' => 'imaediturl', |
||
| 146 | 'readable' => '', |
||
| 147 | 'preload' => '', |
||
| 148 | 'displaytitle' => 'Foo', |
||
| 149 | ) |
||
| 150 | ) |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | } |
||
| 154 | return array(); |
||
| 155 | } |
||
| 156 | ) |
||
| 157 | ); |
||
| 158 | return $mock; |
||
| 159 | } |
||
| 160 | } |
||
| 161 |