Passed
Push — release_2_0 ( 03c63b...4774b0 )
by Stefan
06:32
created

Divs   B

Complexity

Total Complexity 44

Size/Duplication

Total Lines 290
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 44
eloc 141
dl 0
loc 290
rs 8.8798
c 2
b 0
f 1

15 Methods

Rating   Name   Duplication   Size   Complexity  
A div_roller() 0 31 5
A emptyImage() 0 9 2
A __construct() 0 2 1
B div_footer() 0 32 7
A div_institution() 0 7 2
A div_guess_os() 0 34 3
B div_otherinstallers() 0 33 6
A div_profiles() 0 7 1
A div_pagetitle() 0 4 1
A div_heading() 0 24 5
A div_silverbullet() 0 7 1
A div_federation() 0 3 1
A div_main_button() 0 21 6
A div_user_welcome() 0 28 2
A div_top_welcome() 0 7 1

How to fix   Complexity   

Complex Class

Complex classes like Divs often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Divs, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * *****************************************************************************
5
 * Contributions to this work were made on behalf of the GÉANT project, a 
6
 * project that has received funding from the European Union’s Framework 
7
 * Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus),
8
 * Horizon 2020 research and innovation programme under Grant Agreements No. 
9
 * 691567 (GN4-1) and No. 731122 (GN4-2).
10
 * On behalf of the aforementioned projects, GEANT Association is the sole owner
11
 * of the copyright in all material which was developed by a member of the GÉANT
12
 * project. GÉANT Vereniging (Association) is registered with the Chamber of 
13
 * Commerce in Amsterdam with registration number 40535155 and operates in the 
14
 * UK as a branch of GÉANT Vereniging.
15
 * 
16
 * Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. 
17
 * UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK
18
 *
19
 * License: see the web/copyright.inc.php file in the file structure or
20
 *          <base_url>/copyright.php after deploying the software
21
 */
22
23
use web\lib\user;
24
25
require("Menu.php");
0 ignored issues
show
Coding Style introduced by
"require" is a statement not a function; no parentheses are required
Loading history...
26
27
/**
28
 * This class delivers various <div> elements for the front page.
29
 * 
30
 * @author Tomasz Wolniewicz <[email protected]>
31
 */
32
class Divs {
33
34
    /**
35
     * The Gui object we are working with.
36
     * 
37
     * @var user\Gui
38
     */
39
    private $Gui;
40
41
    public function __construct(user\Gui $Gui) {
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
42
        $this->Gui = $Gui;
43
    }
44
45
    public function div_heading($visibility = 'all') {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_heading" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
46
        $selectedLang = $this->Gui->langObject->getLang();
47
        $menu = new Menu($visibility, $selectedLang);
48
        $retval = "<div id='heading'>";
49
        $location = $this->Gui->skinObject->findResourceUrl("IMAGES", "consortium_logo.png");
50
        if ($location !== FALSE) {
51
            $retval .= "<div id='cat_logo'>
52
            <a href='" . CONFIG_CONFASSISTANT['CONSORTIUM']['homepage'] . "'><img id='logo_img' src='$location' alt='Consortium Logo'/></a>
53
            <span>Configuration Assistant Tool</span>
54
            </div>";
55
        }
56
        $retval .= "<div id='motd'>" . (isset(CONFIG['APPEARANCE']['MOTD']) ? CONFIG['APPEARANCE']['MOTD'] : '&nbsp') . "</div>";
57
        $loc2 = $this->Gui->skinObject->findResourceUrl("IMAGES", "icons/menu.png");
58
        if ($loc2 !== FALSE) {
59
            $retval .= "<img id='hamburger' src='$loc2' alt='Menu'/>";
60
        }
61
        $retval .= "<div id='menu_top'>";
62
        if ($visibility === 'start') {
63
            $retval .= $menu->printMinimalMenu();
64
        } else {
65
            $retval .= $menu->printMenu();
66
        }
67
        $retval .= "</div></div>\n";
68
        return $retval;
69
    }
70
71
    public function div_user_welcome() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_user_welcome" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
72
        $retval = "
73
<div id='user_welcome'> <!-- this information is shown just before the download -->
74
    <strong>" . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_PAGEHEADING] . "</strong>
75
    <p>
76
    <span id='download_info'>
77
    <!-- the empty href is dynamically exchanged with the actual path by jQuery at runtime -->
78
        " . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_DOWNLOAD] . "
79
    </span>
80
    <p>" . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_HEADING] . "
81
    <br/>
82
    <br/>";
83
        switch (CONFIG_CONFASSISTANT['CONSORTIUM']['name']) {
84
            case "eduroam": $retval .= $this->Gui->textTemplates->templates[user\EDUROAM_WELCOME_ADVERTISING];
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
85
                break;
86
            default:
87
        }
88
        $retval .= "
89
    </p>
90
    <p>" . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_USAGE] . "
91
    <p>" . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_PROBLEMS] . "
92
    </p>
93
    <p>
94
    <a href='javascript:back_to_downloads()'><strong>" . $this->Gui->textTemplates->templates[user\WELCOME_ABOARD_BACKTODOWNLOADS] . "</strong></a>
95
    </p>
96
</div> <!-- id='user_welcomer_page' -->
97
";
98
        return $retval;
99
    }
