show_wu()   F
last analyzed

Complexity

Conditions 16
Paths 288

Size

Total Lines 82
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 16
eloc 54
c 1
b 0
f 1
nc 288
nop 1
dl 0
loc 82
rs 3.6333

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
// This file is part of BOINC.
3
// http://boinc.berkeley.edu
4
// Copyright (C) 2008 University of California
5
//
6
// BOINC is free software; you can redistribute it and/or modify it
7
// under the terms of the GNU Lesser General Public License
8
// as published by the Free Software Foundation,
9
// either version 3 of the License, or (at your option) any later version.
10
//
11
// BOINC is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
// See the GNU Lesser General Public License for more details.
15
//
16
// You should have received a copy of the GNU Lesser General Public License
17
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
18
19
// show summary of a workunit
20
21
require_once("../inc/util.inc");
22
require_once("../inc/boinc_db.inc");
23
require_once("../inc/result.inc");
24
require_once("../inc/keywords.inc");
25
26
check_get_args(array("wuid"));
27
28
function keyword_string($kwds) {
29
    global $job_keywords;
30
31
    $ks = explode(" ", $kwds);
32
    $first = true;
33
    $x = [];
34
    foreach ($ks as $k) {
35
        $x[] = $job_keywords[$k]->name;
36
    }
37
    return implode('<br>', $x);
38
}
39
40
function show_wu($wu) {
41
    page_head(tra("Workunit %1", $wu->id));
42
    $app = BoincApp::lookup_id($wu->appid);
43
44
    $x = "<in>".$wu->xml_doc."</in>";
45
    $xml_doc = simplexml_load_string($x);
46
47
    start_table();
48
    row2(tra("name"), $wu->name);
49
    row2(tra("application"), $app->user_friendly_name);
50
    if ($wu->batch) {
51
        row2('batch',
52
            "<a href=submit.php?action=query_batch&batch_id=$wu->batch>$wu->batch</a>"
53
        );
54
    }
55
    row2(tra("created"), time_str($wu->create_time));
56
    if (isset($wu->keywords) && $wu->keywords) {
57
        row2(tra("keywords"), keyword_string($wu->keywords));
58
    }
59
    if ($wu->canonical_resultid) {
60
        row2(tra("canonical result"),
61
            "<a href=result.php?resultid=$wu->canonical_resultid>$wu->canonical_resultid</a>"
62
        );
63
        row2(tra("granted credit"), format_credit($wu->canonical_credit));
64
    }
65
66
    // if app is using adaptive replication and no canonical result yet,
67
    // don't show anything more
68
    // (so that bad guys can't tell if they have an unreplicated job)
69
70
    $config = get_config();
71
    if ($app->target_nresults>0 && !$wu->canonical_resultid && !$wu->error_mask && !parse_bool($config, "dont_suppress_pending")) {
72
        row2(tra("Tasks in progress"), tra("suppressed pending completion"));
73
        end_table();
74
    } else {
75
        row2(tra("minimum quorum"), $wu->min_quorum);
76
        row2(tra("initial replication"), $wu->target_nresults);
77
        row2(tra("max # of error/total/success tasks"),
78
            "$wu->max_error_results, $wu->max_total_results, $wu->max_success_results"
79
        );
80
        if ($wu->error_mask) {
81
            row2(tra("errors"), wu_error_mask_str($wu->error_mask));
82
        }
83
        if ($wu->need_validate) {
84
            row2(tra("validation"), tra("Pending"));
85
        }
86
        row2('Command line', $xml_doc->workunit->command_line);
87
        if (function_exists('project_workunit')) {
88
            project_workunit($wu);
89
        }
90
        end_table();
91
92
        echo "<h2>Job instances</h2>\n";
93
        result_table_start(false, true, null);
94
        $results = BoincResult::enum("workunitid=$wu->id");
95
        foreach ($results as $result) {
96
            show_result_row($result, false, true, false);
97
        }
98
        echo "</table>\n";
99
    }
100
101
    // show input files
102
    //
103
    echo "<h2>Input files</h2>\n";
104
    start_table('table-striped');
105
    table_header("Name<br><small>(click to view)</small>", "Size (bytes)");
106
    foreach ($xml_doc->workunit->file_ref as $fr) {
107
        $pname = (string)$fr->file_name;
108
        $lname = (string)$fr->open_name;
109
        foreach ($xml_doc->file_info as $fi) {
110
            if ((string)$fi->name == $pname) {
111
                table_row(
112
                    "<a href=$fi->url>$lname</a>",
113
                    $fi->nbytes
114
                );
115
                break;
116
            }
117
        }
118
    }
119
120
    end_table();
121
    page_tail();
122
}
123
124
$wuid = get_int("wuid");
125
$wu = BoincWorkunit::lookup_id($wuid);
126
if (!$wu) {
127
    error_page(tra("can't find workunit"));
128
}
129
show_wu($wu);
130
131
?>
132