Completed
Push — manifest ( ac6cee...f3d2b6 )
by Michael
04:15
created

Manifest::sendManifest()   F

Complexity

Conditions 12
Paths 672

Size

Total Lines 73
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 12
eloc 42
nc 672
nop 0
dl 0
loc 73
rs 2.7397
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
            if (file_exists(mediaFN(':wiki:favicon.ico'))) {
46
                $url = ml(':wiki:favicon.ico', '', true, '', true);
47
                $manifest['icons'][] = [
48
                    'src' => $url,
49
                    'sizes' => '16x16',
50
                ];
51
            }
52
53
            $look = [
54
                ':wiki:logo.svg',
55
                ':logo.svg',
56
                ':wiki:dokuwiki.svg'
57
            ];
58
59
            foreach ($look as $svgLogo) {
60
61
                $svgLogoFN = mediaFN($svgLogo);
62
63
                if (file_exists($svgLogoFN)) {
64
                    $url = ml($svgLogo, '', true, '', true);
65
                    $manifest['icons'][] = [
66
                        'src' => $url,
67
                        'sizes' => '17x17 512x512',
68
                        'type' => 'image/svg+xml',
69
                    ];
70
                    break;
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
}
81