100
101
    public function div_silverbullet() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_silverbullet" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
102
        $retval = "
103
<div id='silverbullet'>"
104
                . $this->Gui->textTemplates->templates[user\SB_GO_AWAY] .
105
                "</div>
106
    ";
107
        return $retval;
108
    }
109
110
    public function div_top_welcome() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_top_welcome" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
111
        return "
112
<div id='welcome_top1'>
113
    " . $this->Gui->textTemplates->templates[user\HEADING_TOPLEVEL_GREET] . "
114
</div>
115
<div id='top_invite'>
116
    " . $this->Gui->textTemplates->templates[user\HEADING_TOPLEVEL_PURPOSE] . "
117
</div>";
118
    }
119
120
    public function div_roller() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_roller" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
121
        $retval = "
122
<div id='roller'>
123
    <div id='slides'>
124
        <span id='line1'>" . $this->Gui->textTemplates->templates[user\FRONTPAGE_ROLLER_EASY] . "</span>
125
        <span id='line2'></span>
126
        <span id='line3'></span>
127
        <span id='line4'>";
128
129
        if (CONFIG['FUNCTIONALITY_LOCATIONS']['CONFASSISTANT_RADIUS'] == "LOCAL") {
130
            $retval .= $this->Gui->textTemplates->templates[user\FRONTPAGE_ROLLER_CUSTOMBUILT];
131
        } elseif (CONFIG['FUNCTIONALITY_LOCATIONS']['CONFASSISTANT_SILVERBULLET'] == "LOCAL") {
132
            $retval .= $this->Gui->textTemplates->templates[user\SB_FRONTPAGE_ROLLER_CUSTOMBUILT];
133
        }
134
135
        $retval .= "</span>
136
        <span id='line5'>";
137
        if (!empty(CONFIG_CONFASSISTANT['CONSORTIUM']['signer_name'])) {
138
            $retval .= $this->Gui->textTemplates->templates[user\FRONTPAGE_ROLLER_SIGNEDBY];
139
        }
140
        $retval .= "
141
        </span>
142
    </div>";
143
        $rollLocation = $this->Gui->skinObject->findResourceUrl("IMAGES", "empty.png");
144
        if ($rollLocation !== FALSE) {
145
            $retval .= "<div id = 'img_roll'>
146
                <img id='img_roll_0' src='$rollLocation' alt='Rollover 0'/> <img id='img_roll_1' src='$rollLocation' alt='Rollover 1'/>
147
            </div>";
148
        }
149
        $retval .= "</div>";
150
        return $retval;
151
    }
152
153
    public function div_main_button() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_main_button" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
154
        $retval = "<div id='user_button_td'>";
155
        if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { // SW: APPROVED
156
            $retval .= "<span>".$this->Gui->textTemplates->templates[user\FRONTPAGE_EDUROAM_AD]."</span>";
157
        }
158
        $retval .= "<span id='signin'>
159
     <button class='large_button signin signin_large' id='user_button1'>
160
        <span id='user_button'>";
