Passed
Push — develop ( 4d94d6...18f1e0 )
by Andrew
07:22 queued 04:25
created
src/Transcoder.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         Event::on(
62 62
             CraftVariable::class,
63 63
             CraftVariable::EVENT_INIT,
64
-            function (Event $event) {
64
+            function(Event $event) {
65 65
                 /** @var CraftVariable $variable */
66 66
                 $variable = $event->sender;
67 67
                 $variable->set('transcoder', TranscoderVariable::class);
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         Event::on(
73 73
             Assets::class,
74 74
             Assets::EVENT_GET_THUMB_PATH,
75
-            function (AssetThumbEvent $event) {
75
+            function(AssetThumbEvent $event) {
76 76
                 Craft::debug(
77 77
                     'Assets::EVENT_GET_THUMB_PATH',
78 78
                     __METHOD__
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
         Event::on(
95 95
             ClearCaches::class,
96 96
             ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
97
-            function (RegisterCacheOptionsEvent $event) {
98
-                $event->options[] = [
97
+            function(RegisterCacheOptionsEvent $event) {
98
+                $event->options[ ] = [
99 99
                     'key' => 'transcoder',
100 100
                     'label' => Craft::t('transcoder', 'Transcoder caches'),
101
-                    'action' => Transcoder::$plugin->getSettings()->transcoderPaths['default'],
101
+                    'action' => Transcoder::$plugin->getSettings()->transcoderPaths[ 'default' ],
102 102
                 ];
103 103
             }
104 104
         );
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
             Craft::t(
108 108
                 'transcoder',
109 109
                 '{name} plugin loaded',
110
-                ['name' => $this->name]
110
+                [ 'name' => $this->name ]
111 111
             ),
112 112
             __METHOD__
113 113
         );
Please login to merge, or discard this patch.
src/controllers/DefaultController.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
     public function actionDownloadFile($url)
50 50
     {
51 51
         $filePath = parse_url($url, PHP_URL_PATH);
52
-        $filePath = $_SERVER['DOCUMENT_ROOT'].$filePath;
52
+        $filePath = $_SERVER[ 'DOCUMENT_ROOT' ] . $filePath;
53 53
         Craft::$app->getResponse()->sendFile(
54 54
             $filePath,
55 55
             null,
56
-            ['inline' => false]
56
+            [ 'inline' => false ]
57 57
         );
58 58
         Craft::$app->end();
59 59
     }
@@ -72,24 +72,24 @@  discard block
 block discarded – undo
72 72
      */
73 73
     public function actionProgress($filename)
74 74
     {
75
-        $result = [];
76
-        $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename.'.progress';
75
+        $result = [ ];
76
+        $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $filename . '.progress';
77 77
         if (file_exists($progressFile)) {
78 78
             $content = @file_get_contents($progressFile);
79 79
             if ($content) {
80 80
                 // get duration of source
81 81
                 preg_match('/Duration: (.*?), start:/', $content, $matches);
82 82
                 if (\count($matches) > 0) {
83
-                    $rawDuration = $matches[1];
83
+                    $rawDuration = $matches[ 1 ];
84 84
 
85 85
                     // rawDuration is in 00:00:00.00 format. This converts it to seconds.
86 86
                     $ar = array_reverse(explode(':', $rawDuration));
87
-                    $duration = (float)$ar[0];
88
-                    if (!empty($ar[1])) {
89
-                        $duration += (int)$ar[1] * 60;
87
+                    $duration = (float) $ar[ 0 ];
88
+                    if (!empty($ar[ 1 ])) {
89
+                        $duration += (int) $ar[ 1 ] * 60;
90 90
                     }
91
-                    if (!empty($ar[2])) {
92
-                        $duration += (int)$ar[2] * 60 * 60;
91
+                    if (!empty($ar[ 2 ])) {
92
+                        $duration += (int) $ar[ 2 ] * 60 * 60;
93 93
                     }
94 94
                 } else {
95 95
                     $duration = 'unknown'; // with GIF as input, duration is unknown
@@ -106,12 +106,12 @@  discard block
 block discarded – undo
106 106
 
107 107
                 //rawTime is in 00:00:00.00 format. This converts it to seconds.
108 108
                 $ar = array_reverse(explode(':', $rawTime));
109
-                $time = (float)$ar[0];
110
-                if (!empty($ar[1])) {
111
-                    $time += (int)$ar[1] * 60;
109
+                $time = (float) $ar[ 0 ];
110
+                if (!empty($ar[ 1 ])) {
111
+                    $time += (int) $ar[ 1 ] * 60;
112 112
                 }
113
-                if (!empty($ar[2])) {
114
-                    $time += (int)$ar[2] * 60 * 60;
113
+                if (!empty($ar[ 2 ])) {
114
+                    $time += (int) $ar[ 2 ] * 60 * 60;
115 115
                 }
116 116
 
117 117
                 //calculate the progress
Please login to merge, or discard this patch.
src/services/Transcode.php 1 patch
Spacing   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -96,31 +96,31 @@  discard block
 block discarded – undo
96 96
         $filePath = $this->getAssetPath($filePath);
97 97
 
98 98
         if (!empty($filePath)) {
99
-            $destVideoPath = Craft::getAlias($settings['transcoderPaths']['video']);
99
+            $destVideoPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'video' ]);
100 100
             $videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions);
101 101
 
102 102
             // Get the video encoder presets to use
103
-            $videoEncoders = $settings['videoEncoders'];
104
-            $thisEncoder = $videoEncoders[$videoOptions['videoEncoder']];
103
+            $videoEncoders = $settings[ 'videoEncoders' ];
104
+            $thisEncoder = $videoEncoders[ $videoOptions[ 'videoEncoder' ] ];
105 105
 
106
-            $videoOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
106
+            $videoOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
107 107
 
108 108
             // Build the basic command for ffmpeg
109
-            $ffmpegCmd = $settings['ffmpegPath']
110
-                .' -i '.escapeshellarg($filePath)
111
-                .' -vcodec '.$thisEncoder['videoCodec']
112
-                .' '.$thisEncoder['videoCodecOptions']
109
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
110
+                .' -i ' . escapeshellarg($filePath)
111
+                .' -vcodec ' . $thisEncoder[ 'videoCodec' ]
112
+                .' ' . $thisEncoder[ 'videoCodecOptions' ]
113 113
                 .' -bufsize 1000k'
114 114
                 .' -threads 0';
115 115
 
116 116
             // Set the framerate if desired
117
-            if (!empty($videoOptions['videoFrameRate'])) {
118
-                $ffmpegCmd .= ' -r '.$videoOptions['videoFrameRate'];
117
+            if (!empty($videoOptions[ 'videoFrameRate' ])) {
118
+                $ffmpegCmd .= ' -r ' . $videoOptions[ 'videoFrameRate' ];
119 119
             }
120 120
 
121 121
             // Set the bitrate if desired
122
-            if (!empty($videoOptions['videoBitRate'])) {
123
-                $ffmpegCmd .= ' -b:v '.$videoOptions['videoBitRate'].' -maxrate '.$videoOptions['videoBitRate'];
122
+            if (!empty($videoOptions[ 'videoBitRate' ])) {
123
+                $ffmpegCmd .= ' -b:v ' . $videoOptions[ 'videoBitRate' ] . ' -maxrate ' . $videoOptions[ 'videoBitRate' ];
124 124
             }
125 125
 
126 126
             // Adjust the scaling if desired
@@ -130,25 +130,25 @@  discard block
 block discarded – undo
130 130
             );
131 131
 
132 132
             // Handle any audio transcoding
133
-            if (empty($videoOptions['audioBitRate'])
134
-                && empty($videoOptions['audioSampleRate'])
135
-                && empty($videoOptions['audioChannels'])
133
+            if (empty($videoOptions[ 'audioBitRate' ])
134
+                && empty($videoOptions[ 'audioSampleRate' ])
135
+                && empty($videoOptions[ 'audioChannels' ])
136 136
             ) {
137 137
                 // Just copy the audio if no options are provided
138 138
                 $ffmpegCmd .= ' -c:a copy';
139 139
             } else {
140 140
                 // Do audio transcoding based on the settings
141
-                $ffmpegCmd .= ' -acodec '.$thisEncoder['audioCodec'];
142
-                if (!empty($videoOptions['audioBitRate'])) {
143
-                    $ffmpegCmd .= ' -b:a '.$videoOptions['audioBitRate'];
141
+                $ffmpegCmd .= ' -acodec ' . $thisEncoder[ 'audioCodec' ];
142
+                if (!empty($videoOptions[ 'audioBitRate' ])) {
143
+                    $ffmpegCmd .= ' -b:a ' . $videoOptions[ 'audioBitRate' ];
144 144
                 }
145
-                if (!empty($videoOptions['audioSampleRate'])) {
146
-                    $ffmpegCmd .= ' -ar '.$videoOptions['audioSampleRate'];
145
+                if (!empty($videoOptions[ 'audioSampleRate' ])) {
146
+                    $ffmpegCmd .= ' -ar ' . $videoOptions[ 'audioSampleRate' ];
147 147
                 }
148
-                if (!empty($videoOptions['audioChannels'])) {
149
-                    $ffmpegCmd .= ' -ac '.$videoOptions['audioChannels'];
148
+                if (!empty($videoOptions[ 'audioChannels' ])) {
149
+                    $ffmpegCmd .= ' -ac ' . $videoOptions[ 'audioChannels' ];
150 150
                 }
151
-                $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions'];
151
+                $ffmpegCmd .= ' ' . $thisEncoder[ 'audioCodecOptions' ];
152 152
             }
153 153
 
154 154
             // Create the directory if it isn't there already
@@ -163,17 +163,17 @@  discard block
 block discarded – undo
163 163
             $destVideoFile = $this->getFilename($filePath, $videoOptions);
164 164
 
165 165
             // File to store the video encoding progress in
166
-            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress';
166
+            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress';
167 167
 
168 168
             // Assemble the destination path and final ffmpeg command
169 169
             $destVideoPath .= $destVideoFile;
170 170
             $ffmpegCmd .= ' -f '
171
-                .$thisEncoder['fileFormat']
172
-                .' -y '.escapeshellarg($destVideoPath)
173
-                .' 1> '.$progressFile.' 2>&1 & echo $!';
171
+                .$thisEncoder[ 'fileFormat' ]
172
+                .' -y ' . escapeshellarg($destVideoPath)
173
+                .' 1> ' . $progressFile . ' 2>&1 & echo $!';
174 174
 
175 175
             // Make sure there isn't a lockfile for this video already
176
-            $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock';
176
+            $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock';
177 177
             $oldPid = @file_get_contents($lockFile);
178 178
             if ($oldPid !== false) {
179 179
                 exec("ps $oldPid", $ProcessState);
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 
188 188
             // If the video file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
189 189
             if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
190
-                $result = Craft::getAlias($settings['transcoderUrls']['video']).$destVideoFile;
190
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'video' ]) . $destVideoFile;
191 191
             } else {
192 192
                 // Kick off the transcoding
193 193
                 $pid = $this->executeShellCommand($ffmpegCmd);
194
-                Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
194
+                Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
195 195
 
196 196
                 // Create a lockfile in tmp
197 197
                 file_put_contents($lockFile, $pid);
@@ -220,13 +220,13 @@  discard block
 block discarded – undo
220 220
         $filePath = $this->getAssetPath($filePath);
221 221
 
222 222
         if (!empty($filePath)) {
223
-            $destThumbnailPath = Craft::getAlias($settings['transcoderPaths']['thumbnail']);
223
+            $destThumbnailPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'thumbnail' ]);
224 224
 
225 225
             $thumbnailOptions = $this->coalesceOptions('defaultThumbnailOptions', $thumbnailOptions);
226 226
 
227 227
             // Build the basic command for ffmpeg
228
-            $ffmpegCmd = $settings['ffmpegPath']
229
-                .' -i '.escapeshellarg($filePath)
228
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
229
+                .' -i ' . escapeshellarg($filePath)
230 230
                 .' -vcodec mjpeg'
231 231
                 .' -vframes 1';
232 232
 
@@ -237,9 +237,9 @@  discard block
 block discarded – undo
237 237
             );
238 238
 
239 239
             // Set the timecode to get the thumbnail from if desired
240
-            if (!empty($thumbnailOptions['timeInSecs'])) {
241
-                $timeCode = gmdate('H:i:s', $thumbnailOptions['timeInSecs']);
242
-                $ffmpegCmd .= ' -ss '.$timeCode.'.00';
240
+            if (!empty($thumbnailOptions[ 'timeInSecs' ])) {
241
+                $timeCode = gmdate('H:i:s', $thumbnailOptions[ 'timeInSecs' ]);
242
+                $ffmpegCmd .= ' -ss ' . $timeCode . '.00';
243 243
             }
244 244
 
245 245
             // Create the directory if it isn't there already
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 
256 256
             // Assemble the destination path and final ffmpeg command
257 257
             $destThumbnailPath .= $destThumbnailFile;
258
-            $ffmpegCmd .= ' -f image2 -y '.escapeshellarg($destThumbnailPath).' >/dev/null 2>/dev/null &';
258
+            $ffmpegCmd .= ' -f image2 -y ' . escapeshellarg($destThumbnailPath) . ' >/dev/null 2>/dev/null &';
259 259
 
260 260
             // If the thumbnail file already exists, return it.  Otherwise, generate it and return it
261 261
             if (!file_exists($destThumbnailPath)) {
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                     $shellOutput = $this->executeShellCommand($ffmpegCmd);
265 265
                     Craft::info($ffmpegCmd, __METHOD__);
266 266
                 } else {
267
-                    Craft::info('Thumbnail does not exist, but not asked to generate it: '.$filePath, __METHOD__);
267
+                    Craft::info('Thumbnail does not exist, but not asked to generate it: ' . $filePath, __METHOD__);
268 268
 
269 269
                     // The file doesn't exist, and we weren't asked to generate it
270 270
                     return false;
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
             if ($asPath) {
275 275
                 $result = $destThumbnailPath;
276 276
             } else {
277
-                $result = Craft::getAlias($settings['transcoderUrls']['thumbnail']).$destThumbnailFile;
277
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'thumbnail' ]) . $destThumbnailFile;
278 278
             }
279 279
         }
280 280
 
@@ -298,37 +298,37 @@  discard block
 block discarded – undo
298 298
         $filePath = $this->getAssetPath($filePath);
299 299
 
300 300
         if (!empty($filePath)) {
301
-            $destAudioPath = Craft::getAlias($settings['transcoderPaths']['audio']);
301
+            $destAudioPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'audio' ]);
302 302
 
303 303
             $audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions);
304 304
 
305 305
             // Get the audio encoder presets to use
306
-            $audioEncoders = $settings['audioEncoders'];
307
-            $thisEncoder = $audioEncoders[$audioOptions['audioEncoder']];
306
+            $audioEncoders = $settings[ 'audioEncoders' ];
307
+            $thisEncoder = $audioEncoders[ $audioOptions[ 'audioEncoder' ] ];
308 308
 
309
-            $audioOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
309
+            $audioOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
310 310
 
311 311
             // Build the basic command for ffmpeg
312
-            $ffmpegCmd = $settings['ffmpegPath']
313
-                .' -i '.escapeshellarg($filePath)
314
-                .' -acodec '.$thisEncoder['audioCodec']
315
-                .' '.$thisEncoder['audioCodecOptions']
312
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
313
+                .' -i ' . escapeshellarg($filePath)
314
+                .' -acodec ' . $thisEncoder[ 'audioCodec' ]
315
+                .' ' . $thisEncoder[ 'audioCodecOptions' ]
316 316
                 .' -bufsize 1000k'
317 317
                 .' -threads 0';
318 318
 
319 319
             // Set the bitrate if desired
320
-            if (!empty($audioOptions['audioBitRate'])) {
321
-                $ffmpegCmd .= ' -b:a '.$audioOptions['audioBitRate'];
320
+            if (!empty($audioOptions[ 'audioBitRate' ])) {
321
+                $ffmpegCmd .= ' -b:a ' . $audioOptions[ 'audioBitRate' ];
322 322
             }
323 323
             // Set the sample rate if desired
324
-            if (!empty($audioOptions['audioSampleRate'])) {
325
-                $ffmpegCmd .= ' -ar '.$audioOptions['audioSampleRate'];
324
+            if (!empty($audioOptions[ 'audioSampleRate' ])) {
325
+                $ffmpegCmd .= ' -ar ' . $audioOptions[ 'audioSampleRate' ];
326 326
             }
327 327
             // Set the audio channels if desired
328
-            if (!empty($audioOptions['audioChannels'])) {
329
-                $ffmpegCmd .= ' -ac '.$audioOptions['audioChannels'];
328
+            if (!empty($audioOptions[ 'audioChannels' ])) {
329
+                $ffmpegCmd .= ' -ac ' . $audioOptions[ 'audioChannels' ];
330 330
             }
331
-            $ffmpegCmd .= ' '.$thisEncoder['audioCodecOptions'];
331
+            $ffmpegCmd .= ' ' . $thisEncoder[ 'audioCodecOptions' ];
332 332
 
333 333
 
334 334
             // Create the directory if it isn't there already
@@ -343,17 +343,17 @@  discard block
 block discarded – undo
343 343
             $destAudioFile = $this->getFilename($filePath, $audioOptions);
344 344
 
345 345
             // File to store the audio encoding progress in
346
-            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.progress';
346
+            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.progress';
347 347
 
348 348
             // Assemble the destination path and final ffmpeg command
349 349
             $destAudioPath .= $destAudioFile;
350 350
             $ffmpegCmd .= ' -f '
351
-                .$thisEncoder['fileFormat']
352
-                .' -y '.escapeshellarg($destAudioPath)
353
-                .' 1> '.$progressFile.' 2>&1 & echo $!';
351
+                .$thisEncoder[ 'fileFormat' ]
352
+                .' -y ' . escapeshellarg($destAudioPath)
353
+                .' 1> ' . $progressFile . ' 2>&1 & echo $!';
354 354
 
355 355
             // Make sure there isn't a lockfile for this audio file already
356
-            $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destAudioFile.'.lock';
356
+            $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destAudioFile . '.lock';
357 357
             $oldPid = @file_get_contents($lockFile);
358 358
             if ($oldPid !== false) {
359 359
                 exec("ps $oldPid", $ProcessState);
@@ -367,11 +367,11 @@  discard block
 block discarded – undo
367 367
 
368 368
             // If the audio file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
369 369
             if (file_exists($destAudioPath) && (filemtime($destAudioPath) >= filemtime($filePath))) {
370
-                $result = Craft::getAlias($settings['transcoderUrls']['audio']).$destAudioFile;
370
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'audio' ]) . $destAudioFile;
371 371
             } else {
372 372
                 // Kick off the transcoding
373 373
                 $pid = $this->executeShellCommand($ffmpegCmd);
374
-                Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
374
+                Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
375 375
 
376 376
                 // Create a lockfile in tmp
377 377
                 file_put_contents($lockFile, $pid);
@@ -398,10 +398,10 @@  discard block
 block discarded – undo
398 398
 
399 399
         if (!empty($filePath)) {
400 400
             // Build the basic command for ffprobe
401
-            $ffprobeOptions = $settings['ffprobeOptions'];
402
-            $ffprobeCmd = $settings['ffprobePath']
403
-                .' '.$ffprobeOptions
404
-                .' '.escapeshellarg($filePath);
401
+            $ffprobeOptions = $settings[ 'ffprobeOptions' ];
402
+            $ffprobeCmd = $settings[ 'ffprobePath' ]
403
+                .' ' . $ffprobeOptions
404
+                .' ' . escapeshellarg($filePath);
405 405
 
406 406
             $shellOutput = $this->executeShellCommand($ffprobeCmd);
407 407
             Craft::info($ffprobeCmd, __METHOD__);
@@ -410,24 +410,24 @@  discard block
 block discarded – undo
410 410
 
411 411
             // Trim down the arrays to just a summary
412 412
             if ($summary && !empty($result)) {
413
-                $summaryResult = [];
413
+                $summaryResult = [ ];
414 414
                 foreach ($result as $topLevelKey => $topLevelValue) {
415 415
                     switch ($topLevelKey) {
416 416
                         // Format info
417 417
                         case 'format':
418
-                            foreach (self::INFO_SUMMARY['format'] as $settingKey => $settingValue) {
419
-                                if (!empty($topLevelValue[$settingKey])) {
420
-                                    $summaryResult[$settingValue] = $topLevelValue[$settingKey];
418
+                            foreach (self::INFO_SUMMARY[ 'format' ] as $settingKey => $settingValue) {
419
+                                if (!empty($topLevelValue[ $settingKey ])) {
420
+                                    $summaryResult[ $settingValue ] = $topLevelValue[ $settingKey ];
421 421
                                 }
422 422
                             }
423 423
                             break;
424 424
                         // Stream info
425 425
                         case 'streams':
426 426
                             foreach ($topLevelValue as $stream) {
427
-                                $infoSummaryType = $stream['codec_type'];
428
-                                foreach (self::INFO_SUMMARY[$infoSummaryType] as $settingKey => $settingValue) {
429
-                                    if (!empty($stream[$settingKey])) {
430
-                                        $summaryResult[$settingValue] = $stream[$settingKey];
427
+                                $infoSummaryType = $stream[ 'codec_type' ];
428
+                                foreach (self::INFO_SUMMARY[ $infoSummaryType ] as $settingKey => $settingValue) {
429
+                                    if (!empty($stream[ $settingKey ])) {
430
+                                        $summaryResult[ $settingValue ] = $stream[ $settingKey ];
431 431
                                     }
432 432
                                 }
433 433
                             }
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
                     }
439 439
                 }
440 440
                 // Handle cases where the framerate is returned as XX/YY
441
-                if (!empty($summaryResult['videoFrameRate'])
442
-                    && (strpos($summaryResult['videoFrameRate'], '/') !== false)
441
+                if (!empty($summaryResult[ 'videoFrameRate' ])
442
+                    && (strpos($summaryResult[ 'videoFrameRate' ], '/') !== false)
443 443
                 ) {
444
-                    $parts = explode('/', $summaryResult['videoFrameRate']);
445
-                    $summaryResult['videoFrameRate'] = (float)$parts[0] / (float)$parts[1];
444
+                    $parts = explode('/', $summaryResult[ 'videoFrameRate' ]);
445
+                    $summaryResult[ 'videoFrameRate' ] = (float) $parts[ 0 ] / (float) $parts[ 1 ];
446 446
                 }
447 447
                 $result = $summaryResult;
448 448
             }
@@ -465,10 +465,10 @@  discard block
 block discarded – undo
465 465
         $videoOptions = $this->coalesceOptions('defaultVideoOptions', $videoOptions);
466 466
 
467 467
         // Get the video encoder presets to use
468
-        $videoEncoders = $settings['videoEncoders'];
469
-        $thisEncoder = $videoEncoders[$videoOptions['videoEncoder']];
468
+        $videoEncoders = $settings[ 'videoEncoders' ];
469
+        $thisEncoder = $videoEncoders[ $videoOptions[ 'videoEncoder' ] ];
470 470
 
471
-        $videoOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
471
+        $videoOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
472 472
 
473 473
         return $this->getFilename($filePath, $videoOptions);
474 474
     }
@@ -487,10 +487,10 @@  discard block
 block discarded – undo
487 487
         $audioOptions = $this->coalesceOptions('defaultAudioOptions', $audioOptions);
488 488
 
489 489
         // Get the video encoder presets to use
490
-        $audioEncoders = $settings['audioEncoders'];
491
-        $thisEncoder = $audioEncoders[$audioOptions['audioEncoder']];
490
+        $audioEncoders = $settings[ 'audioEncoders' ];
491
+        $thisEncoder = $audioEncoders[ $audioOptions[ 'audioEncoder' ] ];
492 492
 
493
-        $audioOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
493
+        $audioOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
494 494
 
495 495
         return $this->getFilename($filePath, $audioOptions);
496 496
     }
@@ -509,10 +509,10 @@  discard block
 block discarded – undo
509 509
         $gifOptions = $this->coalesceOptions('defaultGifOptions', $gifOptions);
510 510
 
511 511
         // Get the video encoder presets to use
512
-        $videoEncoders = $settings['videoEncoders'];
513
-        $thisEncoder = $videoEncoders[$gifOptions['videoEncoder']];
512
+        $videoEncoders = $settings[ 'videoEncoders' ];
513
+        $thisEncoder = $videoEncoders[ $gifOptions[ 'videoEncoder' ] ];
514 514
 
515
-        $gifOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
515
+        $gifOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
516 516
 
517 517
         return $this->getFilename($filePath, $gifOptions);
518 518
     }
@@ -555,22 +555,22 @@  discard block
 block discarded – undo
555 555
 
556 556
         if (!empty($filePath)) {
557 557
             // Dest path
558
-            $destVideoPath = Craft::getAlias($settings['transcoderPaths']['gif']);
558
+            $destVideoPath = Craft::getAlias($settings[ 'transcoderPaths' ][ 'gif' ]);
559 559
 
560 560
             // Options
561 561
             $gifOptions = $this->coalesceOptions('defaultGifOptions', $gifOptions);
562 562
 
563 563
             // Get the video encoder presets to use
564
-            $videoEncoders = $settings['videoEncoders'];
565
-            $thisEncoder = $videoEncoders[$gifOptions['videoEncoder']];
566
-            $gifOptions['fileSuffix'] = $thisEncoder['fileSuffix'];
564
+            $videoEncoders = $settings[ 'videoEncoders' ];
565
+            $thisEncoder = $videoEncoders[ $gifOptions[ 'videoEncoder' ] ];
566
+            $gifOptions[ 'fileSuffix' ] = $thisEncoder[ 'fileSuffix' ];
567 567
 
568 568
             // Build the basic command for ffmpeg
569
-            $ffmpegCmd = $settings['ffmpegPath']
569
+            $ffmpegCmd = $settings[ 'ffmpegPath' ]
570 570
                 .' -f gif'
571
-                .' -i '.escapeshellarg($filePath)
572
-                .' -vcodec '.$thisEncoder['videoCodec']
573
-                .' '.$thisEncoder['videoCodecOptions'];
571
+                .' -i ' . escapeshellarg($filePath)
572
+                .' -vcodec ' . $thisEncoder[ 'videoCodec' ]
573
+                .' ' . $thisEncoder[ 'videoCodecOptions' ];
574 574
 
575 575
 
576 576
             // Create the directory if it isn't there already
@@ -585,16 +585,16 @@  discard block
 block discarded – undo
585 585
             $destVideoFile = $this->getFilename($filePath, $gifOptions);
586 586
 
587 587
             // File to store the video encoding progress in
588
-            $progressFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.progress';
588
+            $progressFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.progress';
589 589
 
590 590
             // Assemble the destination path and final ffmpeg command
591 591
             $destVideoPath .= $destVideoFile;
592 592
             $ffmpegCmd .= ' '
593
-                .' -y '.escapeshellarg($destVideoPath)
594
-                .' 1> '.$progressFile.' 2>&1 & echo $!';
593
+                .' -y ' . escapeshellarg($destVideoPath)
594
+                .' 1> ' . $progressFile . ' 2>&1 & echo $!';
595 595
 
596 596
             // Make sure there isn't a lockfile for this video already
597
-            $lockFile = sys_get_temp_dir().DIRECTORY_SEPARATOR.$destVideoFile.'.lock';
597
+            $lockFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $destVideoFile . '.lock';
598 598
             $oldPid = @file_get_contents($lockFile);
599 599
             if ($oldPid !== false) {
600 600
                 exec("ps $oldPid", $ProcessState);
@@ -608,11 +608,11 @@  discard block
 block discarded – undo
608 608
 
609 609
             // If the video file already exists and hasn't been modified, return it.  Otherwise, start it transcoding
610 610
             if (file_exists($destVideoPath) && (filemtime($destVideoPath) >= filemtime($filePath))) {
611
-                $result = Craft::getAlias($settings['transcoderUrls']['gif']).$destVideoFile;
611
+                $result = Craft::getAlias($settings[ 'transcoderUrls' ][ 'gif' ]) . $destVideoFile;
612 612
             } else {
613 613
                 // Kick off the transcoding
614 614
                 $pid = $this->executeShellCommand($ffmpegCmd);
615
-                Craft::info($ffmpegCmd."\nffmpeg PID: ".$pid, __METHOD__);
615
+                Craft::info($ffmpegCmd . "\nffmpeg PID: " . $pid, __METHOD__);
616 616
 
617 617
                 // Create a lockfile in tmp
618 618
                 file_put_contents($lockFile, $pid);
@@ -639,32 +639,32 @@  discard block
 block discarded – undo
639 639
         $error = '';
640 640
         if ($validator->validate($filePath, $error)) {
641 641
             $urlParts = parse_url($filePath);
642
-            $pathParts = pathinfo($urlParts['path']);
642
+            $pathParts = pathinfo($urlParts[ 'path' ]);
643 643
         } else {
644 644
             $pathParts = pathinfo($filePath);
645 645
         }
646
-        $fileName = $pathParts['filename'];
646
+        $fileName = $pathParts[ 'filename' ];
647 647
 
648 648
         // Add our options to the file name
649 649
         foreach ($options as $key => $value) {
650 650
             if (!empty($value)) {
651 651
                 $suffix = '';
652
-                if (!empty(self::SUFFIX_MAP[$key])) {
653
-                    $suffix = self::SUFFIX_MAP[$key];
652
+                if (!empty(self::SUFFIX_MAP[ $key ])) {
653
+                    $suffix = self::SUFFIX_MAP[ $key ];
654 654
                 }
655 655
                 if (\is_bool($value)) {
656
-                    $value = $value ? $key : 'no'.$key;
656
+                    $value = $value ? $key : 'no' . $key;
657 657
                 }
658 658
                 if (!\in_array($key, self::EXCLUDE_PARAMS, true)) {
659
-                    $fileName .= '_'.$value.$suffix;
659
+                    $fileName .= '_' . $value . $suffix;
660 660
                 }
661 661
             }
662 662
         }
663 663
         // See if we should use a hash instead
664
-        if ($settings['useHashedNames']) {
665
-            $fileName = $pathParts['filename'].md5($fileName);
664
+        if ($settings[ 'useHashedNames' ]) {
665
+            $fileName = $pathParts[ 'filename' ] . md5($fileName);
666 666
         }
667
-        $fileName .= $options['fileSuffix'];
667
+        $fileName .= $options[ 'fileSuffix' ];
668 668
 
669 669
         return $fileName;
670 670
     }
@@ -693,16 +693,16 @@  discard block
 block discarded – undo
693 693
                 // If it's local, get a path to the file
694 694
                 if ($assetVolume instanceof Local) {
695 695
                     $sourcePath = rtrim($assetVolume->path, DIRECTORY_SEPARATOR);
696
-                    $sourcePath .= '' === $sourcePath ? '': DIRECTORY_SEPARATOR;
696
+                    $sourcePath .= '' === $sourcePath ? '' : DIRECTORY_SEPARATOR;
697 697
                     $folderPath = '';
698 698
                     try {
699 699
                         $folderPath = rtrim($asset->getFolder()->path, DIRECTORY_SEPARATOR);
700 700
                     } catch (InvalidConfigException $e) {
701 701
                         Craft::error($e->getMessage(), __METHOD__);
702 702
                     }
703
-                    $folderPath .= '' === $folderPath ? '': DIRECTORY_SEPARATOR;
703
+                    $folderPath .= '' === $folderPath ? '' : DIRECTORY_SEPARATOR;
704 704
 
705
-                    $filePath = $sourcePath.$folderPath.$asset->filename;
705
+                    $filePath = $sourcePath . $folderPath . $asset->filename;
706 706
                 } else {
707 707
                     // Otherwise, get a URL
708 708
                     $filePath = $asset->getUrl();
@@ -735,39 +735,39 @@  discard block
 block discarded – undo
735 735
      */
736 736
     protected function addScalingFfmpegArgs($options, $ffmpegCmd): string
737 737
     {
738
-        if (!empty($options['width']) && !empty($options['height'])) {
738
+        if (!empty($options[ 'width' ]) && !empty($options[ 'height' ])) {
739 739
             // Handle "none", "crop", and "letterbox" aspectRatios
740 740
             $aspectRatio = '';
741
-            if (!empty($options['aspectRatio'])) {
742
-                switch ($options['aspectRatio']) {
741
+            if (!empty($options[ 'aspectRatio' ])) {
742
+                switch ($options[ 'aspectRatio' ]) {
743 743
                     // Scale to the appropriate aspect ratio, padding
744 744
                     case 'letterbox':
745 745
                         $letterboxColor = '';
746
-                        if (!empty($options['letterboxColor'])) {
747
-                            $letterboxColor = ':color='.$options['letterboxColor'];
746
+                        if (!empty($options[ 'letterboxColor' ])) {
747
+                            $letterboxColor = ':color=' . $options[ 'letterboxColor' ];
748 748
                         }
749 749
                         $aspectRatio = ':force_original_aspect_ratio=decrease'
750
-                            .',pad='.$options['width'].':'.$options['height'].':(ow-iw)/2:(oh-ih)/2'
750
+                            .',pad=' . $options[ 'width' ] . ':' . $options[ 'height' ] . ':(ow-iw)/2:(oh-ih)/2'
751 751
                             .$letterboxColor;
752 752
                         break;
753 753
                     // Scale to the appropriate aspect ratio, cropping
754 754
                     case 'crop':
755 755
                         $aspectRatio = ':force_original_aspect_ratio=increase'
756
-                            .',crop='.$options['width'].':'.$options['height'];
756
+                            .',crop=' . $options[ 'width' ] . ':' . $options[ 'height' ];
757 757
                         break;
758 758
                     // No aspect ratio scaling at all
759 759
                     default:
760 760
                         $aspectRatio = ':force_original_aspect_ratio=disable';
761
-                        $options['aspectRatio'] = 'none';
761
+                        $options[ 'aspectRatio' ] = 'none';
762 762
                         break;
763 763
                 }
764 764
             }
765 765
             $sharpen = '';
766
-            if (!empty($options['sharpen']) && ($options['sharpen'] !== false)) {
766
+            if (!empty($options[ 'sharpen' ]) && ($options[ 'sharpen' ] !== false)) {
767 767
                 $sharpen = ',unsharp=5:5:1.0:5:5:0.0';
768 768
             }
769 769
             $ffmpegCmd .= ' -vf "scale='
770
-                .$options['width'].':'.$options['height']
770
+                .$options[ 'width' ] . ':' . $options[ 'height' ]
771 771
                 .$aspectRatio
772 772
                 .$sharpen
773 773
                 .'"';
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     {
792 792
         // Default options
793 793
         $settings = Transcoder::$plugin->getSettings();
794
-        $defaultOptions = $settings[$defaultName];
794
+        $defaultOptions = $settings[ $defaultName ];
795 795
 
796 796
         // Coalesce the passed in $options with the $defaultOptions
797 797
         $options = array_merge($defaultOptions, $options);
Please login to merge, or discard this patch.
src/models/Settings.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
     /**
30 30
      * @inheritdoc
31 31
      */
32
-    public function __construct(array $config = [])
32
+    public function __construct(array $config = [ ])
33 33
     {
34 34
         // Unset any deprecated properties
35 35
         if (!empty($config)) {
36
-            unset($config['transcoderPath'], $config['transcoderUrl']);
36
+            unset($config[ 'transcoderPath' ], $config[ 'transcoderUrl' ]);
37 37
         }
38 38
         parent::__construct($config);
39 39
     }
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
     public function init()
228 228
     {
229 229
         $tokens = [
230
-            '{DOCUMENT_ROOT}' => $_SERVER['DOCUMENT_ROOT'],
230
+            '{DOCUMENT_ROOT}' => $_SERVER[ 'DOCUMENT_ROOT' ],
231 231
         ];
232 232
         $this->transcoderPath = str_replace(array_keys($tokens), array_values($tokens), $this->transcoderPath);
233 233
     }
@@ -238,25 +238,25 @@  discard block
 block discarded – undo
238 238
     public function rules()
239 239
     {
240 240
         return [
241
-            ['ffmpegPath', 'string'],
242
-            ['ffmpegPath', 'required'],
243
-            ['ffprobePath', 'string'],
244
-            ['ffprobePath', 'required'],
245
-            ['ffprobeOptions', 'string'],
246
-            ['ffprobeOptions', 'safe'],
247
-            ['transcoderPath', 'string'],
248
-            ['transcoderPath', 'required'],
249
-            ['transcoderPaths', ArrayValidator::class],
250
-            ['transcoderPaths', 'required'],
251
-            ['transcoderUrls', ArrayValidator::class],
252
-            ['transcoderUrls', 'required'],
253
-            ['useHashedNames', 'boolean'],
254
-            ['useHashedNames', 'default', 'value' => false],
255
-            ['videoEncoders', 'required'],
256
-            ['audioEncoders', 'required'],
257
-            ['defaultVideoOptions', 'required'],
258
-            ['defaultThumbnailOptions', 'required'],
259
-            ['defaultAudioOptions', 'required'],
241
+            [ 'ffmpegPath', 'string' ],
242
+            [ 'ffmpegPath', 'required' ],
243
+            [ 'ffprobePath', 'string' ],
244
+            [ 'ffprobePath', 'required' ],
245
+            [ 'ffprobeOptions', 'string' ],
246
+            [ 'ffprobeOptions', 'safe' ],
247
+            [ 'transcoderPath', 'string' ],
248
+            [ 'transcoderPath', 'required' ],
249
+            [ 'transcoderPaths', ArrayValidator::class ],
250
+            [ 'transcoderPaths', 'required' ],
251
+            [ 'transcoderUrls', ArrayValidator::class ],
252
+            [ 'transcoderUrls', 'required' ],
253
+            [ 'useHashedNames', 'boolean' ],
254
+            [ 'useHashedNames', 'default', 'value' => false ],
255
+            [ 'videoEncoders', 'required' ],
256
+            [ 'audioEncoders', 'required' ],
257
+            [ 'defaultVideoOptions', 'required' ],
258
+            [ 'defaultThumbnailOptions', 'required' ],
259
+            [ 'defaultAudioOptions', 'required' ],
260 260
         ];
261 261
     }
262 262
 }
Please login to merge, or discard this patch.
src/variables/TranscoderVariable.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
     {
156 156
         $result = '';
157 157
         $filePath = parse_url($url, PHP_URL_PATH);
158
-        $filePath = $_SERVER['DOCUMENT_ROOT'] . $filePath;
158
+        $filePath = $_SERVER[ 'DOCUMENT_ROOT' ] . $filePath;
159 159
         if (file_exists($filePath)) {
160 160
             $urlParams = [
161 161
                 'url' => $url,
Please login to merge, or discard this patch.