Conditions | 9 |
Paths | 12 |
Total Lines | 75 |
Code Lines | 42 |
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 |
||
26 | public function do_activity($task) |
||
27 | { |
||
28 | $this->cpeLogger->log_out( |
||
29 | "INFO", |
||
30 | basename(__FILE__), |
||
31 | "Preparing Asset validation ...", |
||
32 | $this->activityLogKey |
||
33 | ); |
||
34 | |||
35 | // Call parent do_activity: |
||
36 | // It download the input file we will process. |
||
37 | parent::do_activity($task); |
||
38 | |||
39 | // Fetch first 1 KiB of file |
||
40 | $this->send_heartbeat($task); |
||
41 | $tmpFile = tempnam(sys_get_temp_dir(), 'ct'); |
||
42 | $obj = $this->s3->getObject([ |
||
43 | 'Bucket' => $this->input->{'input_asset'}->{'bucket'}, |
||
44 | 'Key' => $this->input->{'input_asset'}->{'file'}, |
||
45 | 'Range' => 'bytes=0-1024' |
||
46 | ]); |
||
47 | $this->send_heartbeat($task); |
||
48 | |||
49 | // Determine file type |
||
50 | file_put_contents($tmpFile, (string) $obj['Body']); |
||
51 | $mime = trim((new CommandExecuter($this->cpeLogger))->execute( |
||
52 | 'file -b --mime-type ' . escapeshellarg($tmpFile))['out']); |
||
53 | $type = substr($mime, 0, strpos($mime, '/')); |
||
54 | |||
55 | $this->cpeLogger->log_out( |
||
56 | "DEBUG", |
||
57 | basename(__FILE__), |
||
58 | "File meta information gathered. Mime: $mime | Type: $type", |
||
59 | $this->activityLogKey |
||
60 | ); |
||
61 | |||
62 | // Load the right transcoder base on input_type |
||
63 | // Get asset detailed info |
||
64 | switch ($type) |
||
65 | { |
||
66 | case 'audio': |
||
67 | case 'video': |
||
68 | case 'image': |
||
69 | default: |
||
70 | require_once __DIR__.'/transcoders/VideoTranscoder.php'; |
||
71 | |||
72 | // Initiate transcoder obj |
||
73 | $videoTranscoder = new VideoTranscoder($this, $task); |
||
74 | // Get input video information |
||
75 | $assetInfo = $videoTranscoder->get_asset_info($this->pathToInputFile); |
||
76 | |||
77 | // Liberate memory |
||
78 | unset($videoTranscoder); |
||
79 | } |
||
80 | |||
81 | if ($mime === 'application/octet-stream' && isset($asset['streams'])) { |
||
|
|||
82 | // Check all stream types |
||
83 | foreach ($asset['streams'] as $stream) { |
||
84 | if ($stream['codec_type'] === 'video') { |
||
85 | // For a video type, set type to video and break |
||
86 | $type = 'video'; |
||
87 | break; |
||
88 | } elseif ($stream['codec_type'] === 'audio') { |
||
89 | // For an audio type, set to audio, but don't break |
||
90 | // in case there's a video stream later |
||
91 | $type = 'audio'; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | $assetInfo->mime = $mime; |
||
97 | $assetInfo->type = $type; |
||
98 | |||
99 | return $assetInfo; |
||
100 | } |
||
101 | } |
||
102 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.