161
        if (CONFIG['FUNCTIONALITY_LOCATIONS']['CONFASSISTANT_RADIUS'] == "LOCAL") {
162
            $retval .= $this->Gui->textTemplates->templates[user\FRONTPAGE_BIGDOWNLOADBUTTON];
163
        } elseif (CONFIG['FUNCTIONALITY_LOCATIONS']['CONFASSISTANT_SILVERBULLET'] == "LOCAL") {
164
            $retval .= $this->Gui->textTemplates->templates[user\SB_FRONTPAGE_BIGDOWNLOADBUTTON];
165
        }
166
167
        $retval .= "
168
        </span>
169
     </button>
170
  </span>
171
  <span style='padding-left:50px'>&nbsp;</span>
172
</div>";
173
        return $retval;
174
    }
175
176
    public function div_profiles() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_profiles" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
177
        return "
178
<div id='profiles'> <!-- this is the profile selection filled during run time -->
179
    <div id='profiles_h' class='sub_h'>" . $this->Gui->textTemplates->templates[user\PROFILE_SELECTION] . "
180
    </div>" .
181
                "<select id='profile_list'></select><div id='profile_desc' class='profile_desc'></div>" .
182
                "</div>";
183
    }
184
185
    public function div_pagetitle($mainText, $extraText = '') {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_pagetitle" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
186
        return "
187
<div id='institution_name'>
188
    <span id='inst_name_span'>$mainText</span> <div id='inst_extra_text'>$extraText</div> 
189
</div>";
190
    }
191
192
    public function div_institution($selectButton = TRUE) {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_institution" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
193
        $retval = "<div id='institution_name'>
194
    <span id='inst_name_span'></span> <div id='inst_extra_text'></div><!-- this will be filled with the IdP name -->" .
195
                ($selectButton ? "<a  id='select_another' class='signin' href=\"\">" . $this->Gui->textTemplates->templates[user\INSTITUTION_SELECTION] . "</a>" : "") .
196
                "</div>";
197
        $retval .= $this->emptyImage('idp_logo', 'IdP Logo');
198
        return $retval;
199
    }
200
201
    public function div_federation() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_federation" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
202
        $retval = $this->emptyImage('fed_logo', 'Federation Logo');
203
        return $retval;
204
    }
205
206
    public function div_otherinstallers() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_otherinstallers" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
207
        $retval = "
208
<div class='sub_h'>
209
    <div id='other_installers'>" . $this->Gui->textTemplates->templates[user\DOWNLOAD_CHOOSE] . "
210
         <table id='device_list' style='padding:0px;'>";
211
212
        foreach ($this->Gui->listDevices(isset($_REQUEST['hidden']) ? $_REQUEST['hidden'] : 0) as $group => $deviceGroup) {
213
            $groupIndex = count($deviceGroup);
214
            $deviceIndex = 0;
215
216
            $imgTag = "";
217
            $imgLocation = $this->Gui->skinObject->findResourceUrl("IMAGES", "vendorlogo/" . $group . ".png");
218
            if ($imgLocation !== FALSE) {
219
                $imgTag = '<img src="' . $imgLocation . '" alt="' . $group . ' Device" title="' . $group . ' Device">';
220
            }
221
            $retval .= '<tbody><tr><td class="vendor" rowspan="' . $groupIndex . '">' . $imgTag . '</td>';
222
            foreach ($deviceGroup as $d => $D) {
223
                if ($deviceIndex) {
224
                    $retval .= '<tr>';
225
                }
226
                $retval .= "<td><button id='" . $d . "'>" . $D['display'] . "</button>"
227
                        . "<div class='device_info' id='info_" . $d . "'></div></td>"
228
                        . "<td><button class='more_info_b' id='info_b_" . $d . "'>i</button></td></tr>\n";
229
                $deviceIndex++;
230
            }
231
            $retval .= "</tbody>";
232
        }
233
234
        $retval .= "    
235
        </table>
236
    </div>
237
</div>";
238
        return $retval;
239
    }
