| Conditions | 13 |
| Paths | 72 |
| Total Lines | 94 |
| Code Lines | 57 |
| 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 | #!/usr/bin/php |
||
| 66 | public function process($task) |
||
| 67 | { |
||
| 68 | $this->cpeLogger->logOut( |
||
| 69 | "INFO", |
||
| 70 | basename(__FILE__), |
||
| 71 | "Preparing Asset validation ...", |
||
| 72 | $this->logKey |
||
| 73 | ); |
||
| 74 | |||
| 75 | // Call parent process: |
||
| 76 | parent::process($task); |
||
| 77 | |||
| 78 | $this->activityHeartbeat(); |
||
| 79 | $tmpFile = tempnam(sys_get_temp_dir(), 'ct'); |
||
| 80 | |||
| 81 | if (isset($this->input->{'input_asset'}->{'http'})) { |
||
| 82 | $ch = curl_init(); |
||
| 83 | curl_setopt($ch, CURLOPT_URL, $this->input->{'input_asset'}->{'http'}); |
||
| 84 | curl_setopt($ch, CURLOPT_RANGE, '0-1024'); |
||
| 85 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, array($this, 'writefn')); |
||
| 86 | curl_exec($ch); |
||
| 87 | curl_close($ch); |
||
| 88 | $chunk = $this->curl_data; |
||
| 89 | } |
||
| 90 | else if (isset($this->input->{'input_asset'}->{'bucket'}) && |
||
| 91 | isset($this->input->{'input_asset'}->{'file'})) { |
||
| 92 | // Fetch first 1 KiB of the file for Magic number validation |
||
| 93 | $obj = $this->s3->getObject([ |
||
| 94 | 'Bucket' => $this->input->{'input_asset'}->{'bucket'}, |
||
| 95 | 'Key' => $this->input->{'input_asset'}->{'file'}, |
||
| 96 | 'Range' => 'bytes=0-1024' |
||
| 97 | ]); |
||
| 98 | $chunk = (string) $obj['Body']; |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->activityHeartbeat(); |
||
| 102 | |||
| 103 | // Determine file type |
||
| 104 | file_put_contents($tmpFile, $chunk); |
||
| 105 | $mime = trim((new CommandExecuter($this->cpeLogger, $this->logKey))->execute( |
||
| 106 | 'file -b --mime-type '.escapeshellarg($tmpFile))['out']); |
||
| 107 | $type = substr($mime, 0, strpos($mime, '/')); |
||
| 108 | |||
| 109 | if ($this->debug) |
||
| 110 | $this->cpeLogger->logOut( |
||
| 111 | "DEBUG", |
||
| 112 | basename(__FILE__), |
||
| 113 | "File meta information gathered. Mime: $mime | Type: $type", |
||
| 114 | $this->logKey |
||
| 115 | ); |
||
| 116 | |||
| 117 | // Load the right transcoder base on input_type |
||
| 118 | // Get asset detailed info |
||
| 119 | switch ($type) |
||
| 120 | { |
||
| 121 | case 'audio': |
||
| 122 | case 'video': |
||
| 123 | case 'image': |
||
| 124 | default: |
||
| 125 | require_once __DIR__.'/transcoders/VideoTranscoder.php'; |
||
| 126 | |||
| 127 | // Initiate transcoder obj |
||
| 128 | $videoTranscoder = new VideoTranscoder($this, $task); |
||
| 129 | // Get input video information |
||
| 130 | $assetInfo = $videoTranscoder->getAssetInfo($this->inputFilePath); |
||
| 131 | |||
| 132 | // Liberate memory |
||
| 133 | unset($videoTranscoder); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($mime === 'application/octet-stream' && isset($assetInfo->streams)) { |
||
| 137 | // Check all stream types |
||
| 138 | foreach ($assetInfo->streams as $stream) { |
||
| 139 | if ($stream->codec_type === 'video') { |
||
| 140 | // For a video type, set type to video and break |
||
| 141 | $type = 'video'; |
||
| 142 | break; |
||
| 143 | } elseif ($stream->codec_type === 'audio') { |
||
| 144 | // For an audio type, set to audio, but don't break |
||
| 145 | // in case there's a video stream later |
||
| 146 | $type = 'audio'; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | $assetInfo->mime = $mime; |
||
| 152 | $assetInfo->type = $type; |
||
| 153 | |||
| 154 | $result['input_asset'] = $this->input->{'input_asset'}; |
||
| 155 | $result['input_metadata'] = $assetInfo; |
||
| 156 | $result['output_assets'] = $this->input->{'output_assets'}; |
||
| 157 | |||
| 158 | return json_encode($result); |
||
| 159 | } |
||
| 160 | } |
||
| 256 |
This check marks private properties in classes that are never used. Those properties can be removed.