| Conditions | 14 |
| Paths | 192 |
| Total Lines | 85 |
| Code Lines | 57 |
| 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 | $manifest['scope'] = DOKU_REL; |
||
| 15 | |||
| 16 | if (empty($manifest['name'])) { |
||
| 17 | $manifest['name'] = $conf['title']; |
||
| 18 | } |
||
| 19 | |||
| 20 | if (empty($manifest['short_name'])) { |
||
| 21 | $manifest['short_name'] = $conf['title']; |
||
| 22 | } |
||
| 23 | |||
| 24 | if (empty($manifest['description'])) { |
||
| 25 | $manifest['description'] = $conf['tagline']; |
||
| 26 | } |
||
| 27 | |||
| 28 | if (empty($manifest['start_url'])) { |
||
| 29 | $manifest['start_url'] = DOKU_REL; |
||
| 30 | } |
||
| 31 | |||
| 32 | $styleUtil = new \dokuwiki\StyleUtils(); |
||
| 33 | $styleIni = $styleUtil->cssStyleini($conf['template']); |
||
| 34 | $replacements = $styleIni['replacements']; |
||
| 35 | |||
| 36 | if (empty($manifest['background_color'])) { |
||
| 37 | $manifest['background_color'] = $replacements['__background__']; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (empty($manifest['theme_color'])) { |
||
| 41 | $manifest['theme_color'] = !empty($replacements['__theme_color__']) ? $replacements['__theme_color__'] : $replacements['__background_alt__']; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (empty($manifest['icons'])) { |
||
| 45 | $manifest['icons'] = []; |
||
| 46 | $look = [ |
||
| 47 | ':wiki:logo.png', |
||
| 48 | ':logo.png', |
||
| 49 | 'images/logo.png', |
||
| 50 | ':wiki:apple-touch-icon.png', |
||
| 51 | ':apple-touch-icon.png', |
||
| 52 | 'images/apple-touch-icon.png', |
||
| 53 | ':wiki:favicon.svg', |
||
| 54 | ':favicon.svg', |
||
| 55 | 'images/favicon.svg', |
||
| 56 | ':wiki:favicon.ico', |
||
| 57 | ':favicon.ico', |
||
| 58 | 'images/favicon.ico', |
||
| 59 | ':wiki:logo', |
||
| 60 | ]; |
||
| 61 | |||
| 62 | $abs = true; |
||
| 63 | foreach($look as $img) { |
||
| 64 | if($img[0] === ':') { |
||
| 65 | $file = mediaFN($img); |
||
| 66 | $ismedia = true; |
||
| 67 | } else { |
||
| 68 | $file = tpl_incdir().$img; |
||
| 69 | $ismedia = false; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (file_exists($file)) { |
||
| 73 | $imginfo = getimagesize($file); |
||
| 74 | if($ismedia) { |
||
| 75 | $url = ml($img, '', true, '', $abs); |
||
| 76 | } else { |
||
| 77 | $url = tpl_basedir().$img; |
||
| 78 | if($abs) $url = DOKU_URL.substr($url, strlen(DOKU_REL)); |
||
| 79 | } |
||
| 80 | $manifest['icons'][] = [ |
||
| 81 | 'src' => $url, |
||
| 82 | 'sizes' => $imginfo[0] . 'x' . $imginfo[1], |
||
| 83 | 'type' => $imginfo['mime'], |
||
| 84 | ]; |
||
| 85 | }; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | trigger_event('MANIFEST_SEND', $manifest); |
||
| 90 | |||
| 91 | header('Content-Type: application/manifest+json'); |
||
| 92 | echo json_encode($manifest); |
||
| 93 | } |
||
| 94 | |||
| 149 |