| Conditions | 4 |
| Paths | 8 |
| Total Lines | 198 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 19 | public function settingsProvider() { |
||
| 20 | $cases = [ |
||
| 21 | [ // #0: no local repo, all values set |
||
| 22 | [ // $settings |
||
| 23 | 'repoUrl' => 'http://acme.com', |
||
| 24 | 'repoArticlePath' => '/wiki', |
||
| 25 | 'repoScriptPath' => '/w', |
||
| 26 | 'siteGlobalID' => 'mywiki', |
||
| 27 | 'repoDatabase' => 'foo', |
||
| 28 | 'changesDatabase' => 'doo', |
||
| 29 | 'sharedCacheKeyPrefix' => 'wikibase_shared/', |
||
| 30 | ], |
||
| 31 | [ // $wg |
||
| 32 | 'wgServer' => 'http://www.acme.com', |
||
| 33 | 'wgArticlePath' => '/mywiki', |
||
| 34 | 'wgScriptPath' => '/mediawiki', |
||
| 35 | 'wgDBname' => 'mw_mywiki', |
||
| 36 | ], |
||
| 37 | false, // $repoIsLocal |
||
| 38 | [ // $expected |
||
| 39 | 'repoUrl' => 'http://acme.com', |
||
| 40 | 'repoArticlePath' => '/wiki', |
||
| 41 | 'repoScriptPath' => '/w', |
||
| 42 | 'siteGlobalID' => 'mywiki', |
||
| 43 | 'repoDatabase' => 'foo', |
||
| 44 | 'changesDatabase' => 'doo', |
||
| 45 | 'sharedCacheKeyPrefix' => 'wikibase_shared/', |
||
| 46 | ] |
||
| 47 | ], |
||
| 48 | |||
| 49 | [ // #1: no local repo, no values set |
||
| 50 | [ // $settings |
||
| 51 | ], |
||
| 52 | [ // $wg |
||
| 53 | 'wgServer' => 'http://www.acme.com', |
||
| 54 | 'wgArticlePath' => '/mywiki', |
||
| 55 | 'wgScriptPath' => '/mediawiki', |
||
| 56 | 'wgDBname' => 'mw_mywiki', |
||
| 57 | ], |
||
| 58 | false, // $repoIsLocal |
||
| 59 | [ // $expected |
||
| 60 | 'repoUrl' => '//www.wikidata.org', // hardcoded default |
||
| 61 | 'repoArticlePath' => '/wiki/$1', // hardcoded default |
||
| 62 | 'repoScriptPath' => '/w', // hardcoded default |
||
| 63 | 'siteGlobalID' => 'mw_mywiki', |
||
| 64 | 'repositories' => [ |
||
| 65 | '' => [ |
||
| 66 | 'repoDatabase' => null, |
||
| 67 | 'baseUri' => '//www.wikidata.org/entity/', |
||
| 68 | 'entityNamespaces' => [ |
||
| 69 | 'item' => 0, |
||
| 70 | 'property' => 120, |
||
| 71 | ], |
||
| 72 | ], |
||
| 73 | ], |
||
| 74 | 'changesDatabase' => null, |
||
| 75 | 'sharedCacheKeyPrefix' => 'wikibase_shared/mw_mywiki', |
||
| 76 | ] |
||
| 77 | ], |
||
| 78 | |||
| 79 | [ // #2: local repo, all values set |
||
| 80 | [ // $settings |
||
| 81 | 'repoUrl' => 'http://acme.com', |
||
| 82 | 'repoArticlePath' => '/wiki', |
||
| 83 | 'repoScriptPath' => '/w', |
||
| 84 | 'siteGlobalID' => 'mywiki', |
||
| 85 | 'repoDatabase' => 'foo', |
||
| 86 | 'changesDatabase' => 'doo', |
||
| 87 | 'sharedCacheKeyPrefix' => 'foo:WBL/', |
||
| 88 | ], |
||
| 89 | [ // $wg |
||
| 90 | 'wgServer' => 'http://www.acme.com', |
||
| 91 | 'wgArticlePath' => '/mywiki', |
||
| 92 | 'wgScriptPath' => '/mediawiki', |
||
| 93 | 'wgDBname' => 'mw_mywiki', |
||
| 94 | ], |
||
| 95 | true, // $repoIsLocal |
||
| 96 | [ // $expected |
||
| 97 | 'repoUrl' => 'http://acme.com', |
||
| 98 | 'repoArticlePath' => '/wiki', |
||
| 99 | 'repoScriptPath' => '/w', |
||
| 100 | 'siteGlobalID' => 'mywiki', |
||
| 101 | 'repoDatabase' => 'foo', |
||
| 102 | 'changesDatabase' => 'doo', |
||
| 103 | 'sharedCacheKeyPrefix' => 'foo:WBL/', |
||
| 104 | ] |
||
| 105 | ], |
||
| 106 | ]; |
||
| 107 | |||
| 108 | if ( WikibaseSettings::isRepoEnabled() ) { |
||
| 109 | $cases[] = [ // #3: local repo, no values set |
||
| 110 | [ // $settings |
||
| 111 | ], |
||
| 112 | [ // $wg |
||
| 113 | 'wgServer' => 'http://www.acme.com', |
||
| 114 | 'wgArticlePath' => '/mywiki', |
||
| 115 | 'wgScriptPath' => '/mediawiki', |
||
| 116 | 'wgDBname' => 'mw_mywiki', |
||
| 117 | 'wgWBRepoSettings' => [ |
||
| 118 | 'entityNamespaces' => [ 'item' => 303 ], |
||
| 119 | ], |
||
| 120 | ], |
||
| 121 | true, // $repoIsLocal |
||
| 122 | [ // $expected |
||
| 123 | 'repoUrl' => 'http://www.acme.com', |
||
| 124 | 'repoArticlePath' => '/mywiki', |
||
| 125 | 'repoScriptPath' => '/mediawiki', |
||
| 126 | 'siteGlobalID' => 'mw_mywiki', |
||
| 127 | 'repositories' => [ |
||
| 128 | '' => [ |
||
| 129 | 'repoDatabase' => false, |
||
| 130 | 'baseUri' => 'http://www.acme.com/entity/', |
||
| 131 | ], |
||
| 132 | ], |
||
| 133 | 'changesDatabase' => false, |
||
| 134 | 'sharedCacheKeyPrefix' => 'wikibase_shared/mw_mywiki', |
||
| 135 | ] |
||
| 136 | ]; |
||
| 137 | } |
||
| 138 | |||
| 139 | $cases[] = [ // #4: derive changesDatabase |
||
| 140 | [ // $settings |
||
| 141 | 'repositories' => [ |
||
| 142 | '' => [ |
||
| 143 | 'repoDatabase' => 'mw_foowiki' |
||
| 144 | ], |
||
| 145 | ], |
||
| 146 | ], |
||
| 147 | [ // $wg |
||
| 148 | ], |
||
| 149 | false, // $repoIsLocal |
||
| 150 | [ // $expected |
||
| 151 | 'changesDatabase' => 'mw_foowiki', |
||
| 152 | ] |
||
| 153 | ]; |
||
| 154 | |||
| 155 | if ( WikibaseSettings::isRepoEnabled() ) { |
||
| 156 | $cases[] = [ // #5: sharedCacheKeyPrefix explicitly set |
||
| 157 | [ // $settings |
||
| 158 | 'sharedCacheKeyPrefix' => 'wikibase_shared/wikidata_1_25wmf24' |
||
| 159 | ], |
||
| 160 | [ // $wg |
||
| 161 | 'wgServer' => 'http://www.acme.com', |
||
| 162 | 'wgArticlePath' => '/mywiki', |
||
| 163 | 'wgScriptPath' => '/mediawiki', |
||
| 164 | 'wgDBname' => 'mw_mywiki', |
||
| 165 | 'wgWBRepoSettings' => [ 'entityNamespaces' => [ 'item' => 303 ] ], |
||
| 166 | ], |
||
| 167 | true, // $repoIsLocal |
||
| 168 | [ // $expected |
||
| 169 | 'repoUrl' => 'http://www.acme.com', |
||
| 170 | 'repoArticlePath' => '/mywiki', |
||
| 171 | 'repoScriptPath' => '/mediawiki', |
||
| 172 | 'siteGlobalID' => 'mw_mywiki', |
||
| 173 | 'changesDatabase' => false, |
||
| 174 | 'sharedCacheKeyPrefix' => 'wikibase_shared/wikidata_1_25wmf24', |
||
| 175 | ] |
||
| 176 | ]; |
||
| 177 | } |
||
| 178 | |||
| 179 | $cases[] = [ // #6: derive repoNamespaces and entityNamespaces |
||
| 180 | [ // $settings |
||
| 181 | ], |
||
| 182 | [ // $wg |
||
| 183 | ], |
||
| 184 | false, // $repoIsLocal |
||
| 185 | [ // $expected |
||
| 186 | 'repoNamespaces' => [ 'item' => '', 'property' => 'Property' ], |
||
| 187 | 'repositories' => [ |
||
| 188 | '' => [ |
||
| 189 | 'entityNamespaces' => [ 'item' => 0, 'property' => 120 ], |
||
| 190 | ], |
||
| 191 | ], |
||
| 192 | ] |
||
| 193 | ]; |
||
| 194 | |||
| 195 | if ( WikibaseSettings::isRepoEnabled() ) { |
||
| 196 | $repoSettings = WikibaseSettings::getRepoSettings(); |
||
| 197 | $entityNamespaces = $repoSettings->getSetting( 'entityNamespaces' ); |
||
| 198 | $namespaceNames = array_map( [ MWNamespace::class, 'getCanonicalName' ], $entityNamespaces ); |
||
| 199 | |||
| 200 | $cases[] = [ // #7: default repoNamespaces and entityNamespaces |
||
| 201 | [], // $settings |
||
| 202 | [], // $wg |
||
| 203 | true, // $repoIsLocal |
||
| 204 | [ // $expected |
||
| 205 | 'repoNamespaces' => $namespaceNames, |
||
| 206 | 'repositories' => [ |
||
| 207 | '' => [ |
||
| 208 | 'entityNamespaces' => $entityNamespaces, |
||
| 209 | ], |
||
| 210 | ], |
||
| 211 | ] |
||
| 212 | ]; |
||
| 213 | } |
||
| 214 | |||
| 215 | return $cases; |
||
| 216 | } |
||
| 217 | |||
| 255 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: