Completed
Push — master ( a28409...20baf9 )
by Michael
01:24
created

block_contact_form_map.php ➔ ContactGetElements()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 68
Code Lines 52

Duplication

Lines 4
Ratio 5.88 %

Importance

Changes 0
Metric Value
cc 3
eloc 52
nc 2
nop 1
dl 4
loc 68
rs 9.2447
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
 * wgSitenotice module for xoops
13
 *
14
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
15
 * @license         GPL 2.0 or later
16
 * @package         wgsitenotice
17
 * @since           1.0
18
 * @min_xoops       2.5.7
19
 * @author          Goffy (wedega.com) - Email:<[email protected]> - Website:<http://wedega.com>
20
 * @param $options
21
 * @return array
22
 */
23
24
// Function show block form only
25
function block_contact_form_show($options)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
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...
26
{
27
    $block = array();
28
    ContactGetElements($block);
29
30
    return $block;
31
}
32
33
// Function show block map
34
/**
35
 * @param $options
36
 * @return array
37
 */
38
function block_contact_map_show($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...
39
{
40
    $block = array();
41
    ContactGetElements($block);
42
43
    return $block;
44
}
45
46
// Function show block form and map
47
/**
48
 * @param $options
49
 * @return array
50
 */
51
function block_contact_form_map_show($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...
52
{
53
    $block = array();
54
    ContactGetElements($block);
55
56
    return $block;
57
}
58
59
/**
60
 * @param $block
61
 */
62
function ContactGetElements(&$block)
63
{
64
    /** @var XoopsModuleHandler $moduleHandler */
65
    $moduleHandler = xoops_getHandler('module');
66
    $xoopsModule   = $moduleHandler->getByDirname('contact');
67
    /** @var XoopsConfigHandler $configHandler */
68
    $configHandler     = xoops_getHandler('config');
69
    $xoopsModuleConfig = $configHandler->getConfigsByCat(0, $xoopsModule->mid());
70
71
    xoops_loadLanguage('main', 'contact');
72
73
    include_once XOOPS_ROOT_PATH . '/modules/contact/class/contact.php';
74
75
    $block['lng_username'] = 'name';
76
77
    /*Modules Options*/
78
    if ($xoopsModuleConfig['form_dept'] == 1) {
79
        // show a drop down with the correct departments listed
80
        $departmentlist = array();
81
        $departments    = xoops_getModuleOption('contact_dept', 'contact');
82 View Code Duplication
        foreach ($departments as $val) {
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...
83
            list($name, $email) = explode(',', $val, 2); //split the name and email
0 ignored issues
show
Unused Code introduced by
The assignment to $email is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
84
            array_push($departmentlist, $name);
85
        }
86
        $block['depart']      = $xoopsModuleConfig['form_dept'];
87
        $block['departments'] = $departmentlist;
88
    }
89
    $block['recaptcha']       = $xoopsModuleConfig['recaptchause'];
90
    $block['recaptchakey']    = $xoopsModuleConfig['recaptchakey'];
91
    $block['url']             = $xoopsModuleConfig['form_url'];
92
    $block['icq']             = $xoopsModuleConfig['form_icq'];
93
    $block['skype']           = $xoopsModuleConfig['form_skype'];
94
    $block['company']         = $xoopsModuleConfig['form_company'];
95
    $block['location']        = $xoopsModuleConfig['form_location'];
96
    $block['phone']           = $xoopsModuleConfig['form_phone'];
97
    $block['address']         = $xoopsModuleConfig['form_address'];
98
    $block['info']            = $xoopsModuleConfig['contact_info'];
99
    $block['contact_default'] = $xoopsModuleConfig['contact_default'];
100
    $block['map']             = $xoopsModuleConfig['embed_maps'];
101
    /*end Modules options*/
102
103
    /* get language vars*/
104
    $block['lng_username']   = _MD_CONTACT_NAME;
105
    $block['lng_email']      = _MD_CONTACT_MAIL;
106
    $block['lng_url']        = _MD_CONTACT_URL;
107
    $block['lng_company']    = _MD_CONTACT_COMPANY;
108
    $block['lng_icq']        = _MD_CONTACT_ICQ_NAME;
109
    $block['lng_address']    = _MD_CONTACT_ADDRESS;
110
    $block['lng_location']   = _MD_CONTACT_LOCATION;
111
    $block['lng_phone']      = _MD_CONTACT_PHONE;
112
    $block['lng_skypename']  = _MD_CONTACT_SKYPE_NAME;
113
    $block['lng_department'] = _MD_CONTACT_DEPARTMENT;
114
    $block['lng_subject']    = _MD_CONTACT_SUBJECT;
115
    $block['lng_message']    = _MD_CONTACT_MESSAGE;
116
    $block['lng_submit']     = _MD_CONTACT_SUBMIT;
117
118
    $block['lng_username_info']  = _MD_CONTACT_NAME_INFO;
119
    $block['lng_email_info']     = _MD_CONTACT_MAIL_INFO;
120
    $block['lng_url_info']       = _MD_CONTACT_URL_INFO;
121
    $block['lng_company_info']   = _MD_CONTACT_COMPANY_INFO;
122
    $block['lng_address_info']   = _MD_CONTACT_ADDRESS_INFO;
123
    $block['lng_location_info']  = _MD_CONTACT_LOCATION_INFO;
124
    $block['lng_phone_info']     = _MD_CONTACT_PHONE_INFO;
125
    $block['lng_icq_info']       = _MD_CONTACT_ICQ_INFO;
126
    $block['lng_skypename_info'] = _MD_CONTACT_SKYPE_NAME_INFO;
127
    $block['lng_subject_info']   = _MD_CONTACT_SUBJECT_INFO;
128
    $block['lng_message_info']   = _MD_CONTACT_MESSAGE_INFO;
129
}
130