Completed
Pull Request — 1.10.x (#1244)
by
unknown
42:26
created

compilatio_ajax.php ➔ giveWorkIdState()   D

Complexity

Conditions 10
Paths 22

Size

Total Lines 98
Code Lines 84

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 10
eloc 84
c 1
b 0
f 0
nc 22
nop 1
dl 0
loc 98
rs 4.8837

How to fix   Long Method    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
    require ('../../inc/global.inc.php');
3
    include('config.php');
4
    include('compilatio.class.php');
5
6
    if (isset($_GET['workid'])) {
7
        $compTable = Database::get_course_table("plagiarism_compilatio_docs");
8
        $workIdList = $_GET['workid'];	// list of workid separate by the :
9
        $result = "";
10
        $tabWorkId =  split("a", $workIdList);
11
        for ($i=0; $i < count($tabWorkId); $i++) {
12
            if (is_numeric($tabWorkId[$i])) {
13
                $result .= giveWorkIdState($tabWorkId[$i]);
14
            }
15
        }
16
        echo $result;
17
    }
18
    /**
19
     * @param $workId
20
     * @return string
21
     */
22
    function giveWorkIdState($workId) {
23
        global $compilatioParameter;
24
        global $compTable;
25
        $compilatio = new compilatio(
26
            $compilatioParameter['key'],
27
            $compilatioParameter['$urlsoap'],
28
            $compilatioParameter['proxy_host'],
29
            $compilatioParameter['proxy_port']
30
        );
31
        $text = "";
32
        $result = "";
33
        $compilatioImgFolder = api_get_path(WEB_CODE_PATH)."plagiarism/compilatio/img/";
34
        $compilatioWebFolder = api_get_path(WEB_CODE_PATH)."plagiarism/compilatio/";
35
        $courseId = api_get_course_int_id();
36
        $compilatioQuery = "SELECT compilatio_id 
37
           FROM $compTable 
38
           where id_doc = $workId 
39
           AND c_id = $courseId";
40
        $compiSqlResult = Database::query($compilatioQuery);
41
        $compi = Database::fetch_object($compiSqlResult);
42
        if (isset($compi->compilatio_id)) {
43
            $actionCompilatio = "";
44
            if(isMd5($compi->compilatio_id)) {
45
                // if compilatio_id is a hash md5, we call the function of the compilatio's webservice who return the document's status
46
47
                $soapRes = $compilatio->getDoc($compi->compilatio_id);
48
                $status = '';
49
                if(isset($soapRes->documentStatus)) {
50
                    $status = $soapRes->documentStatus->status;
51
                }
52
            } else {
53
                // if the compilatio's hash is not a valide hash md5, we return à specific status (cf : IsInCompilatio() )
54
                $status="NOT_IN_COMPILATIO";
55
                $actionCompilatio = "<div style='font-style:italic'>"
56
                    . get_lang('compilatioDocumentTextNotImage')
57
                    . "<br/>"
58
                    . get_lang('compilatioDocumentNotCorrupt')
59
                    . "</div>";
60
            }
61
62
            if ($status == "ANALYSE_COMPLETE") {
63
                $urlRapport = $compilatio->getReportUrl($compi->compilatio_id);
64
                $actionCompilatio .= getPomprankBarv31(
65
                        $soapRes->documentStatus->indice,
66
                        10 ,
67
                        35,
68
                        $compilatioImgFolder,
69
                        $text
70
                    )
71
                    . "<br/><a href='"
72
                    . $urlRapport
73
                    . "' target='_blank'>"
74
                    . get_lang('compilatioSeeReport')
75
                    . "</a>";
76
            } elseif ($status == "ANALYSE_PROCESSING") {
77
                $actionCompilatio .= "<div style='font-weight:bold;text-align:left'>"
78
                    . get_lang('compilatioAnalysisInProgress')
79
                    . "</div>";
80
                $actionCompilatio .= "<div style='font-size:80%;font-style:italic;margin-bottom:5px;'>"
81
                    . get_lang('compilatioAnalysisPercentage')
82
                    . "</div>";
83
                $text['analysisinqueue'] = get_lang('compilatioWaitingAnalysis');
84
                $text['analysisinfinalization'] = get_lang('compilatioAnalysisEnding');
85
                $text['refresh'] = get_lang('Refresh');
86
                $actionCompilatio .= getProgressionAnalyseDocv31(
87
                    $status,
88
                    $soapRes->documentStatus->progression,
89
                    $compilatioImgFolder,
90
                    $text
91
                );
92
            }
93
            elseif ($status == "ANALYSE_IN_QUEUE") {
94
                $actionCompilatio.="<img src='"
95
                    . $compilatioImgFolder
96
                    . "/ajax-loader2.gif' style='margin-right:10px;' />"
97
                    . get_lang('compilatioAwaitingAnalysis');
98
            } elseif ($status == "BAD_FILETYPE") {
99
                $actionCompilatio.= "<div style='font-style:italic'>"
100
                    . get_lang('compilatioFileisnotsupported')
101
                    . "<br/>"
102
                    . get_lang('compilatioProtectedPdfVerification')
103
                    . "</div>";
104
            } elseif ($status == "BAD_FILESIZE") {
105
                $actionCompilatio.=  "<div style='font-style:italic'>"
106
                    . get_lang('compilatioTooHeavyDocument')
107
                    . "</div>";
108
            } elseif ($status != "NOT_IN_COMPILATIO") {
109
                $actionCompilatio.= "<div style='font-style:italic'>"
110
                    . get_lang('compilatioMomentarilyUnavailableResult')
111
                    . " : [ "
112
                    . $status
113
                    . "].</div>";
114
            }
115
        }
116
        $result = $workId . "|" . $actionCompilatio . "|" . $status . "|";
117
118
        return $result;
119
    }
120
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...