apcal_monthly_calendar.php ➔ apcal_monthly_calendar_show()   B
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 73

Duplication

Lines 7
Ratio 9.59 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 1
dl 7
loc 73
rs 8.589
c 0
b 0
f 0

How to fix   Long Method   

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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright   {@link http://xoops.org/ XOOPS Project}
14
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team,
18
 * @author       GIJ=CHECKMATE (PEAK Corp. http://www.peak.ne.jp/)
19
 */
20
21
if (!defined('APCAL_BLOCK_MONTHLY_CALENDAR_INCLUDED')) {
22
    define('APCAL_BLOCK_MONTHLY_CALENDAR_INCLUDED', 1);
23
24
    /**
25
     * @param $options
26
     * @return mixed
27
     */
28
    function apcal_monthly_calendar_show($options)
29
    {
30
        global $xoopsConfig, $xoopsDB;
31
32
33
        $moduleDirName = empty($options[0]) ? basename(dirname(__DIR__)) : $options[0];
34
        xoops_loadLanguage('main', $moduleDirName);
35
36
        // setting physical & virtual paths
37
        $mod_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName";
38
        $mod_url  = XOOPS_URL . "/modules/$moduleDirName";
39
40
        // defining class of APCal
41
        if (!class_exists('APCal_xoops')) {
42
            require_once "$mod_path/class/APCal.php";
43
            require_once "$mod_path/class/APCal_xoops.php";
44
        }
45
46
        // creating an instance of APCal
47
        $cal = new APCal_xoops('', $xoopsConfig['language'], true);
48
49
        // ignoring cid from GET
50
        $cal->now_cid = 0;
51
52
        // setting properties of APCal
53
        $cal->conn = $GLOBALS['xoopsDB']->conn;
54
        include "$mod_path/include/read_configs.php";
55
        $cal->base_url    = $mod_url;
56
        $cal->base_path   = $mod_path;
57
        $cal->images_url  = "$mod_url/assets/images/$skin_folder";
0 ignored issues
show
Bug introduced by
The variable $skin_folder does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
58
        $cal->images_path = "$mod_path/assets/images/$skin_folder";
59
60
        $original_level = error_reporting(E_ALL ^ E_NOTICE);
61
62
        require_once "$mod_path/include/patTemplate.php";
63
        $tmpl = new PatTemplate();
64
        $tmpl->readTemplatesFromFile("$cal->images_path/default/block_monthly.tmpl.html");
65
66
        // setting skin folder
67
        $tmpl->addVar('WholeBoard', 'SKINPATH', $cal->images_url);
68
69
        // setting language
70
        $tmpl->addVar('WholeBoard', 'LANG_PREV_MONTH', _MB_APCAL_PREV_MONTH);
71
        $tmpl->addVar('WholeBoard', 'LANG_NEXT_MONTH', _MB_APCAL_NEXT_MONTH);
72
        $tmpl->addVar('WholeBoard', 'LANG_YEAR', _MB_APCAL_YEAR);
73
        $tmpl->addVar('WholeBoard', 'LANG_MONTH', _MB_APCAL_MONTH);
74
        $tmpl->addVar('WholeBoard', 'LANG_JUMP', _MB_APCAL_JUMP);
75
76
        // Static parameter for the request
77
        $tmpl->addVar('WholeBoard', 'GET_TARGET', "$mod_url/index.php");
78
        $tmpl->addVar('WholeBoard', 'QUERY_STRING', '');
79
80
        // Variables required in header part etc.
81
        $tmpl->addVars('WholeBoard', $cal->get_calendar_information('M'));
82
83
        // BODY of the calendar
84
        $tmpl->addVar('WholeBoard', 'CALENDAR_BODY', $cal->get_monthly_html("$mod_url/index.php"));
85
86
        // legends of long events
87 View Code Duplication
        foreach ($cal->long_event_legends as $bit => $legend) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
            $tmpl->addVar('LongEventLegends', 'BIT_MASK', 1 << ($bit - 1));
89
            $tmpl->addVar('LongEventLegends', 'LEGEND_ALT', _APCAL_MB_ALLDAY_EVENT . " $bit");
90
            $tmpl->addVar('LongEventLegends', 'LEGEND', $legend);
91
            $tmpl->addVar('LongEventLegends', 'SKINPATH', $cal->images_url);
92
            $tmpl->parseTemplate('LongEventLegends', 'a');
93
        }
94
95
        // content generated from PatTemplate
96
        $block['content'] = $tmpl->getParsedTemplate('WholeBoard');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$block was never initialized. Although not strictly required by PHP, it is generally a good practice to add $block = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
97
        error_reporting($original_level);
98
99
        return $block;
100
    }
101
102
    /**
103
     * @param $options
104
     * @return string
105
     */
106
    function apcal_monthly_calendar_edit($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
    {
108
        return '';
109
    }
110
}
111