bootstrap.php ➔ backendLayoutVars()   D
last analyzed

Complexity

Conditions 12
Paths 160

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
eloc 26
nc 160
nop 0
dl 0
loc 37
rs 4.8484
c 0
b 0
f 0

How to fix   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
 * Licensed under The GPL-3.0 License
4
 * For full copyright and license information, please see the LICENSE.txt
5
 * Redistributions of files must retain the above copyright notice.
6
 *
7
 * @since    2.0.0
8
 * @author   Christopher Castro <[email protected]>
9
 * @link     http://www.quickappscms.org
10
 * @license  http://opensource.org/licenses/gpl-3.0.html GPL-3.0 License
11
 */
12
use Cake\Cache\Cache;
13
use Cake\Core\Configure;
14
use Cake\ORM\TableRegistry;
15
16
/**
17
 * Sets default jQueryUI theme to use.
18
 */
19
Configure::write('jQueryUI.defaultTheme', 'Jquery.flick');
20
21
/**
22
 * Used to count pending comments.
23
 */
24
Cache::config('pending_comments', [
25
    'className' => 'File',
26
    'prefix' => 'backend_theme_',
27
    'path' => CACHE,
28
    'duration' => '+3 minutes',
29
]);
30
31
if (!function_exists('backendLayoutVars')) {
32
    /**
33
     * Prepares some variables used in "default.ctp" layout, such as skin color to use,
34
     * pending comments counter, etc.
35
     *
36
     * @return array Associative array
37
     */
38
    function backendLayoutVars()
39
    {
40
        $layoutOptions = [];
41
        $skin = theme()->settings('skin');
42
        $boxClass = 'success';
43
        $pendingComments = Cache::read('pending_comments', 'pending_comments');
44
45
        if ($pendingComments === false) {
46
            $pendingComments = TableRegistry::get('Comment.Comments')
47
                ->find()->where(['Comments.status' => 'pending', 'Comments.table_alias' => 'contents'])
48
                ->count();
49
            Cache::write('pending_comments', $pendingComments, 'pending_comments');
50
        }
51
        $pendingComments = !$pendingComments ? '' : $pendingComments;
52
53
        if (strpos($skin, 'blue') !== false || strpos($skin, 'black') !== false) {
54
            $boxClass = 'info';
55
        } elseif (strpos($skin, 'green') !== false) {
56
            $boxClass = 'success';
57
        } elseif (strpos($skin, 'red') !== false || strpos($skin, 'purple') !== false) {
58
            $boxClass = 'danger';
59
        } elseif (strpos($skin, 'yellow') !== false) {
60
            $boxClass = 'warning';
61
        }
62
63
        if (theme()->settings('fixed_layout')) {
64
            $layoutOptions[] = 'fixed';
65
        }
66
        if (theme()->settings('boxed_layout')) {
67
            $layoutOptions[] = 'layout-boxed';
68
        }
69
        if (theme()->settings('collapsed_sidebar')) {
70
            $layoutOptions[] = 'sidebar-collapse';
71
        }
72
73
        return compact('skin', 'layoutOptions', 'boxClass', 'pendingComments');
74
    }
75
}
76