Conditions | 4 |
Paths | 4 |
Total Lines | 59 |
Code Lines | 35 |
Lines | 0 |
Ratio | 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 |
||
25 | public function do_activity($task) |
||
26 | { |
||
27 | $this->cpeLogger->log_out( |
||
28 | "INFO", |
||
29 | basename(__FILE__), |
||
30 | "Preparing Asset validation ...", |
||
31 | $this->activityLogKey |
||
32 | ); |
||
33 | |||
34 | // Call parent do_activity: |
||
35 | // It download the input file we will process. |
||
36 | parent::do_activity($task); |
||
37 | |||
38 | // Fetch first 1 KiB of file |
||
39 | $this->send_heartbeat($task); |
||
40 | $obj = $this->s3->getObject([ |
||
41 | 'Bucket' => $this->input->{'input_asset'}->{'bucket'}, |
||
42 | 'Key' => $this->input->{'input_asset'}->{'file'}, |
||
43 | 'Range' => '0-10240' |
||
44 | ]); |
||
45 | $this->send_heartbeat($task); |
||
46 | |||
47 | // Determine file type |
||
48 | $tmpFile = tempnam(sys_get_temp_dir(), 'ct'); |
||
49 | file_put_contents($tmpFile, $obj['Body']); |
||
50 | $mime = trim((new CommandExecuter($this->cpeLogger))->execute( |
||
51 | 'file -b --mime-type ' . escapeshellarg($tmpFile))['out']); |
||
52 | $type = substr($mime, 0, strpos($mime, '/')); |
||
53 | |||
54 | $this->cpeLogger->log_out( |
||
55 | "DEBUG", |
||
56 | basename(__FILE__), |
||
57 | "File meta information gathered. Mime: $mime | Type: $type", |
||
58 | $this->activityLogKey |
||
59 | ); |
||
60 | |||
61 | // Load the right transcoder base on input_type |
||
62 | // Get asset detailed info |
||
63 | switch ($type) |
||
64 | { |
||
65 | case 'audio': |
||
66 | case 'video': |
||
67 | case 'image': |
||
68 | default: |
||
69 | require_once __DIR__.'/transcoders/VideoTranscoder.php'; |
||
70 | |||
71 | // Initiate transcoder obj |
||
72 | $videoTranscoder = new VideoTranscoder($this, $task); |
||
73 | // Get input video information |
||
74 | $assetInfo = $videoTranscoder->get_asset_info($this->pathToInputFile); |
||
75 | $assetInfo->mime = $mime; |
||
76 | $assetInfo->type = $type; |
||
77 | |||
78 | // Liberate memory |
||
79 | unset($videoTranscoder); |
||
80 | |||
81 | return $assetInfo; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 |