240
241
    public function div_guess_os($operatingSystem) {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_guess_os" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
242
        $vendorlogo = $this->Gui->skinObject->findResourceUrl("IMAGES", "vendorlogo/" . $operatingSystem['group'] . ".png");
243
        $vendorstyle = "";
244
        if ($vendorlogo !== FALSE) {
245
            $vendorstyle = "style='background-image:url(\"" . $vendorlogo . "\")'";
246
        }
247
        $deleteIcon = $this->Gui->skinObject->findResourceUrl("IMAGES", "icons/delete_32.png");
248
        $deleteImg = "";
249
        if ($deleteIcon !== FALSE) {
250
            $deleteImg = "<img id='cross_icon_" . $operatingSystem['device'] . "' src='$deleteIcon' >";
251
        }
252
        return "
253
<div class='sub_h' id='guess_os'>
254
    <!-- table browser -->
255
    <table id='browser'>
256
        <tr>
257
            <td>
258
                <button class='large_button guess_os' $vendorstyle id='g_" . $operatingSystem['device'] . "'>
259
                    $deleteImg
260
                    <div class='download_button_text_1' id='download_button_header_" . $operatingSystem['device'] . "'> " . $this->Gui->textTemplates->templates[user\DOWNLOAD_MESSAGE] . "
261
                    </div>
262
                    <div class='download_button_text'>" .
263
                $operatingSystem['display'] . "
264
                    </div>
265
                </button>
266
                <div class='device_info' id='info_g_" . $operatingSystem['device'] . "'></div>
267
          </td>
268
          <td style='vertical-align:top'>
269
               <button class='more_info_b large_button' id='g_info_b_" . $operatingSystem['device'] . "'>i</button>
270
          </td>
271
      </tr>
272
    </table> <!-- id='browser' -->
273
    <div class='sub_h'>
274
       <a href='javascript:other_installers()'>" . $this->Gui->textTemplates->templates[user\DOWNLOAD_CHOOSE] . "</a>
275
    </div>
276
</div> <!-- id='guess_os' -->";
277
    }
278
279
    public function div_footer() {
0 ignored issues
show
Coding Style introduced by
Method name "Divs::div_footer" is not in camel caps format
Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
280
        $retval = "
281
<div class='footer' id='footer'>
282
    <table>
283
        <tr>
284
            <td>" .
285
                $this->Gui->CAT_COPYRIGHT
286
                . "
287
            </td>";
288
289
        if (!empty(CONFIG['APPEARANCE']['privacy_notice_url'])) {
290
            $retval .= "<td><a href='" . CONFIG['APPEARANCE']['privacy_notice_url'] . "'>" . sprintf(_("%s Privacy Notice"), CONFIG_CONFASSISTANT['CONSORTIUM']['display_name']) . "</a></td>";
291
        }
292
        $retval .= "<td>";
293
        if (CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") {
294
            $geant = $this->Gui->skinObject->findResourceUrl("IMAGES", "dante.png");
295
            $eu = $this->Gui->skinObject->findResourceUrl("IMAGES", "eu.png");
296
            if ($geant !== FALSE && $eu !== FALSE) {
297
                $retval .= "<span id='logos'><img src='$geant' alt='GEANT' style='height:23px;width:47px'/>
298
              <img src='$eu' alt='EU' style='height:23px;width:27px;border-width:0px;'/></span>";
299
            }
300
            $retval .= "<span id='eu_text' style='text-align:right; padding-left: 60px; display: block; '><a href='http://ec.europa.eu/dgs/connect/index_en.htm' style='text-decoration:none; vertical-align:top; text-align:right'>European Commission Communications Networks, Content and Technology</a></span>";
301
        } else {
302
            $retval .= "&nbsp;";
303
        }
304
305
        $retval .= "
306
            </td>
307
        </tr>
308
    </table>
309
</div>";
310
        return $retval;
311
    }
312
313
    private function emptyImage($id, $alt) {
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
314
        $empty = $this->Gui->skinObject->findResourceUrl("IMAGES", "empty.png");
315
        $retval = '';
316
        if ($empty !== FALSE) {
317
            $retval = "<div>
318
    <img id='$id' src='$empty' alt='$alt'/>
319
 </div>";
320
        }
321
        return $retval;
322
    }
323
324
}
325