Conditions | 6 |
Paths | 14 |
Total Lines | 55 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
30 | } |
||
31 | |||
32 | function handle_submit($r, $user, $app) { |
||
33 | global $app_name,$log; |
||
34 | |||
35 | $timestamp = date("Y-m-d H:i",time()); |
||
36 | // read the list of template filenames |
||
37 | // |
||
38 | $files = file("../../tree_threader_template_files"); |
||
39 | if ($files === false) { |
||
40 | fwrite($log,"$timestamp\ttemplate file tree_threader_template_files\n"); |
||
41 | error("no templates file"); |
||
42 | |||
43 | } |
||
44 | $njobs = sizeof($files); |
||
45 | $now = time(); |
||
46 | $batch_id = BoincBatch::insert( |
||
47 | "(user_id, create_time, njobs, name, app_id, state) values ($user->id, $now, $njobs, 'tree_threader batch', $app->id, ".BATCH_STATE_IN_PROGRESS.")" |
||
48 | ); |
||
49 | if (!$batch_id) { |
||
50 | $log_msg = "$timestamp\tfailed to create batch for user $user->id\n"; |
||
51 | fwrite($log, $log_msg); |
||
52 | die("couldn't create batch\n"); |
||
53 | } else { |
||
54 | $log_msg = "$timestamp\tcreated batch $batch_id for user $user->id\n"; |
||
55 | fwrite($log, $log_msg); |
||
56 | } |
||
57 | |||
58 | // move the sequence file to the download hier |
||
59 | // |
||
60 | $config = simplexml_load_string(file_get_contents("../../config.xml")); |
||
61 | $fanout = (int)$config->config->uldl_dir_fanout; |
||
62 | $download_dir = trim((string)$config->config->download_dir); |
||
63 | |||
64 | $seq_fname = "treeThreader_sequence_$batch_id.tar.gz"; |
||
65 | $seq_path = dir_hier_path($seq_fname, $download_dir, $fanout); |
||
66 | $tmp_name = $_FILES['seq_file']['tmp_name']; |
||
67 | $ret = rename($tmp_name, $seq_path); |
||
68 | if ($ret === false) { |
||
69 | error("couldn't rename sequence file"); |
||
70 | } |
||
71 | |||
72 | $i = 1; |
||
73 | foreach ($files as $file) { |
||
74 | $file = trim($file); |
||
75 | $wu_name = "ICT_".$batch_id."_$i"; |
||
76 | |||
77 | $cmd = "cd ../..; ./bin/create_work --appname $app_name --batch $batch_id --wu_name $wu_name --wu_template templates/ICT_in --result_template templates/ICT_out $seq_fname $file"; |
||
78 | fwrite($log, "$timestamp\t$cmd\n"); |
||
79 | system($cmd, $ret); |
||
80 | if ($ret != 0) { |
||
81 | fwrite($log, "can not creat job $wu_name\n"); |
||
82 | error("can't create job"); |
||
83 | } |
||
84 | $i++; |
||
85 | } |
||
192 |