Passed
Push — master ( 4791a8...56927d )
by Julito
09:52
created

save_item()   F

Complexity

Conditions 130

Size

Total Lines 506
Code Lines 251

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 130
eloc 251
nop 18
dl 0
loc 506
rs 3.3333
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

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:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * This script contains the server part of the AJAX interaction process.
7
 * The client part is located * in lp_api.php or other api's.
8
 *
9
 * @author Yannick Warnier <[email protected]>
10
 */
11
12
// Flag to allow for anonymous user - needs to be set before global.inc.php.
13
$use_anonymous = true;
14
require_once __DIR__.'/../inc/global.inc.php';
15
16
api_protect_course_script();
17
18
$interactions = [];
19
if (isset($_REQUEST['interact'])) {
20
    if (is_array($_REQUEST['interact'])) {
21
        foreach ($_REQUEST['interact'] as $idx => $interac) {
22
            $interactions[$idx] = preg_split('/,/', substr($interac, 1, -1));
23
            if (!isset($interactions[$idx][7])) { // Make sure there are 7 elements.
24
                $interactions[$idx][7] = '';
25
            }
26
        }
27
    }
28
}
29
30
echo ScormApi::saveItem(
31
    (!empty($_REQUEST['lid']) ? $_REQUEST['lid'] : null),
32
    (!empty($_REQUEST['uid']) ? $_REQUEST['uid'] : null),
33
    (!empty($_REQUEST['vid']) ? $_REQUEST['vid'] : null),
34
    (!empty($_REQUEST['iid']) ? $_REQUEST['iid'] : null),
35
    (!empty($_REQUEST['s']) ? $_REQUEST['s'] : null),
36
    (!empty($_REQUEST['max']) ? $_REQUEST['max'] : null),
37
    (!empty($_REQUEST['min']) ? $_REQUEST['min'] : null),
38
    (!empty($_REQUEST['status']) ? $_REQUEST['status'] : null),
39
    (!empty($_REQUEST['t']) ? $_REQUEST['t'] : null),
40
    (!empty($_REQUEST['suspend']) ? $_REQUEST['suspend'] : null),
41
    (!empty($_REQUEST['loc']) ? $_REQUEST['loc'] : null),
42
    $interactions,
43
    (!empty($_REQUEST['core_exit']) ? $_REQUEST['core_exit'] : ''),
44
    (!empty($_REQUEST['session_id']) ? $_REQUEST['session_id'] : ''),
45
    (!empty($_REQUEST['course_id']) ? $_REQUEST['course_id'] : ''),
46
    (empty($_REQUEST['finish']) ? 0 : 1),
47
    (empty($_REQUEST['userNavigatesAway']) ? 0 : 1),
48
    (empty($_REQUEST['statusSignalReceived']) ? 0 : 1),
49
    $_REQUEST['switch_next'] ?? 0
50
);
51