| Conditions | 9 |
| Paths | 5 |
| Total Lines | 64 |
| Code Lines | 36 |
| Lines | 22 |
| Ratio | 34.38 % |
| 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 |
||
| 131 | public function getMetadata($projectUrl) |
||
| 132 | { |
||
| 133 | if ($this->metadata) { |
||
| 134 | return $this->metadata; |
||
| 135 | } |
||
| 136 | |||
| 137 | $api = MediawikiApi::newFromPage($projectUrl); |
||
| 138 | |||
| 139 | $params = ['meta' => 'siteinfo', 'siprop' => 'general|namespaces']; |
||
| 140 | $query = new SimpleRequest('query', $params); |
||
| 141 | |||
| 142 | $this->metadata = [ |
||
| 143 | 'general' => [], |
||
| 144 | 'namespaces' => [], |
||
| 145 | ]; |
||
| 146 | |||
| 147 | $res = $api->getRequest($query); |
||
| 148 | |||
| 149 | if (isset($res['query']['general'])) { |
||
| 150 | $info = $res['query']['general']; |
||
| 151 | $this->metadata['general'] = [ |
||
| 152 | 'wikiName' => $info['sitename'], |
||
| 153 | 'wikiId' => $info['wikiid'], |
||
| 154 | 'url' => $info['server'], |
||
| 155 | 'lang' => $info['lang'], |
||
| 156 | 'articlePath' => $info['articlepath'], |
||
| 157 | 'scriptPath' => $info['scriptpath'], |
||
| 158 | 'script' => $info['script'], |
||
| 159 | 'timezone' => $info['timezone'], |
||
| 160 | 'timeOffset' => $info['timeoffset'], |
||
| 161 | ]; |
||
| 162 | |||
| 163 | // if ($this->container->getParameter('app.is_labs') && |
||
|
1 ignored issue
–
show
|
|||
| 164 | // substr($result['general']['dbName'], -2) != '_p' |
||
| 165 | // ) { |
||
| 166 | // $result['general']['dbName'] .= '_p'; |
||
| 167 | // } |
||
| 168 | } |
||
| 169 | |||
| 170 | View Code Duplication | if (isset($res['query']['namespaces'])) { |
|
| 171 | foreach ($res['query']['namespaces'] as $namespace) { |
||
| 172 | if ($namespace['id'] < 0) { |
||
| 173 | continue; |
||
| 174 | } |
||
| 175 | |||
| 176 | if (isset($namespace['name'])) { |
||
| 177 | $name = $namespace['name']; |
||
| 178 | } elseif (isset($namespace['*'])) { |
||
| 179 | $name = $namespace['*']; |
||
| 180 | } else { |
||
| 181 | continue; |
||
| 182 | } |
||
| 183 | |||
| 184 | // FIXME: Figure out a way to i18n-ize this |
||
| 185 | if ($name === '') { |
||
| 186 | $name = 'Article'; |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->metadata['namespaces'][$namespace['id']] = $name; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | return $this->metadata; |
||
| 194 | } |
||
| 195 | } |
||
| 196 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.