Conditions | 10 |
Paths | 22 |
Total Lines | 98 |
Code Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | ?> |
||
|
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.