Completed
Push — manifest ( 10b4c8...c90718 )
by Michael
03:59
created

Manifest::sendManifest()   D

Complexity

Conditions 14
Paths 192

Size

Total Lines 88
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 14
eloc 58
nc 192
nop 0
dl 0
loc 88
rs 4.6283
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

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