Conditions | 16 |
Paths | 288 |
Total Lines | 82 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
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 | } |
||
132 |