| Conditions | 11 |
| Paths | 32 |
| Total Lines | 71 |
| Code Lines | 49 |
| 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 |
||
| 9 | public function run() { |
||
| 10 | $manifest = retrieveConfig('manifest', [$this, 'jsonToArray']); |
||
| 11 | |||
| 12 | global $conf; |
||
| 13 | |||
| 14 | if (empty($manifest['name'])) { |
||
| 15 | $manifest['name'] = $conf['title']; |
||
| 16 | } |
||
| 17 | |||
| 18 | if (empty($manifest['short_name'])) { |
||
| 19 | $manifest['short_name'] = $conf['title']; |
||
| 20 | } |
||
| 21 | |||
| 22 | if (empty($manifest['description'])) { |
||
| 23 | $manifest['description'] = $conf['tagline']; |
||
| 24 | } |
||
| 25 | |||
| 26 | if (empty($manifest['start_url'])) { |
||
| 27 | $manifest['start_url'] = DOKU_REL; |
||
| 28 | } |
||
| 29 | |||
| 30 | if (empty($manifest['icons'])) { |
||
| 31 | $manifest['icons'] = []; |
||
| 32 | $look = [ |
||
| 33 | ':wiki:logo.png', |
||
| 34 | ':logo.png', |
||
| 35 | 'images/logo.png', |
||
| 36 | ':wiki:apple-touch-icon.png', |
||
| 37 | ':apple-touch-icon.png', |
||
| 38 | 'images/apple-touch-icon.png', |
||
| 39 | ':wiki:favicon.svg', |
||
| 40 | ':favicon.svg', |
||
| 41 | 'images/favicon.svg', |
||
| 42 | ':wiki:favicon.ico', |
||
| 43 | ':favicon.ico', |
||
| 44 | 'images/favicon.ico', |
||
| 45 | ':wiki:logo', |
||
| 46 | ]; |
||
| 47 | |||
| 48 | $abs = true; |
||
| 49 | foreach($look as $img) { |
||
| 50 | if($img[0] === ':') { |
||
| 51 | $file = mediaFN($img); |
||
| 52 | $ismedia = true; |
||
| 53 | } else { |
||
| 54 | $file = tpl_incdir().$img; |
||
| 55 | $ismedia = false; |
||
| 56 | } |
||
| 57 | |||
| 58 | if (file_exists($file)) { |
||
| 59 | $imginfo = getimagesize($file); |
||
| 60 | if($ismedia) { |
||
| 61 | $url = ml($img, '', true, '', $abs); |
||
| 62 | } else { |
||
| 63 | $url = tpl_basedir().$img; |
||
| 64 | if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); |
||
| 65 | } |
||
| 66 | $manifest['icons'][] = [ |
||
| 67 | 'src' => $url, |
||
| 68 | 'sizes' => $imginfo[0] . 'x' . $imginfo[1], |
||
| 69 | 'type' => $imginfo['mime'], |
||
| 70 | ]; |
||
| 71 | }; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | trigger_event('MANIFEST_SEND', $manifest); |
||
| 76 | |||
| 77 | header('Content-Type: application/manifest+json'); |
||
| 78 | echo json_encode($manifest); |
||
| 79 | } |
||
| 80 | |||
| 135 |