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 |
||
45 | function show_wu($wu) { |
||
46 | page_head(tra("Workunit %1", $wu->id)); |
||
47 | $app = BoincApp::lookup_id($wu->appid); |
||
48 | |||
49 | $x = "<in>".$wu->xml_doc."</in>"; |
||
50 | $xml_doc = simplexml_load_string($x); |
||
51 | |||
52 | start_table(); |
||
53 | row2(tra("name"), $wu->name); |
||
54 | row2(tra("application"), $app->user_friendly_name); |
||
55 | if ($wu->batch) { |
||
56 | row2('batch', |
||
57 | "<a href=submit.php?action=query_batch&batch_id=$wu->batch>$wu->batch</a>" |
||
58 | ); |
||
59 | } |
||
60 | row2(tra("created"), time_str($wu->create_time)); |
||
61 | if (isset($wu->keywords) && $wu->keywords) { |
||
62 | row2(tra("keywords"), keyword_string($wu->keywords)); |
||
63 | } |
||
64 | if ($wu->canonical_resultid) { |
||
65 | row2(tra("canonical result"), |
||
66 | "<a href=result.php?resultid=$wu->canonical_resultid>$wu->canonical_resultid</a>" |
||
67 | ); |
||
68 | row2(tra("granted credit"), format_credit($wu->canonical_credit)); |
||
69 | } |
||
70 | |||
71 | // if app is using adaptive replication and no canonical result yet, |
||
72 | // don't show anything more |
||
73 | // (so that bad guys can't tell if they have an unreplicated job) |
||
74 | |||
75 | $config = get_config(); |
||
76 | if ($app->target_nresults>0 && !$wu->canonical_resultid && !$wu->error_mask && !parse_bool($config, "dont_suppress_pending")) { |
||
77 | row2(tra("Tasks in progress"), tra("suppressed pending completion")); |
||
78 | end_table(); |
||
79 | } else { |
||
80 | row2(tra("minimum quorum"), $wu->min_quorum); |
||
81 | row2(tra("initial replication"), $wu->target_nresults); |
||
82 | row2(tra("max # of error/total/success tasks"), |
||
83 | "$wu->max_error_results, $wu->max_total_results, $wu->max_success_results" |
||
84 | ); |
||
85 | if ($wu->error_mask) { |
||
86 | row2(tra("errors"), wu_error_mask_str($wu->error_mask)); |
||
87 | } |
||
88 | if ($wu->need_validate) { |
||
89 | row2(tra("validation"), tra("Pending")); |
||
90 | } |
||
91 | row2('Command line', $xml_doc->workunit->command_line); |
||
92 | if (function_exists('project_workunit')) { |
||
93 | project_workunit($wu); |
||
94 | } |
||
95 | end_table(); |
||
96 | |||
97 | echo "<h2>Job instances</h2>\n"; |
||
98 | result_table_start(false, true, null); |
||
99 | $results = BoincResult::enum("workunitid=$wu->id"); |
||
100 | foreach ($results as $result) { |
||
101 | show_result_row($result, false, true, false); |
||
102 | } |
||
103 | echo "</table>\n"; |
||
104 | } |
||
105 | |||
106 | // show input files |
||
107 | // |
||
108 | echo "<h2>Input files</h2>\n"; |
||
109 | start_table('table-striped'); |
||
110 | table_header("Name<br><small>(click to view)</small>", "Size (bytes)"); |
||
111 | foreach ($xml_doc->workunit->file_ref as $fr) { |
||
112 | $pname = (string)$fr->file_name; |
||
113 | $lname = (string)$fr->open_name; |
||
114 | foreach ($xml_doc->file_info as $fi) { |
||
115 | if ((string)$fi->name == $pname) { |
||
116 | table_row( |
||
117 | "<a href=$fi->url>$lname</a>", |
||
118 | $fi->nbytes |
||
119 | ); |
||
120 | break; |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | end_table(); |
||
126 | page_tail(); |
||
127 | } |
||
137 |